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

Persist dataSourceId across applications under new Nav change #1088

Merged
merged 4 commits into from
Jul 19, 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
25 changes: 23 additions & 2 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import {
import { DataSourceOption } from "../../../../../src/plugins/data_source_management/public/components/data_source_menu/types";
import * as pluginManifest from "../../../opensearch_dashboards.json";
import { DataSourceAttributes } from "../../../../../src/plugins/data_source/common/data_sources";
import { BehaviorSubject } from "rxjs";
import { i18n } from "@osd/i18n";

enum Navigation {
IndexManagement = "Index Management",
Expand Down Expand Up @@ -189,6 +191,15 @@ const dataSourceEnabledPaths: string[] = [
ROUTES.EDIT_REPOSITORY,
];

const LocalCluster: DataSourceOption = {
label: i18n.translate("dataSource.localCluster", {
defaultMessage: "Local cluster",
}),
id: "",
};

export const dataSourceObservable = new BehaviorSubject<DataSourceOption>(LocalCluster);

export default class Main extends Component<MainProps, MainState> {
constructor(props: MainProps) {
super(props);
Expand All @@ -201,14 +212,23 @@ export default class Main extends Component<MainProps, MainState> {
dataSourceId: string;
dataSourceLabel: string;
};
dataSourceId = parsedDataSourceId || "";
dataSourceId = parsedDataSourceId;
dataSourceLabel = parsedDataSourceLabel || "";

if (dataSourceId) {
dataSourceObservable.next({ id: dataSourceId, label: dataSourceLabel });
}
}
this.state = {
dataSourceId,
dataSourceLabel,
dataSourceReadOnly: false,
dataSourceLoading: props.multiDataSourceEnabled,
/**
* undefined: need data source picker to help to determine which data source to use.
* empty string: using the local cluster.
* string: using the selected data source.
*/
dataSourceLoading: dataSourceId === undefined ? props.multiDataSourceEnabled : false,
};
}

Expand Down Expand Up @@ -263,6 +283,7 @@ export default class Main extends Component<MainProps, MainState> {
dataSourceId: id,
dataSourceLabel: label,
});
dataSourceObservable.next({ id, label });
}
if (this.state.dataSourceLoading) {
this.setState({
Expand Down
104 changes: 89 additions & 15 deletions public/plugin.ts
CaptainDredge marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IndexManagementPluginStart, IndexManagementPluginSetup } from ".";
import {
AppCategory,
AppMountParameters,
AppUpdater,
CoreSetup,
CoreStart,
DEFAULT_APP_CATEGORIES,
Expand All @@ -21,6 +22,8 @@ import { ROUTES } from "./utils/constants";
import { JobHandlerRegister } from "./JobHandler";
import { ManagementOverViewPluginSetup } from "../../../src/plugins/management_overview/public";
import { DataSourceManagementPluginSetup } from "../../../src/plugins/data_source_management/public";
import { dataSourceObservable } from "./pages/Main/Main";
import { BehaviorSubject } from "rxjs";

interface IndexManagementSetupDeps {
managementOverview?: ManagementOverViewPluginSetup;
Expand All @@ -42,11 +45,65 @@ const ISM_CATEGORIES: Record<string, AppCategory> = Object.freeze({
},
});

const ISM_FEATURE_DESCRIPTION: Record<string, string> = Object.freeze({
index_management: i18n.translate("indexManagement.description", {
defaultMessage: "Manage your indexes with state polices, templates and aliases. You can also roll up or transform your indexes.",
}),
snapshot_management: i18n.translate("snapshotManagement.description", {
defaultMessage: "Back up and restore your cluster's indexes and state. Setup a policy to automate snapshot creation and deletion.",
}),
indexes: i18n.translate("indexes.description", {
defaultMessage: "Manage your indexes",
}),
policy_managed_indexes: i18n.translate("policyManagedIndexes.description", {
defaultMessage: "Manage your policy managed indexes",
}),
data_streams: i18n.translate("dataStreams.description", {
defaultMessage: "Manage your data streams",
}),
aliases: i18n.translate("aliases.description", {
defaultMessage: "Manage your index aliases",
}),
index_state_management_policies: i18n.translate("indexStateManagementPolicies.description", {
defaultMessage: "Manage your index state management policies",
}),
index_templates: i18n.translate("indexTemplates.description", {
defaultMessage: "Manage your index templates",
}),
notification_settings: i18n.translate("notificationSettings.description", {
defaultMessage: "Manage your notification settings",
}),
rollup_jobs: i18n.translate("rollupJobs.description", {
defaultMessage: "Manage your rollup jobs",
}),
transform_jobs: i18n.translate("transformJobs.description", {
defaultMessage: "Manage your transform jobs",
}),
index_snapshots: i18n.translate("indexSnapshots.description", {
defaultMessage: "Manage your index snapshots",
}),
snapshot_policies: i18n.translate("snapshotPolicies.description", {
defaultMessage: "Manage your snapshot policies",
}),
snapshot_repositories: i18n.translate("snapshotRepositories.description", {
defaultMessage: "Manage your snapshot repositories",
}),
});

export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup, IndexManagementPluginStart, IndexManagementSetupDeps> {
constructor(private readonly initializerContext: PluginInitializerContext) {
// can retrieve config from initializerContext
}

private updateDefaultRouteOfManagementApplications: AppUpdater = () => {
const hash = `#/?dataSourceId=${dataSourceObservable.value?.id || ""}`;
return {
defaultPath: hash,
};
};

private appStateUpdater = new BehaviorSubject<AppUpdater>(this.updateDefaultRouteOfManagementApplications);

public setup(core: CoreSetup, { managementOverview, dataSourceManagement }: IndexManagementSetupDeps): IndexManagementPluginSetup {
JobHandlerRegister(core);

Expand Down Expand Up @@ -85,6 +142,7 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 9010,
category: DEFAULT_APP_CATEGORIES.management,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.index_management,
mount: async (params: AppMountParameters) => {
const { renderApp } = await import("./index_management_app");
const [coreStart, depsStart] = await core.getStartServices();
Expand All @@ -98,28 +156,14 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 9020,
category: DEFAULT_APP_CATEGORIES.management,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.snapshot_management,
mount: async (params: AppMountParameters) => {
const { renderApp } = await import("./index_management_app");
const [coreStart, depsStart] = await core.getStartServices();
return renderApp(coreStart, depsStart, params, ROUTES.SNAPSHOT_POLICIES, dataSourceManagement);
},
});

// Register with category and use case information
core.chrome.navGroup.addNavLinksToGroup(DEFAULT_NAV_GROUPS.dataAdministration, [
{
id: imApplicationID,
category: DEFAULT_APP_CATEGORIES.management,
},
]);

core.chrome.navGroup.addNavLinksToGroup(DEFAULT_NAV_GROUPS.dataAdministration, [
{
id: smApplicationID,
category: DEFAULT_APP_CATEGORIES.management,
},
]);

// In-app navigation registration

if (core.chrome.navGroup.getNavGroupEnabled()) {
Expand All @@ -130,6 +174,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.indexes,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.INDICES);
},
Expand All @@ -142,6 +188,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.policy_managed_indexes,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.MANAGED_INDICES);
},
Expand All @@ -154,6 +202,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.data_streams,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.DATA_STREAMS);
},
Expand All @@ -166,6 +216,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.aliases,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.ALIASES);
},
Expand All @@ -178,6 +230,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.index_state_management_policies,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.INDEX_POLICIES);
},
Expand All @@ -190,6 +244,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.index_templates,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.TEMPLATES);
},
Expand All @@ -202,6 +258,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.notification_settings,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.NOTIFICATIONS);
},
Expand All @@ -214,6 +272,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.rollup_jobs,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.ROLLUPS);
},
Expand All @@ -226,6 +286,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.indexes,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.transform_jobs,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.TRANSFORMS);
},
Expand All @@ -238,6 +300,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.index_backup_and_recovery,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.index_snapshots,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.SNAPSHOTS);
},
Expand All @@ -250,6 +314,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.index_backup_and_recovery,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.snapshot_policies,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.SNAPSHOT_POLICIES);
},
Expand All @@ -262,12 +328,20 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 8040,
category: ISM_CATEGORIES.index_backup_and_recovery,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.snapshot_repositories,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.REPOSITORIES);
},
});
}

dataSourceObservable.subscribe((dataSourceOption) => {
if (dataSourceOption) {
this.appStateUpdater.next(this.updateDefaultRouteOfManagementApplications);
}
});

core.chrome.navGroup.addNavLinksToGroup(DEFAULT_NAV_GROUPS.dataAdministration, [
{
id: `opensearch_index_management_dashboards_${encodeURIComponent(ROUTES.INDICES)}`,
Expand Down
Loading