Skip to content

Commit

Permalink
Fix home dashboard not loaded and updated
Browse files Browse the repository at this point in the history
  • Loading branch information
copyhold committed Oct 13, 2024
1 parent 8b875f1 commit 1eed783
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
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

0 comments on commit 1eed783

Please sign in to comment.