From 3a8d01c159140b8b2c0ff6fb0287ee3b500f99b0 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 28 Aug 2023 17:55:31 +0800 Subject: [PATCH] feat: register advanced settings under Management library Signed-off-by: SuZhou-Joe --- .../components/page_wrapper/index.ts | 6 ++ .../components/page_wrapper/page_wrapper.tsx | 21 +++++++ .../mount_management_section.tsx | 56 ++++++++++++------- .../advanced_settings/public/plugin.ts | 20 ++++--- 4 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 src/plugins/advanced_settings/public/management_app/components/page_wrapper/index.ts create mode 100644 src/plugins/advanced_settings/public/management_app/components/page_wrapper/page_wrapper.tsx diff --git a/src/plugins/advanced_settings/public/management_app/components/page_wrapper/index.ts b/src/plugins/advanced_settings/public/management_app/components/page_wrapper/index.ts new file mode 100644 index 000000000000..3cf0cdd26c99 --- /dev/null +++ b/src/plugins/advanced_settings/public/management_app/components/page_wrapper/index.ts @@ -0,0 +1,6 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export { PageWrapper } from './page_wrapper'; diff --git a/src/plugins/advanced_settings/public/management_app/components/page_wrapper/page_wrapper.tsx b/src/plugins/advanced_settings/public/management_app/components/page_wrapper/page_wrapper.tsx new file mode 100644 index 000000000000..e0b725edc42d --- /dev/null +++ b/src/plugins/advanced_settings/public/management_app/components/page_wrapper/page_wrapper.tsx @@ -0,0 +1,21 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { EuiPageContent } from '@elastic/eui'; +import React from 'react'; + +export const PageWrapper = (props: { fullWidth?: boolean; children?: React.ReactChild }) => { + return ( + + ); +}; diff --git a/src/plugins/advanced_settings/public/management_app/mount_management_section.tsx b/src/plugins/advanced_settings/public/management_app/mount_management_section.tsx index 7fa0b9ddd2c0..27245e31c376 100644 --- a/src/plugins/advanced_settings/public/management_app/mount_management_section.tsx +++ b/src/plugins/advanced_settings/public/management_app/mount_management_section.tsx @@ -34,11 +34,17 @@ import { Router, Switch, Route } from 'react-router-dom'; import { i18n } from '@osd/i18n'; import { I18nProvider } from '@osd/i18n/react'; -import { StartServicesAccessor } from 'src/core/public'; +import { + AppMountParameters, + ChromeBreadcrumb, + ScopedHistory, + StartServicesAccessor, +} from 'src/core/public'; import { AdvancedSettings } from './advanced_settings'; -import { ManagementAppMountParams } from '../../../management/public'; import { ComponentRegistry } from '../types'; +import { reactRouterNavigate } from '../../../opensearch_dashboards_react/public'; +import { PageWrapper } from './components/page_wrapper'; import './index.scss'; @@ -57,13 +63,21 @@ const readOnlyBadge = { iconType: 'glasses', }; -export async function mountManagementSection( +export async function mountAdvancedSettingsManagementSection( getStartServices: StartServicesAccessor, - params: ManagementAppMountParams, + params: AppMountParameters, componentRegistry: ComponentRegistry['start'] ) { - params.setBreadcrumbs(crumb); const [{ uiSettings, notifications, docLinks, application, chrome }] = await getStartServices(); + const setBreadcrumbsScoped = (crumbs: ChromeBreadcrumb[] = []) => { + const wrapBreadcrumb = (item: ChromeBreadcrumb, scopedHistory: ScopedHistory) => ({ + ...item, + ...(item.href ? reactRouterNavigate(scopedHistory, item.href) : {}), + }); + + chrome.setBreadcrumbs([...crumbs.map((item) => wrapBreadcrumb(item, params.history))]); + }; + setBreadcrumbsScoped(crumb); const canSave = application.capabilities.advancedSettings.save as boolean; @@ -72,21 +86,23 @@ export async function mountManagementSection( } ReactDOM.render( - - - - - - - - - , + + + + + + + + + + + , params.element ); return () => { diff --git a/src/plugins/advanced_settings/public/plugin.ts b/src/plugins/advanced_settings/public/plugin.ts index 608bfc6a25e7..d447e3fa992f 100644 --- a/src/plugins/advanced_settings/public/plugin.ts +++ b/src/plugins/advanced_settings/public/plugin.ts @@ -29,10 +29,11 @@ */ import { i18n } from '@osd/i18n'; -import { CoreSetup, Plugin } from 'opensearch-dashboards/public'; +import { AppMountParameters, CoreSetup, Plugin } from 'opensearch-dashboards/public'; import { FeatureCatalogueCategory } from '../../home/public'; import { ComponentRegistry } from './component_registry'; import { AdvancedSettingsSetup, AdvancedSettingsStart, AdvancedSettingsPluginSetup } from './types'; +import { DEFAULT_APP_CATEGORIES } from '../../../core/public'; const component = new ComponentRegistry(); @@ -43,17 +44,20 @@ const title = i18n.translate('advancedSettings.advancedSettingsLabel', { export class AdvancedSettingsPlugin implements Plugin { public setup(core: CoreSetup, { management, home }: AdvancedSettingsPluginSetup) { - const opensearchDashboardsSection = management.sections.section.opensearchDashboards; - - opensearchDashboardsSection.registerApp({ + core.application.register({ id: 'settings', title, - order: 3, - async mount(params) { - const { mountManagementSection } = await import( + order: 99, + category: DEFAULT_APP_CATEGORIES.management, + async mount(params: AppMountParameters) { + const { mountAdvancedSettingsManagementSection } = await import( './management_app/mount_management_section' ); - return mountManagementSection(core.getStartServices, params, component.start); + return mountAdvancedSettingsManagementSection( + core.getStartServices, + params, + component.start + ); }, });