Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* persist dataSource when swictching between sideNav

Signed-off-by: Riya Saxena <[email protected]>

* persist dataSource when swictching between sideNav

Signed-off-by: Riya Saxena <[email protected]>

* persist dataSource when swictching between sideNav

Signed-off-by: Riya Saxena <[email protected]>

* fix the CI

Signed-off-by: Riya Saxena <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
(cherry picked from commit 5feef22)
  • Loading branch information
riysaxen-amzn authored Sep 5, 2024
1 parent 83ad06c commit d4862dc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 280 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"@babel/plugin-transform-modules-commonjs": "^7.22.9",
"@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": "^6.0.0",
"husky": "^3.0.0",
"cypress": "9.5.4",
"husky": "^8.0.0",
"lint-staged": "^10.2.0",
"@types/react": "^16.14.23"
},
Expand Down Expand Up @@ -67,4 +67,4 @@
"engines": {
"yarn": "^1.21.1"
}
}
}
5 changes: 5 additions & 0 deletions public/pages/Main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import {
} from '../../../public/services';
import { MultiDataSourceContext } from '../../../public/utils/MultiDataSourceContext';
import { parseQueryStringAndGetDataSource } from '../utils/helpers';
import * as pluginManifest from '../../../opensearch_dashboards.json';
import semver from 'semver';
import { dataSourceObservable } from '../../pages/utils/constants';
import { dataSourceFilterFn } from '../../utils/helpers';

class Main extends Component {
Expand Down Expand Up @@ -88,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) {
Expand All @@ -96,6 +100,7 @@ class Main extends Component {
});
setDataSource({ dataSourceId });
}
dataSourceObservable.next({ id: dataSourceId, label: dataSourceLabel });
if (this.state.dataSourceLoading) {
this.setState({
dataSourceLoading: false,
Expand Down
14 changes: 13 additions & 1 deletion public/pages/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@
* SPDX-License-Identifier: Apache-2.0
*/

export const COMMENTS_ENABLED_SETTING = "plugins.alerting.comments_enabled";
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<DataSourceOption>(LocalCluster);
22 changes: 22 additions & 0 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
import { ContentManagementPluginStart } from '../../../src/plugins/content_management/public';
import { registerAlertsCard } from './utils/helpers';

Expand Down Expand Up @@ -56,6 +59,16 @@ export interface AlertingStartDeps {

export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetupDeps, AlertingStartDeps> {

private updateDefaultRouteOfManagementApplications: AppUpdater = () => {
const hash = `#/?dataSourceId=${dataSourceObservable.value?.id || ""}`;
return {
defaultPath: hash,
};
};

private appStateUpdater = new BehaviorSubject<AppUpdater>(this.updateDefaultRouteOfManagementApplications);


public setup(core: CoreSetup<AlertingStartDeps, AlertingStart>, { expressions, uiActions, dataSourceManagement, dataSource }: AlertingSetupDeps) {

const mountWrapper = async (params: AppMountParameters, redirect: string) => {
Expand Down Expand Up @@ -105,6 +118,7 @@ export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetup
title: 'Alerts',
order: 9070,
category: DEFAULT_APP_CATEGORIES.detect,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, "/dashboard");
},
Expand All @@ -115,6 +129,7 @@ export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetup
title: 'Monitors',
order: 9070,
category: DEFAULT_APP_CATEGORIES.detect,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, "/monitors");
},
Expand All @@ -125,11 +140,18 @@ export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetup
title: 'Destinations',
order: 9070,
category: DEFAULT_APP_CATEGORIES.detect,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, "/destinations");
},
});

dataSourceObservable.subscribe((dataSourceOption) => {
if (dataSourceOption) {
this.appStateUpdater.next(this.updateDefaultRouteOfManagementApplications);
}
});

const navLinks = [
{
id: ALERTS_NAV_ID,
Expand Down
Loading

0 comments on commit d4862dc

Please sign in to comment.