From 6e1ed56da49dff470af76d3e8cad0ad6731d3742 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 29 Aug 2024 16:20:31 -0700 Subject: [PATCH 1/4] persist dataSource when swictching between sideNav Signed-off-by: Riya Saxena --- public/pages/Main/Main.js | 6 +++++- public/pages/utils/constants.ts | 14 +++++++++++++- public/plugin.tsx | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/public/pages/Main/Main.js b/public/pages/Main/Main.js index 7751f43dc..2b932fff4 100644 --- a/public/pages/Main/Main.js +++ b/public/pages/Main/Main.js @@ -24,6 +24,7 @@ import { MultiDataSourceContext } from '../../../public/utils/MultiDataSourceCon import { parseQueryStringAndGetDataSource } from '../utils/helpers'; import * as pluginManifest from '../../../opensearch_dashboards.json'; import semver from 'semver'; +import { dataSourceObservable } from '../../pages/utils/constants'; class Main extends Component { static contextType = CoreContext; @@ -31,7 +32,8 @@ class Main extends Component { flyout: null, selectedDataSourceId: undefined, dataSourceLoading: this.props.dataSourceEnabled, - }; + dataSourceLabel: "" + } async componentDidMount() { if (this.context) { this.updateBreadcrumbs(); @@ -89,6 +91,7 @@ class Main extends Component { handleDataSourceChange = ([dataSource]) => { const dataSourceId = dataSource?.id; + const dataSourceLabel = dataSource?.label if (this.props.dataSourceEnabled && dataSourceId === undefined) { getNotifications().toasts.addDanger('Unable to set data source.'); } else if (this.state.selectedDataSourceId != dataSourceId) { @@ -97,6 +100,7 @@ class Main extends Component { }); setDataSource({ dataSourceId }); } + dataSourceObservable.next({ id: dataSourceId, label: dataSourceLabel }); if (this.state.dataSourceLoading) { this.setState({ dataSourceLoading: false, diff --git a/public/pages/utils/constants.ts b/public/pages/utils/constants.ts index 5bc03545f..a08e2ba2c 100644 --- a/public/pages/utils/constants.ts +++ b/public/pages/utils/constants.ts @@ -3,4 +3,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -export const COMMENTS_ENABLED_SETTING = "plugins.alerting.comments_enabled"; \ No newline at end of file +import { i18n } from "@osd/i18n"; +import { BehaviorSubject } from 'rxjs'; +import { DataSourceOption } from "../../../../../src/plugins/data_source_management/public"; + +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 diff --git a/public/plugin.tsx b/public/plugin.tsx index 06ca8a2bc..0cb56ad8d 100644 --- a/public/plugin.tsx +++ b/public/plugin.tsx @@ -12,6 +12,7 @@ import { WorkspaceAvailability, AppMountParameters, DEFAULT_APP_CATEGORIES, + AppUpdater, } from '../../../src/core/public'; import { ACTION_ALERTING } from './actions/alerting_dashboard_action'; import { CONTEXT_MENU_TRIGGER, EmbeddableStart } from '../../../src/plugins/embeddable/public'; @@ -26,6 +27,8 @@ import { DataPublicPluginStart } from '../../../src/plugins/data/public'; import { DataSourceManagementPluginSetup } from '../../../src/plugins/data_source_management/public'; import { DataSourcePluginSetup } from '../../../src/plugins/data_source/public'; import { NavigationPublicPluginStart } from '../../../src/plugins/navigation/public'; +import { BehaviorSubject } from 'rxjs'; +import { dataSourceObservable } from './pages/utils/constants'; declare module '../../../src/plugins/ui_actions/public' { export interface ActionContextMapping { @@ -53,6 +56,16 @@ export interface AlertingStartDeps { export class AlertingPlugin implements Plugin { + private updateDefaultRouteOfManagementApplications: AppUpdater = () => { + const hash = `#/?dataSourceId=${dataSourceObservable.value?.id || ""}`; + return { + defaultPath: hash, + }; + }; + + private appStateUpdater = new BehaviorSubject(this.updateDefaultRouteOfManagementApplications); + + public setup(core: CoreSetup, { expressions, uiActions, dataSourceManagement, dataSource }: AlertingSetupDeps) { const mountWrapper = async (params: AppMountParameters, redirect: string) => { @@ -102,6 +115,7 @@ export class AlertingPlugin implements Plugin { return mountWrapper(params, "/dashboard"); }, @@ -112,6 +126,7 @@ export class AlertingPlugin implements Plugin { return mountWrapper(params, "/monitors"); }, @@ -122,11 +137,18 @@ export class AlertingPlugin implements Plugin { return mountWrapper(params, "/destinations"); }, }); + dataSourceObservable.subscribe((dataSourceOption) => { + if (dataSourceOption) { + this.appStateUpdater.next(this.updateDefaultRouteOfManagementApplications); + } + }); + const navLinks = [ { id: ALERTS_NAV_ID, From 04b0e6a22cbc33aaeb0200c5c7c7ff6e96eba1bb Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 29 Aug 2024 16:22:43 -0700 Subject: [PATCH 2/4] persist dataSource when swictching between sideNav Signed-off-by: Riya Saxena --- public/pages/Main/Main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/public/pages/Main/Main.js b/public/pages/Main/Main.js index 2b932fff4..39b3b2caa 100644 --- a/public/pages/Main/Main.js +++ b/public/pages/Main/Main.js @@ -32,7 +32,6 @@ class Main extends Component { flyout: null, selectedDataSourceId: undefined, dataSourceLoading: this.props.dataSourceEnabled, - dataSourceLabel: "" } async componentDidMount() { if (this.context) { From 8a7f61976a5fa4b2b9c20a4fd1dc236cb72ec18b Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 29 Aug 2024 16:23:13 -0700 Subject: [PATCH 3/4] persist dataSource when swictching between sideNav Signed-off-by: Riya Saxena --- public/pages/Main/Main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/pages/Main/Main.js b/public/pages/Main/Main.js index 39b3b2caa..f361aac95 100644 --- a/public/pages/Main/Main.js +++ b/public/pages/Main/Main.js @@ -32,7 +32,7 @@ class Main extends Component { flyout: null, selectedDataSourceId: undefined, dataSourceLoading: this.props.dataSourceEnabled, - } + }; async componentDidMount() { if (this.context) { this.updateBreadcrumbs(); From 4a09df7f123ca5227187d6569491f7ba54a3b347 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Tue, 3 Sep 2024 08:34:40 -0700 Subject: [PATCH 4/4] fix the CI Signed-off-by: Riya Saxena --- package.json | 2 +- .../__snapshots__/Dashboard.test.js.snap | 13 + .../DestinationsList.test.js.snap | 3 + yarn.lock | 293 +----------------- 4 files changed, 26 insertions(+), 285 deletions(-) diff --git a/package.json b/package.json index edae5e827..df35e6cb9 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@elastic/elastic-eslint-config-kibana": "link:../../packages/opensearch-eslint-config-opensearch-dashboards", "@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards", "cypress": "9.5.4", - "husky": "^3.0.0", + "husky": "^8.0.0", "lint-staged": "^10.2.0", "@types/react": "^16.14.23" }, diff --git a/public/pages/Dashboard/containers/__snapshots__/Dashboard.test.js.snap b/public/pages/Dashboard/containers/__snapshots__/Dashboard.test.js.snap index 21adda480..575374ee4 100644 --- a/public/pages/Dashboard/containers/__snapshots__/Dashboard.test.js.snap +++ b/public/pages/Dashboard/containers/__snapshots__/Dashboard.test.js.snap @@ -221,6 +221,7 @@ exports[`Dashboard renders in flyout 1`] = ` >