From cab37582bcb527a01898cf8d7956a804485f229c Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:12:41 +0800 Subject: [PATCH] Persist dataSourceId across applications under new Nav change (#1088) (#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 6216c697c96bd9530d8cf3dc62c4be2d0aeccdc3) Signed-off-by: Prabhat Sharma Signed-off-by: SuZhou-Joe Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] Co-authored-by: Prabhat Sharma Co-authored-by: SuZhou-Joe --- public/pages/Main/Main.tsx | 25 ++++++++- public/plugin.ts | 102 +++++++++++++++++++++++++++++++------ 2 files changed, 110 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 f2df956c8..98c179d78 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,8 @@ export class IndexManagementPlugin implements Plugin { const { renderApp } = await import("./index_management_app"); const [coreStart, depsStart] = await core.getStartServices(); @@ -98,6 +157,8 @@ export class IndexManagementPlugin implements Plugin { const { renderApp } = await import("./index_management_app"); const [coreStart, depsStart] = await core.getStartServices(); @@ -105,21 +166,6 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.INDICES); }, @@ -142,6 +190,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.MANAGED_INDICES); }, @@ -154,6 +204,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.DATA_STREAMS); }, @@ -166,6 +218,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.ALIASES); }, @@ -178,6 +232,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.TEMPLATES); }, @@ -190,6 +246,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.NOTIFICATIONS); }, @@ -202,6 +260,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.ROLLUPS); }, @@ -214,6 +274,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.TRANSFORMS); }, @@ -226,6 +288,8 @@ export class IndexManagementPlugin implements Plugin { return mountWrapper(params, ROUTES.SNAPSHOTS); }, @@ -238,12 +302,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)}`,