From d2adf23d0c49caca5f5eb19acbce8424c0458cef Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Sun, 27 Oct 2024 23:10:27 -0700 Subject: [PATCH] testing default ds switch changes Signed-off-by: Riya Saxena --- public/components/MDS/DataSourceMenuWrapper.tsx | 2 +- public/components/PageHeader/PageHeader.tsx | 1 + public/pages/Main/Main.tsx | 17 +++++++++-------- public/plugin.ts | 15 +++++++++++---- public/utils/constants.ts | 3 ++- public/utils/helpers.tsx | 2 +- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/public/components/MDS/DataSourceMenuWrapper.tsx b/public/components/MDS/DataSourceMenuWrapper.tsx index 69ddc841..e612532b 100644 --- a/public/components/MDS/DataSourceMenuWrapper.tsx +++ b/public/components/MDS/DataSourceMenuWrapper.tsx @@ -80,7 +80,7 @@ export const DataSourceMenuWrapper: React.FC = ({ }); if (matchedPath) { - // should have the data source id in url, if not then redirect back to the overview or related page for each path + // should have the data source id in url, if not then redirect back to the overview or related page for each path\ const searchParams = new URLSearchParams(location.search); const dataSourceId = searchParams.get('dataSourceId'); if (dataSourceId !== null && dataSourceId !== undefined) { diff --git a/public/components/PageHeader/PageHeader.tsx b/public/components/PageHeader/PageHeader.tsx index 548967cd..2efe7caf 100644 --- a/public/components/PageHeader/PageHeader.tsx +++ b/public/components/PageHeader/PageHeader.tsx @@ -9,6 +9,7 @@ import { TopNavControlDescriptionData, } from '../../../../../src/plugins/navigation/public'; import { getApplication, getNavigationUI, getUseUpdatedUx } from '../../services/utils/constants'; +import {useUpdateUrlWithDataSourceProperties} from "../../utils/helpers"; export interface PageHeaderProps { appRightControls?: TopNavControlData[]; diff --git a/public/pages/Main/Main.tsx b/public/pages/Main/Main.tsx index e3a548dc..a3b27a45 100644 --- a/public/pages/Main/Main.tsx +++ b/public/pages/Main/Main.tsx @@ -146,6 +146,7 @@ export default class Main extends Component { }; let dataSourceId = ''; let dataSourceLabel = ''; + console.log("props location is ", this.props.location); if (props.multiDataSourceEnabled) { const { dataSourceId: parsedDataSourceId, @@ -156,10 +157,8 @@ export default class Main extends Component { }; dataSourceId = parsedDataSourceId; dataSourceLabel = parsedDataSourceLabel || ''; - - if (dataSourceId) { - dataSourceObservable.next({ id: dataSourceId, label: dataSourceLabel }); - } + console.log("dataSourceId is ", dataSourceId); + console.log("DataSource observable is ", dataSourceObservable); } this.state = { @@ -275,11 +274,13 @@ export default class Main extends Component { this.setState({ selectedDataSource: { ...sources[0] }, }); + console.log("DataSource observable is 3 ", sources[0]); + dataSourceObservable.next( + dataSourceInfo.activeDataSource + ); + console.log("DataSource observable is 4 ", dataSourceObservable); } - dataSourceObservable.next({ - id: this.state.selectedDataSource.id, - label: this.state.selectedDataSource.label, - }); + if (dataSourceLoading) { this.setState({ dataSourceLoading: false }); } diff --git a/public/plugin.ts b/public/plugin.ts index 54a74f43..ff0d09de 100644 --- a/public/plugin.ts +++ b/public/plugin.ts @@ -74,10 +74,17 @@ export class SecurityAnalyticsPlugin ) {} private updateDefaultRouteOfManagementApplications: AppUpdater = () => { - const hash = `#/?dataSourceId=${dataSourceObservable.value?.id || ''}`; - return { - defaultPath: hash, - }; + const dataSourceValue = dataSourceObservable.value?.id; + console.log("DataSource value is 1 ", dataSourceValue); + let hash = `#/`; + /*** + When data source value is undefined, + it means the data source picker has not determined 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}`; + } }; private appStateUpdater = new BehaviorSubject( diff --git a/public/utils/constants.ts b/public/utils/constants.ts index c3355678..e7949448 100644 --- a/public/utils/constants.ts +++ b/public/utils/constants.ts @@ -316,4 +316,5 @@ const LocalCluster: DataSourceOption = { id: '', }; -export const dataSourceObservable = new BehaviorSubject(LocalCluster); +// We should use empty object for default value as local cluster may be disabled +export const dataSourceObservable = new BehaviorSubject({}); diff --git a/public/utils/helpers.tsx b/public/utils/helpers.tsx index 97423a5c..28d69a12 100644 --- a/public/utils/helpers.tsx +++ b/public/utils/helpers.tsx @@ -17,7 +17,7 @@ import { } from '@elastic/eui'; import moment from 'moment'; import { PeriodSchedule } from '../../models/interfaces'; -import React from 'react'; +import React, {useContext, useEffect} from 'react'; import { ALERT_SEVERITY_OPTIONS, ALERT_SEVERITY_PROPS,