Skip to content

Commit

Permalink
testing default ds switch changes
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Saxena <[email protected]>
  • Loading branch information
riysaxen-amzn committed Oct 28, 2024
1 parent 5a1d5dd commit d2adf23
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion public/components/MDS/DataSourceMenuWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
});

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) {
Expand Down
1 change: 1 addition & 0 deletions public/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
17 changes: 9 additions & 8 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export default class Main extends Component<MainProps, MainState> {
};
let dataSourceId = '';
let dataSourceLabel = '';
console.log("props location is ", this.props.location);
if (props.multiDataSourceEnabled) {
const {
dataSourceId: parsedDataSourceId,
Expand All @@ -156,10 +157,8 @@ export default class Main extends Component<MainProps, MainState> {
};
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 = {
Expand Down Expand Up @@ -275,11 +274,13 @@ export default class Main extends Component<MainProps, MainState> {
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 });
}
Expand Down
15 changes: 11 additions & 4 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppUpdater>(
Expand Down
3 changes: 2 additions & 1 deletion public/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,5 @@ const LocalCluster: DataSourceOption = {
id: '',
};

export const dataSourceObservable = new BehaviorSubject<DataSourceOption>(LocalCluster);
// We should use empty object for default value as local cluster may be disabled
export const dataSourceObservable = new BehaviorSubject<DataSourceOption>({});
2 changes: 1 addition & 1 deletion public/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d2adf23

Please sign in to comment.