Skip to content

Commit 1eed783

Browse files
committed
Fix home dashboard not loaded and updated
1 parent 8b875f1 commit 1eed783

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

public/app/core/components/SharedPreferences/SharedPreferences.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { LANGUAGES } from 'app/core/internationalization/constants';
2222
import { PreferencesService } from 'app/core/services/PreferencesService';
2323
import { backendSrv } from "app/core/services/backend_srv";// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
2424
import { changeTheme } from 'app/core/services/theme';
25+
import { DashboardSearchItem } from 'app/features/search/types';
2526

2627
export interface Props {
2728
resourceUri: string;
@@ -30,7 +31,7 @@ export interface Props {
3031
onConfirm?: () => Promise<boolean>;
3132
}
3233

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

3536
function getLanguageOptions(): Array<SelectableValue<string>> {
3637
const languageOptions = LANGUAGES.map((v) => ({
@@ -63,6 +64,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
6364
weekStart: '',
6465
language: '',
6566
queryHistory: { homeTab: '' },
67+
dashboards: [],
6668
};
6769

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

7779
async componentDidMount() {
78-
const prefs = await backendSrv.get(`/api/${this.props.resourceUri.toLowerCase()}/preferences`);// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
80+
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
81+
const prefs = await backendSrv.get(`/api/${this.props.resourceUri.toLowerCase()}/preferences`);
82+
const dashboards = await backendSrv.search({ starred: true });
83+
//
84+
// this.setState({
85+
// homeDashboardUID: prefs.homeDashboardUID,
86+
// theme: prefs.theme,
87+
// timezone: prefs.timezone,
88+
// weekStart: prefs.weekStart,
89+
// language: prefs.language,
90+
// queryHistory: prefs.queryHistory,
91+
// });
92+
93+
if (prefs.homeDashboardId > 0 && !dashboards.find((d) => d.id === prefs.homeDashboardId)) {
94+
const missing = await backendSrv.search({ dashboardIds: [prefs.homeDashboardId] });
95+
if (missing && missing.length > 0) {
96+
dashboards.push(missing[0]);
97+
}
98+
}
7999

80100
this.setState({
101+
homeDashboardId: prefs.homeDashboardId,
81102
homeDashboardUID: prefs.homeDashboardUID,
82103
theme: prefs.theme,
83104
timezone: prefs.timezone,
84105
weekStart: prefs.weekStart,
85-
language: prefs.language,
86-
queryHistory: prefs.queryHistory,
106+
dashboards,
87107
});
108+
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Remove default dashboard end
88109
}
89110

90111
onSubmitForm = async (event: React.FormEvent<HTMLFormElement>) => {
@@ -94,8 +115,9 @@ export class SharedPreferences extends PureComponent<Props, State> {
94115
if (confirmationResult) {
95116
// LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard
96117
const { homeDashboardUID, theme, timezone } = this.state;
118+
const homeDashboard = this.state.dashboards.find(d => d.uid === homeDashboardUID);
97119
await backendSrv.put(`/api/${this.props.resourceUri.toLowerCase()}/preferences`, {
98-
homeDashboardId: homeDashboardUID,
120+
homeDashboardId: homeDashboard?.id || null,
99121
theme,
100122
timezone,
101123
});

public/app/core/services/backend_srv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export class BackendSrv implements BackendService {
508508
}
509509

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

public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P
371371
removeExpressionsInQueries,
372372
condition,
373373
]);
374+
375+
// LOGZ.IO CHANGE :: DEV-46521 remove rule type switch. need this useless call
376+
// in order to mitigate the not-in-use error
377+
useEffect(() => {
378+
onClickSwitch();
379+
}, [onClickSwitch]);
374380

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

public/app/features/alerting/unified/hooks/usePluginBridge.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ interface PluginBridgeHookResponse {
1414
}
1515

1616
export function usePluginBridge(plugin: PluginID): PluginBridgeHookResponse {
17+
const { loading, error, value } = useAsync(() => getPluginSettings(plugin, { showErrorAlert: false }));
1718
// LOGZ.IO CHANGE :: DEV-46522 disable the oncall grafana plugin
1819
if (plugin === SupportedPlugin.OnCall) {
1920
return { loading: false, installed: false};
2021
}
2122
// LOGZ.IO CHANGE :: DEV-46522 disable the oncall grafana plugin. END
22-
const { loading, error, value } = useAsync(() => getPluginSettings(plugin, { showErrorAlert: false }));
23-
2423
const installed = value && !error && !loading;
2524
const enabled = value?.enabled;
2625
const isLoading = loading && !value;

0 commit comments

Comments
 (0)