Skip to content

Commit

Permalink
Persist dataSourceId across applications under new Nav change (#1088) (
Browse files Browse the repository at this point in the history
…#1090)

* Persist datasource across Apps

* feat: enable passing data source info within ISM

* Fixed duplicate app in navigation

* Added description to features

---------

(cherry picked from commit 6216c69)

Signed-off-by: Prabhat Sharma <[email protected]>
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>
Co-authored-by: Prabhat Sharma <[email protected]>
Co-authored-by: SuZhou-Joe <[email protected]>
(cherry picked from commit cab3758)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 23, 2024
1 parent 1815132 commit e66c237
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 17 deletions.
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
102 changes: 87 additions & 15 deletions public/plugin.ts
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,8 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 9010,
category: DEFAULT_APP_CATEGORIES.management,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.index_management,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
const { renderApp } = await import("./index_management_app");
const [coreStart, depsStart] = await core.getStartServices();
Expand All @@ -98,28 +157,15 @@ export class IndexManagementPlugin implements Plugin<IndexManagementPluginSetup,
order: 9020,
category: DEFAULT_APP_CATEGORIES.management,
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
description: ISM_FEATURE_DESCRIPTION.snapshot_management,
updater$: this.appStateUpdater,
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 +176,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 +190,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 +204,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 +218,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 +232,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 @@ -190,6 +246,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 @@ -202,6 +260,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 @@ -214,6 +274,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 @@ -226,6 +288,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 @@ -238,12 +302,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

0 comments on commit e66c237

Please sign in to comment.