Skip to content

Commit

Permalink
remove overview register setup in start phase
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Jul 6, 2023
1 parent e2be9ce commit 01d8ea6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 77 deletions.
8 changes: 2 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Bump OUI to `1.1.2` to make `anomalyDetection` icon available ([#4408](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4408))
- Add `color-scheme` to the root styling ([#4477](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4477))
- [Multiple DataSource] Frontend support for adding sample data ([#4412](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4412))
- New management overview page and rename stack management to dashboard management ([#4287](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4287))


### 🐛 Bug Fixes

Expand Down Expand Up @@ -84,12 +86,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### 🔩 Tests

## [2.9.0 - TBD]

### 📈 Features/Enhancements

- New management overview page and rename stack management to dashboard management ([#4287](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4287))

## [2.8.0 - 2023-06-06](https://github.com/opensearch-project/OpenSearch-Dashboards/releases/tag/2.8.0)

### Deprecations
Expand Down
48 changes: 22 additions & 26 deletions src/plugins/dev_tools/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,23 @@
*/

import { BehaviorSubject } from 'rxjs';
import { Plugin, CoreSetup, AppMountParameters, CoreStart } from 'src/core/public';
import { Plugin, CoreSetup, AppMountParameters } from 'src/core/public';
import { AppUpdater } from 'opensearch-dashboards/public';
import { i18n } from '@osd/i18n';
import { sortBy } from 'lodash';

import { DataSourcePluginStart } from 'src/plugins/data_source/public';
import { DataSourcePluginSetup } from 'src/plugins/data_source/public';
import { AppNavLinkStatus, DEFAULT_APP_CATEGORIES } from '../../../core/public';
import { UrlForwardingSetup } from '../../url_forwarding/public';
import { CreateDevToolArgs, DevToolApp, createDevToolApp } from './dev_tool';

import './index.scss';
import { ManagementOverViewPluginStart } from '../../management_overview/public';
import { ManagementOverViewPluginSetup } from '../../management_overview/public';

export interface DevToolsSetupDependencies {
dataSource?: DataSourcePluginStart;
}

export interface DevToolsStartDependencies {
managementOverview?: ManagementOverViewPluginStart;
dataSource?: DataSourcePluginSetup;
urlForwarding: UrlForwardingSetup;
managementOverview?: ManagementOverViewPluginSetup;
}

export interface DevToolsSetup {
Expand All @@ -64,7 +62,7 @@ export interface DevToolsSetup {
register: (devTool: CreateDevToolArgs) => DevToolApp;
}

export class DevToolsPlugin implements Plugin<DevToolsSetup, void> {
export class DevToolsPlugin implements Plugin<DevToolsSetup> {
private readonly devTools = new Map<string, DevToolApp>();
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));

Expand All @@ -76,11 +74,9 @@ export class DevToolsPlugin implements Plugin<DevToolsSetup, void> {
defaultMessage: 'Dev Tools',
});

public setup(
coreSetup: CoreSetup<DevToolsSetupDependencies>,
{ urlForwarding }: { urlForwarding: UrlForwardingSetup }
) {
public setup(coreSetup: CoreSetup, deps: DevToolsSetupDependencies) {
const { application: applicationSetup, getStartServices } = coreSetup;
const { urlForwarding, managementOverview } = deps;

applicationSetup.register({
id: 'dev_tools',
Expand All @@ -93,13 +89,23 @@ export class DevToolsPlugin implements Plugin<DevToolsSetup, void> {
const { element, history } = params;
element.classList.add('devAppWrapper');

const [core, devSetup] = await getStartServices();
const [core] = await getStartServices();

const { renderApp } = await import('./application');
return renderApp(core, element, history, this.getSortedDevTools(), devSetup);
return renderApp(core, element, history, this.getSortedDevTools(), deps);
},
});

managementOverview?.register({
id: 'dev_tools',
title: this.title,
description: i18n.translate('devTools.devToolsDescription', {
defaultMessage:
'Use the console to set up and troubleshoot your OpenSearch environment with the REST API.',
}),
order: 9070,
});

urlForwarding.forwardApp('dev_tools', 'dev_tools');

return {
Expand All @@ -117,19 +123,9 @@ export class DevToolsPlugin implements Plugin<DevToolsSetup, void> {
};
}

public start(core: CoreStart, { managementOverview }: DevToolsStartDependencies) {
public start() {
if (this.getSortedDevTools().length === 0) {
this.appStateUpdater.next(() => ({ navLinkStatus: AppNavLinkStatus.hidden }));
} else {
managementOverview?.register({
id: 'dev_tools',
title: this.title,
description: i18n.translate('devTools.devToolsDescription', {
defaultMessage:
'Use the console to set up and troubleshoot your OpenSearch environment with the REST API.',
}),
order: 9070,
});
}
}

Expand Down
33 changes: 14 additions & 19 deletions src/plugins/management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ import {
ManagementSectionsService,
getSectionsServiceStartPrivate,
} from './management_sections_service';
import { ManagementOverViewPluginStart } from '../../management_overview/public';
import { ManagementOverViewPluginSetup } from '../../management_overview/public';

interface ManagementSetupDependencies {
home?: HomePublicPluginSetup;
}

interface ManagementStartDependencies {
managementOverview?: ManagementOverViewPluginStart;
managementOverview?: ManagementOverViewPluginSetup;
}

export class ManagementPlugin implements Plugin<ManagementSetup, ManagementStart> {
Expand All @@ -72,7 +69,7 @@ export class ManagementPlugin implements Plugin<ManagementSetup, ManagementStart
defaultMessage: 'Dashboards Management',
});

public setup(core: CoreSetup, { home }: ManagementSetupDependencies) {
public setup(core: CoreSetup, { home, managementOverview }: ManagementSetupDependencies) {
const opensearchDashboardsVersion = this.initializerContext.env.packageInfo.version;

core.application.register({
Expand All @@ -94,12 +91,22 @@ export class ManagementPlugin implements Plugin<ManagementSetup, ManagementStart
},
});

managementOverview?.register({
id: MANAGEMENT_APP_ID,
title: this.title,
description: i18n.translate('management.dashboardManagement.description', {
defaultMessage:
'Manage Dashboards saved objects and data source connections. You can also modify advanced settings for Dashboards.',
}),
order: 9030,
});

return {
sections: this.managementSections.setup(),
};
}

public start(core: CoreStart, { managementOverview }: ManagementStartDependencies) {
public start(core: CoreStart) {
this.managementSections.start({ capabilities: core.application.capabilities });
this.hasAnyEnabledApps = getSectionsServiceStartPrivate()
.getSectionsEnabled()
Expand All @@ -114,18 +121,6 @@ export class ManagementPlugin implements Plugin<ManagementSetup, ManagementStart
});
}

if (managementOverview && this.hasAnyEnabledApps) {
managementOverview.register({
id: MANAGEMENT_APP_ID,
title: this.title,
description: i18n.translate('management.dashboardManagement.description', {
defaultMessage:
'Manage Dashboards saved objects and data source connections. You can also modify advanced settings for Dashboards.',
}),
order: 9030,
});
}

return {};
}
}
21 changes: 17 additions & 4 deletions src/plugins/management_overview/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@ import ReactDOM from 'react-dom';
import { I18nProvider, FormattedMessage } from '@osd/i18n/react';
import React from 'react';
import { EuiFlexGrid, EuiFlexItem, EuiPage, EuiPageBody, EuiSpacer, EuiTitle } from '@elastic/eui';
import { ApplicationStart, CoreStart } from '../../../core/public';
import useObservable from 'react-use/lib/useObservable';
import { ApplicationStart, ChromeStart, CoreStart } from '../../../core/public';
import { OverviewApp } from '.';
import { OverviewCard } from './components/overview_card';

export interface ManagementOverviewProps {
application: ApplicationStart;
chrome: ChromeStart;
overviewApps?: OverviewApp[];
}

function ManagementOverviewWrapper(props: ManagementOverviewProps) {
const { application, overviewApps } = props;
const { chrome, application, overviewApps } = props;

const hiddenAppIds =
useObservable(chrome.navLinks.getNavLinks$())
?.filter((link) => link.hidden)
.map((link) => link.id) || [];

const availableApps = overviewApps?.filter((app) => hiddenAppIds.indexOf(app.id) === -1);

return (
<EuiPage restrictWidth={1200}>
Expand All @@ -29,7 +38,7 @@ function ManagementOverviewWrapper(props: ManagementOverviewProps) {
</EuiTitle>
<EuiSpacer />
<EuiFlexGrid columns={3}>
{overviewApps?.map((app) => (
{availableApps?.map((app) => (
<EuiFlexItem key={app.id}>
<OverviewCard
{...app}
Expand All @@ -52,7 +61,11 @@ export function renderApp(
) {
ReactDOM.render(
<I18nProvider>
<ManagementOverviewWrapper application={application} overviewApps={overviewApps} />
<ManagementOverviewWrapper
chrome={chrome}
application={application}
overviewApps={overviewApps}
/>
</I18nProvider>,
element
);
Expand Down
32 changes: 10 additions & 22 deletions src/plugins/management_overview/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,14 @@ interface ManagementOverviewSetupDeps {
export interface ManagementOverViewPluginSetup {
register: (overviewApp: OverviewApp) => void;
}

export type ManagementOverViewPluginStart = ManagementOverViewPluginSetup;

/** @public */
export class ManagementOverViewPlugin
implements Plugin<ManagementOverViewPluginSetup, ManagementOverViewPluginStart> {
export class ManagementOverViewPlugin implements Plugin<ManagementOverViewPluginSetup, void> {
private readonly overviewApps = new Map<string, OverviewApp>();

private getSortedOverviewApps(): OverviewApp[] {
return [...this.overviewApps.values()].sort((a, b) => a.order - b.order);
}

private getRegister() {
return (app: OverviewApp) => {
if (this.overviewApps.has(app.id)) {
throw new Error(
`Management overview App tool with id [${app.id}] has already been registered. Use a unique id.`
);
}
this.overviewApps.set(app.id, app);
};
}

public setup(
coreSetup: CoreSetup,
{ home }: ManagementOverviewSetupDeps
Expand Down Expand Up @@ -86,13 +71,16 @@ export class ManagementOverViewPlugin
});

return {
register: this.getRegister(),
register: (app: OverviewApp) => {
if (this.overviewApps.has(app.id)) {
throw new Error(
`Management overview App tool with id [${app.id}] has already been registered. Use a unique id.`
);
}
this.overviewApps.set(app.id, app);
},
};
}

public start(core: CoreStart): ManagementOverViewPluginStart {
return {
register: this.getRegister(),
};
}
public start(core: CoreStart): void {}
}

0 comments on commit 01d8ea6

Please sign in to comment.