Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] bug fix to switch to default datasource instead of local cluster when initial loading #1201

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';


Loading