diff --git a/public/app/core/components/SharedPreferences/SharedPreferences.tsx b/public/app/core/components/SharedPreferences/SharedPreferences.tsx index 08be7cf9f2f00..e224877db9e89 100644 --- a/public/app/core/components/SharedPreferences/SharedPreferences.tsx +++ b/public/app/core/components/SharedPreferences/SharedPreferences.tsx @@ -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; @@ -30,7 +31,7 @@ export interface Props { onConfirm?: () => Promise; } -export type State = UserPreferencesDTO; +export type State = UserPreferencesDTO & { homeDashboardId?: number; dashboards: Array}; // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard function getLanguageOptions(): Array> { const languageOptions = LANGUAGES.map((v) => ({ @@ -63,6 +64,7 @@ export class SharedPreferences extends PureComponent { weekStart: '', language: '', queryHistory: { homeTab: '' }, + dashboards: [], }; this.themeOptions = getBuiltInThemes(config.featureToggles.extraThemes).map((theme) => ({ @@ -75,16 +77,35 @@ export class SharedPreferences extends PureComponent { } 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) => { @@ -94,8 +115,9 @@ export class SharedPreferences extends PureComponent { 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, }); diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 559fbff18ff30..719a303615244 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -508,7 +508,7 @@ export class BackendSrv implements BackendService { } /** @deprecated */ - search(query: any): Promise { + search(query: any): Promise> { // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard return this.get('/api/search', query); } diff --git a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx index 1b6b7bf044584..b353d492f454a 100644 --- a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx @@ -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]; diff --git a/public/app/features/alerting/unified/hooks/usePluginBridge.ts b/public/app/features/alerting/unified/hooks/usePluginBridge.ts index 2468fedd9eae8..10ede77a9a802 100644 --- a/public/app/features/alerting/unified/hooks/usePluginBridge.ts +++ b/public/app/features/alerting/unified/hooks/usePluginBridge.ts @@ -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;