From 6216c697c96bd9530d8cf3dc62c4be2d0aeccdc3 Mon Sep 17 00:00:00 2001 From: Prabhat <20185657+CaptainDredge@users.noreply.github.com> Date: Fri, 19 Jul 2024 13:00:42 +0530 Subject: [PATCH] Persist dataSourceId across applications under new Nav change (#1088) * Persist datasource across Apps Signed-off-by: Prabhat Sharma * feat: enable passing data source info within ISM Signed-off-by: SuZhou-Joe Signed-off-by: Prabhat Sharma * Fixed duplicate app in navigation Signed-off-by: Prabhat Sharma * Added description to features Signed-off-by: Prabhat Sharma --------- Signed-off-by: Prabhat Sharma Signed-off-by: SuZhou-Joe Co-authored-by: Prabhat Sharma Co-authored-by: SuZhou-Joe --- public/pages/Main/Main.tsx | 25 ++++++++- public/plugin.ts | 104 +++++++++++++++++++++++++++++++------ 2 files changed, 112 insertions(+), 17 deletions(-) diff --git a/public/pages/Main/Main.tsx b/public/pages/Main/Main.tsx index b36430bc9..fc0590be7 100644 --- a/public/pages/Main/Main.tsx +++ b/public/pages/Main/Main.tsx @@ -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", @@ -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(LocalCluster); + export default class Main extends Component { constructor(props: MainProps) { super(props); @@ -201,14 +212,23 @@ export default class Main extends Component { 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, }; } @@ -263,6 +283,7 @@ export default class Main extends Component { dataSourceId: id, dataSourceLabel: label, }); + dataSourceObservable.next({ id, label }); } if (this.state.dataSourceLoading) { this.setState({ diff --git a/public/plugin.ts b/public/plugin.ts index 6f265e536..087c4b49f 100644 --- a/public/plugin.ts +++ b/public/plugin.ts @@ -8,6 +8,7 @@ import { IndexManagementPluginStart, IndexManagementPluginSetup } from "."; import { AppCategory, AppMountParameters, + AppUpdater, CoreSetup, CoreStart, DEFAULT_APP_CATEGORIES, @@ -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; @@ -42,11 +45,65 @@ const ISM_CATEGORIES: Record = Object.freeze({ }, }); +const ISM_FEATURE_DESCRIPTION: Record = 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 { 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(this.updateDefaultRouteOfManagementApplications); + public setup(core: CoreSetup, { managementOverview, dataSourceManagement }: IndexManagementSetupDeps): IndexManagementPluginSetup { JobHandlerRegister(core); @@ -85,6 +142,7 @@ export class IndexManagementPlugin implements Plugin { const { renderApp } = await import("./index_management_app"); const [coreStart, depsStart] = await core.getStartServices(); @@ -98,6 +156,7 @@ export class IndexManagementPlugin implements Plugin { const { renderApp } = await import("./index_management_app"); const [coreStart, depsStart] = await core.getStartServices(); @@ -105,21 +164,6 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.INDICES); }, @@ -142,6 +188,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.MANAGED_INDICES); }, @@ -154,6 +202,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.DATA_STREAMS); }, @@ -166,6 +216,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.ALIASES); }, @@ -178,6 +230,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.INDEX_POLICIES); }, @@ -190,6 +244,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.TEMPLATES); }, @@ -202,6 +258,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.NOTIFICATIONS); }, @@ -214,6 +272,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.ROLLUPS); }, @@ -226,6 +286,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.TRANSFORMS); }, @@ -238,6 +300,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.SNAPSHOTS); }, @@ -250,6 +314,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.SNAPSHOT_POLICIES); }, @@ -262,12 +328,20 @@ export class IndexManagementPlugin implements Plugin { 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)}`,