From 40baf85ec5164f189ae58c3012b29e3d8fff4cd5 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 28 Oct 2024 22:54:13 +0800 Subject: [PATCH] fix: default data source (#1143) * fix: default data source Signed-off-by: SuZhou-Joe * feat: optimize Signed-off-by: SuZhou-Joe * feat: update comment Signed-off-by: SuZhou-Joe --------- Signed-off-by: SuZhou-Joe --- public/pages/utils/constants.ts | 15 ++++++++------- public/plugin.tsx | 9 ++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/public/pages/utils/constants.ts b/public/pages/utils/constants.ts index a08e2ba2c..ff30dd076 100644 --- a/public/pages/utils/constants.ts +++ b/public/pages/utils/constants.ts @@ -9,10 +9,11 @@ import { DataSourceOption } from "../../../../../src/plugins/data_source_managem export const COMMENTS_ENABLED_SETTING = "plugins.alerting.comments_enabled"; const LocalCluster: DataSourceOption = { - label: i18n.translate("dataSource.localCluster", { - defaultMessage: "Local cluster", - }), - id: "", - }; - - export const dataSourceObservable = new BehaviorSubject(LocalCluster); \ No newline at end of file + label: i18n.translate("dataSource.localCluster", { + defaultMessage: "Local cluster", + }), + id: "", +}; + +// We should use empty object for default value as local cluster may be disabled +export const dataSourceObservable = new BehaviorSubject({}); \ No newline at end of file diff --git a/public/plugin.tsx b/public/plugin.tsx index 82ce91b70..bc63d80b0 100644 --- a/public/plugin.tsx +++ b/public/plugin.tsx @@ -62,7 +62,14 @@ export interface AlertingStartDeps { export class AlertingPlugin implements Plugin { private updateDefaultRouteOfManagementApplications: AppUpdater = () => { - const hash = `#/?dataSourceId=${dataSourceObservable.value?.id || ""}`; + const dataSourceValue = dataSourceObservable.value?.id; + let hash = `#/`; + // When data source value is undefined, + // it means the data source picker has not determine which data source to use(local or default data source) + // so we should not append any data source id into hash to avoid impacting the data source picker. + if (dataSourceValue !== undefined) { + hash = `#/?dataSourceId=${dataSourceValue}`; + } return { defaultPath: hash, };