From 2725e5d41949c864655381d0b74c1fc500531d0b Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:15:24 -0700 Subject: [PATCH] fix: default data source (#1143) (#1145) * fix: default data source * feat: optimize * feat: update comment --------- (cherry picked from commit 40baf85ec5164f189ae58c3012b29e3d8fff4cd5) Signed-off-by: SuZhou-Joe Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- 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, };