Skip to content

Commit

Permalink
feat: register advanced settings under Management library
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Aug 28, 2023
1 parent e2f277c commit 3a8d01c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { PageWrapper } from './page_wrapper';
Original file line number Diff line number Diff line change
@@ -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 (
<EuiPageContent
style={props.fullWidth ? {} : { maxWidth: '75%', marginTop: '20px' }}
hasShadow={false}
hasBorder={false}
panelPaddingSize="none"
horizontalPosition="center"
color="transparent"
{...props}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;

Expand All @@ -72,21 +86,23 @@ export async function mountManagementSection(
}

ReactDOM.render(
<I18nProvider>
<Router history={params.history}>
<Switch>
<Route path={['/:query', '/']}>
<AdvancedSettings
enableSaving={canSave}
toasts={notifications.toasts}
dockLinks={docLinks.links}
uiSettings={uiSettings}
componentRegistry={componentRegistry}
/>
</Route>
</Switch>
</Router>
</I18nProvider>,
<PageWrapper>
<I18nProvider>
<Router history={params.history}>
<Switch>
<Route path={['/:query', '/']}>
<AdvancedSettings
enableSaving={canSave}
toasts={notifications.toasts}
dockLinks={docLinks.links}
uiSettings={uiSettings}
componentRegistry={componentRegistry}
/>
</Route>
</Switch>
</Router>
</I18nProvider>
</PageWrapper>,
params.element
);
return () => {
Expand Down
20 changes: 12 additions & 8 deletions src/plugins/advanced_settings/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -43,17 +44,20 @@ const title = i18n.translate('advancedSettings.advancedSettingsLabel', {
export class AdvancedSettingsPlugin
implements Plugin<AdvancedSettingsSetup, AdvancedSettingsStart, AdvancedSettingsPluginSetup> {
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
);
},
});

Expand Down

0 comments on commit 3a8d01c

Please sign in to comment.