Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV-46535 Grafana 10 saving profile preferences fails with 400 bad request #58

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions public/app/core/components/SharedPreferences/SharedPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { LANGUAGES } from 'app/core/internationalization/constants';
import { PreferencesService } from 'app/core/services/PreferencesService';
import { backendSrv } from "app/core/services/backend_srv";// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
import { changeTheme } from 'app/core/services/theme';
import { DashboardSearchItem } from 'app/features/search/types';

export interface Props {
resourceUri: string;
Expand All @@ -30,7 +31,7 @@ export interface Props {
onConfirm?: () => Promise<boolean>;
}

export type State = UserPreferencesDTO;
export type State = UserPreferencesDTO & { homeDashboardId?: number; dashboards: Array<DashboardSearchItem & {id?: number}>}; // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard

function getLanguageOptions(): Array<SelectableValue<string>> {
const languageOptions = LANGUAGES.map((v) => ({
Expand Down Expand Up @@ -63,6 +64,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
weekStart: '',
language: '',
queryHistory: { homeTab: '' },
dashboards: [],
};

this.themeOptions = getBuiltInThemes(config.featureToggles.extraThemes).map((theme) => ({
Expand All @@ -75,16 +77,35 @@ export class SharedPreferences extends PureComponent<Props, State> {
}

async componentDidMount() {
const prefs = await backendSrv.get(`/api/${this.props.resourceUri.toLowerCase()}/preferences`);// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
const prefs = await backendSrv.get(`/api/${this.props.resourceUri.toLowerCase()}/preferences`);
const dashboards = await backendSrv.search({ starred: true });
//
// this.setState({
// homeDashboardUID: prefs.homeDashboardUID,
// theme: prefs.theme,
// timezone: prefs.timezone,
// weekStart: prefs.weekStart,
// language: prefs.language,
// queryHistory: prefs.queryHistory,
// });

if (prefs.homeDashboardId > 0 && !dashboards.find((d) => d.id === prefs.homeDashboardId)) {
const missing = await backendSrv.search({ dashboardIds: [prefs.homeDashboardId] });
if (missing && missing.length > 0) {
dashboards.push(missing[0]);
}
}

this.setState({
homeDashboardId: prefs.homeDashboardId,
homeDashboardUID: prefs.homeDashboardUID,
theme: prefs.theme,
timezone: prefs.timezone,
weekStart: prefs.weekStart,
language: prefs.language,
queryHistory: prefs.queryHistory,
dashboards,
});
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Remove default dashboard end
}

onSubmitForm = async (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -94,8 +115,9 @@ export class SharedPreferences extends PureComponent<Props, State> {
if (confirmationResult) {
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
const { homeDashboardUID, theme, timezone } = this.state;
const homeDashboard = this.state.dashboards.find(d => d.uid === homeDashboardUID);
await backendSrv.put(`/api/${this.props.resourceUri.toLowerCase()}/preferences`, {
homeDashboardId: homeDashboardUID,
homeDashboardId: homeDashboard?.id || null,
theme,
timezone,
});
Expand Down
2 changes: 1 addition & 1 deletion public/app/core/services/backend_srv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class BackendSrv implements BackendService {
}

/** @deprecated */
search(query: any): Promise<DashboardSearchItem[]> {
search(query: any): Promise<Array<DashboardSearchItem & {id?: number}>> { // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
return this.get('/api/search', query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P
removeExpressionsInQueries,
condition,
]);

// LOGZ.IO CHANGE :: DEV-46521 remove rule type switch. need this useless call
// in order to mitigate the not-in-use error
useEffect(() => {
onClickSwitch();
}, [onClickSwitch]);

const { sectionTitle, helpLabel, helpContent, helpLink } = DESCRIPTIONS[type ?? RuleFormType.grafana];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ interface PluginBridgeHookResponse {
}

export function usePluginBridge(plugin: PluginID): PluginBridgeHookResponse {
const { loading, error, value } = useAsync(() => getPluginSettings(plugin, { showErrorAlert: false }));
// LOGZ.IO CHANGE :: DEV-46522 disable the oncall grafana plugin
if (plugin === SupportedPlugin.OnCall) {
return { loading: false, installed: false};
}
// LOGZ.IO CHANGE :: DEV-46522 disable the oncall grafana plugin. END
const { loading, error, value } = useAsync(() => getPluginSettings(plugin, { showErrorAlert: false }));

const installed = value && !error && !loading;
const enabled = value?.enabled;
const isLoading = loading && !value;
Expand Down
3 changes: 2 additions & 1 deletion public/app/plugins/panel/alertGroups/AlertGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ export const AlertGroup = ({ alertManagerSourceName, group, expandAll }: Props)
Silence
</LinkButton>
)}
{ /* LOGZ.IO CHANGE :: DEV-46517 - add link target to _top */ }
{alert.generatorURL && (
<LinkButton className={styles.button} href={alert.generatorURL} icon={'chart-line'} size={'sm'}>
<LinkButton target="_top" className={styles.button} href={alert.generatorURL} icon={'chart-line'} size={'sm'}>
See source
</LinkButton>
)}
Expand Down