Skip to content

Commit

Permalink
move index pattern to Library (opensearch-project#91)
Browse files Browse the repository at this point in the history
* move index pattern to libaray

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* Remove it from Dashboards management when workspace is on

Signed-off-by: Hailong Cui <ihailong@amazon.com>

---------

Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Sep 20, 2023
1 parent d7d712e commit 8408258
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { i18n } from '@osd/i18n';
import { I18nProvider } from '@osd/i18n/react';
import { StartServicesAccessor } from 'src/core/public';

import { EuiPage, EuiPageBody } from '@elastic/eui';
import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public';
import { ManagementAppMountParams } from '../../../management/public';
import {
Expand All @@ -60,7 +61,8 @@ const readOnlyBadge = {
export async function mountManagementSection(
getStartServices: StartServicesAccessor<IndexPatternManagementStartDependencies>,
params: ManagementAppMountParams,
getMlCardState: () => MlCardState
getMlCardState: () => MlCardState,
withPage: boolean = false
) {
const [
{ chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks },
Expand Down Expand Up @@ -90,26 +92,36 @@ export async function mountManagementSection(
dataSourceEnabled,
};

const router = (
<Router history={params.history}>
<Switch>
<Route path={['/create']}>
<CreateIndexPatternWizardWithRouter />
</Route>
<Route path={['/patterns/:id/field/:fieldName', '/patterns/:id/create-field/']}>
<CreateEditFieldContainer />
</Route>
<Route path={['/patterns/:id']}>
<EditIndexPatternContainer />
</Route>
<Route path={['/']}>
<IndexPatternTableWithRouter canSave={canSave} />
</Route>
</Switch>
</Router>
);
let content = router;
if (withPage) {
content = (
<EuiPage restrictWidth="1200px">
<EuiPageBody component="main">{router}</EuiPageBody>
</EuiPage>
);
}

ReactDOM.render(
<OpenSearchDashboardsContextProvider services={deps}>
<I18nProvider>
<Router history={params.history}>
<Switch>
<Route path={['/create']}>
<CreateIndexPatternWizardWithRouter />
</Route>
<Route path={['/patterns/:id/field/:fieldName', '/patterns/:id/create-field/']}>
<CreateEditFieldContainer />
</Route>
<Route path={['/patterns/:id']}>
<EditIndexPatternContainer />
</Route>
<Route path={['/']}>
<IndexPatternTableWithRouter canSave={canSave} />
</Route>
</Switch>
</Router>
</I18nProvider>
<I18nProvider>{content}</I18nProvider>
</OpenSearchDashboardsContextProvider>,
params.element
);
Expand Down
68 changes: 64 additions & 4 deletions src/plugins/index_pattern_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
*/

import { i18n } from '@osd/i18n';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'src/core/public';
import {
PluginInitializerContext,
CoreSetup,
CoreStart,
Plugin,
AppMountParameters,
ChromeBreadcrumb,
ScopedHistory,
} from 'src/core/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { DataSourcePluginStart } from 'src/plugins/data_source/public';
import { UrlForwardingSetup } from '../../url_forwarding/public';
Expand All @@ -39,7 +47,9 @@ import {
IndexPatternManagementServiceStart,
} from './service';

import { ManagementSetup } from '../../management/public';
import { ManagementAppMountParams, ManagementSetup } from '../../management/public';
import { DEFAULT_APP_CATEGORIES } from '../../../core/public';
import { reactRouterNavigate } from '../../opensearch_dashboards_react/public';

export interface IndexPatternManagementSetupDependencies {
management: ManagementSetup;
Expand All @@ -51,7 +61,9 @@ export interface IndexPatternManagementStartDependencies {
dataSource?: DataSourcePluginStart;
}

export type IndexPatternManagementSetup = IndexPatternManagementServiceSetup;
export interface IndexPatternManagementSetup extends IndexPatternManagementServiceSetup {
registerLibrarySubApp: () => void;
}

export type IndexPatternManagementStart = IndexPatternManagementServiceStart;

Expand Down Expand Up @@ -109,7 +121,55 @@ export class IndexPatternManagementPlugin
},
});

return this.indexPatternManagementService.setup({ httpClient: core.http });
const registerLibrarySubApp = () => {
// disable it under Dashboards Management
opensearchDashboardsSection.getApp(IPM_APP_ID)?.disable();
// register it under Library
core.application.register({
id: IPM_APP_ID,
title: sectionsHeader,
order: 8100,
category: DEFAULT_APP_CATEGORIES.opensearchDashboards,
mount: async (params: AppMountParameters) => {
const { mountManagementSection } = await import('./management_app');

const [coreStart] = await core.getStartServices();

const setBreadcrumbsScope = (
crumbs: ChromeBreadcrumb[] = [],
appHistory?: ScopedHistory
) => {
const wrapBreadcrumb = (item: ChromeBreadcrumb, scopedHistory: ScopedHistory) => ({
...item,
...(item.href ? reactRouterNavigate(scopedHistory, item.href) : {}),
});

coreStart.chrome.setBreadcrumbs([
...crumbs.map((item) => wrapBreadcrumb(item, appHistory || params.history)),
]);
};

const managementParams: ManagementAppMountParams = {
element: params.element,
history: params.history,
setBreadcrumbs: setBreadcrumbsScope,
basePath: params.appBasePath,
};

return mountManagementSection(
core.getStartServices,
managementParams,
() => this.indexPatternManagementService.environmentService.getEnvironment().ml(),
true
);
},
});
};

return {
...this.indexPatternManagementService.setup({ httpClient: core.http }),
registerLibrarySubApp,
};
}

public start(core: CoreStart, plugins: IndexPatternManagementStartDependencies) {
Expand Down

0 comments on commit 8408258

Please sign in to comment.