Skip to content

Commit

Permalink
testing default ds switch changes (#1199) (#1201)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5d3801a)

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent eb2279c commit 1ddfde7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
14 changes: 5 additions & 9 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ export default class Main extends Component<MainProps, MainState> {
};
dataSourceId = parsedDataSourceId;
dataSourceLabel = parsedDataSourceLabel || '';

if (dataSourceId) {
dataSourceObservable.next({ id: dataSourceId, label: dataSourceLabel });
}
}

this.state = {
Expand Down Expand Up @@ -275,17 +271,17 @@ export default class Main extends Component<MainProps, MainState> {
this.setState({
selectedDataSource: { ...sources[0] },
});
DataStore.logTypes.getLogTypes();
dataSourceObservable.next(
dataSourceInfo.activeDataSource
);
}
dataSourceObservable.next({
id: this.state.selectedDataSource.id,
label: this.state.selectedDataSource.label,
});

if (dataSourceLoading) {
this.setState({ dataSourceLoading: false });
}
};


setDataSourceMenuReadOnly = (readOnly: boolean) => {
this.setState({ dataSourceMenuReadOnly: readOnly });
};
Expand Down
15 changes: 12 additions & 3 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,19 @@ export class SecurityAnalyticsPlugin
) {}

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 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}`;
}
return {
defaultPath: hash,
};
defaultPath: hash
}
};

private appStateUpdater = new BehaviorSubject<AppUpdater>(
Expand Down
5 changes: 4 additions & 1 deletion public/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ 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>({});

export const DATA_SOURCE_NOT_SET_ERROR = 'Data source is not set';


0 comments on commit 1ddfde7

Please sign in to comment.