Skip to content

Commit

Permalink
fix: default data source (#1143) (#1144)
Browse files Browse the repository at this point in the history
* fix: default data source



* feat: optimize



* feat: update comment



---------


(cherry picked from commit 40baf85)

Signed-off-by: SuZhou-Joe <[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 42e8906 commit d204033
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 8 additions & 7 deletions public/pages/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { DataSourceOption } from "../../../../../src/plugins/data_source_managem

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);
label: i18n.translate("dataSource.localCluster", {
defaultMessage: "Local cluster",
}),
id: "",
};

// We should use empty object for default value as local cluster may be disabled
export const dataSourceObservable = new BehaviorSubject<DataSourceOption>({});
9 changes: 8 additions & 1 deletion public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ export interface AlertingStartDeps {
export class AlertingPlugin implements Plugin<void, AlertingStart, AlertingSetupDeps, AlertingStartDeps> {

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 determine 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,
};
Expand Down

0 comments on commit d204033

Please sign in to comment.