From f7a3a54c5c49aa0431273cb6442cf5bfaa12eb9f Mon Sep 17 00:00:00 2001 From: Kristen Tian <105667444+kristenTian@users.noreply.github.com> Date: Sun, 31 Jul 2022 23:37:35 -0700 Subject: [PATCH] Data source inside stack management setup (#2017) (#2030) Signed-off-by: Kristen Tian --- src/plugins/data_source_management/README.md | 11 +++ .../data_source_management/common/index.ts | 13 ++++ .../opensearch_dashboards.json | 10 +++ .../create_data_source_wizard.tsx | 24 +++++++ .../create_data_source_wizard/index.ts | 12 ++++ .../data_source_table/data_source_table.tsx | 24 +++++++ .../components/data_source_table/index.ts | 12 ++++ .../data_source_management/public/index.ts | 19 ++++++ .../public/management_app/index.ts | 12 ++++ .../mount_management_section.tsx | 67 +++++++++++++++++++ .../data_source_management/public/plugin.ts | 45 +++++++++++++ .../data_source_management/public/types.ts | 41 ++++++++++++ 12 files changed, 290 insertions(+) create mode 100755 src/plugins/data_source_management/README.md create mode 100644 src/plugins/data_source_management/common/index.ts create mode 100644 src/plugins/data_source_management/opensearch_dashboards.json create mode 100644 src/plugins/data_source_management/public/components/create_data_source_wizard/create_data_source_wizard.tsx create mode 100644 src/plugins/data_source_management/public/components/create_data_source_wizard/index.ts create mode 100644 src/plugins/data_source_management/public/components/data_source_table/data_source_table.tsx create mode 100644 src/plugins/data_source_management/public/components/data_source_table/index.ts create mode 100644 src/plugins/data_source_management/public/index.ts create mode 100644 src/plugins/data_source_management/public/management_app/index.ts create mode 100644 src/plugins/data_source_management/public/management_app/mount_management_section.tsx create mode 100644 src/plugins/data_source_management/public/plugin.ts create mode 100644 src/plugins/data_source_management/public/types.ts diff --git a/src/plugins/data_source_management/README.md b/src/plugins/data_source_management/README.md new file mode 100755 index 000000000000..fe1cc9875b09 --- /dev/null +++ b/src/plugins/data_source_management/README.md @@ -0,0 +1,11 @@ +# dataSourceManagement + +A OpenSearch Dashboards plugin + +--- + +## Development + +See the [OpenSearch Dashboards contributing +guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/CONTRIBUTING.md) for instructions +setting up your development environment. diff --git a/src/plugins/data_source_management/common/index.ts b/src/plugins/data_source_management/common/index.ts new file mode 100644 index 000000000000..7c0ba07d7de1 --- /dev/null +++ b/src/plugins/data_source_management/common/index.ts @@ -0,0 +1,13 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +export const PLUGIN_ID = 'dataSourceManagement'; +export const PLUGIN_NAME = 'Data Sources'; diff --git a/src/plugins/data_source_management/opensearch_dashboards.json b/src/plugins/data_source_management/opensearch_dashboards.json new file mode 100644 index 000000000000..e6389d4a2577 --- /dev/null +++ b/src/plugins/data_source_management/opensearch_dashboards.json @@ -0,0 +1,10 @@ +{ + "id": "dataSourceManagement", + "version": "1.0.0", + "opensearchDashboardsVersion": "opensearchDashboards", + "server": false, + "ui": true, + "requiredPlugins": ["management"], + "optionalPlugins": [], + "requiredBundles": ["opensearchDashboardsReact"] +} diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/create_data_source_wizard.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/create_data_source_wizard.tsx new file mode 100644 index 000000000000..59db342ef1b6 --- /dev/null +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/create_data_source_wizard.tsx @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { EuiTitle } from '@elastic/eui'; +import React from 'react'; +import { withRouter } from 'react-router-dom'; + +export const CreateDataSourceWizard = () => { + return ( + +

{'This is the data source creation page'}

+
+ ); +}; + +export const CreateDataSourceWizardWithRouter = withRouter(CreateDataSourceWizard); diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/index.ts b/src/plugins/data_source_management/public/components/create_data_source_wizard/index.ts new file mode 100644 index 000000000000..7975368f61d3 --- /dev/null +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/index.ts @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +export { CreateDataSourceWizardWithRouter } from './create_data_source_wizard'; diff --git a/src/plugins/data_source_management/public/components/data_source_table/data_source_table.tsx b/src/plugins/data_source_management/public/components/data_source_table/data_source_table.tsx new file mode 100644 index 000000000000..81e918f8eab4 --- /dev/null +++ b/src/plugins/data_source_management/public/components/data_source_table/data_source_table.tsx @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { EuiTitle } from '@elastic/eui'; +import React from 'react'; +import { withRouter } from 'react-router-dom'; + +export const DataSourceTable = () => { + return ( + +

{'This is the landing page, going to list data sources here...'}

+
+ ); +}; + +export const DataSourceTableWithRouter = withRouter(DataSourceTable); diff --git a/src/plugins/data_source_management/public/components/data_source_table/index.ts b/src/plugins/data_source_management/public/components/data_source_table/index.ts new file mode 100644 index 000000000000..0763b5107834 --- /dev/null +++ b/src/plugins/data_source_management/public/components/data_source_table/index.ts @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +export { DataSourceTableWithRouter } from './data_source_table'; diff --git a/src/plugins/data_source_management/public/index.ts b/src/plugins/data_source_management/public/index.ts new file mode 100644 index 000000000000..1d5170c87a7f --- /dev/null +++ b/src/plugins/data_source_management/public/index.ts @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { DataSourceManagementPlugin } from './plugin'; + +// This exports static code and TypeScript types, +// as well as, OpenSearch Dashboards Platform `plugin()` initializer. +export function plugin() { + return new DataSourceManagementPlugin(); +} +export { DataSourceManagementPluginStart } from './types'; diff --git a/src/plugins/data_source_management/public/management_app/index.ts b/src/plugins/data_source_management/public/management_app/index.ts new file mode 100644 index 000000000000..fe9249cb70e3 --- /dev/null +++ b/src/plugins/data_source_management/public/management_app/index.ts @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +export { mountManagementSection } from './mount_management_section'; diff --git a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx new file mode 100644 index 000000000000..1ced84d2fdcb --- /dev/null +++ b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx @@ -0,0 +1,67 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { StartServicesAccessor } from 'src/core/public'; + +import { I18nProvider } from '@osd/i18n/react'; +import React from 'react'; +import ReactDOM from 'react-dom'; +import { Route, Router, Switch } from 'react-router-dom'; +import { ManagementAppMountParams } from '../../../management/public'; + +import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public'; +import { CreateDataSourceWizardWithRouter } from '../components/create_data_source_wizard'; +import { DataSourceTableWithRouter } from '../components/data_source_table'; +import { DataSourceManagmentContext } from '../types'; + +export async function mountManagementSection( + getStartServices: StartServicesAccessor, + params: ManagementAppMountParams +) { + const [ + { chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks }, + ] = await getStartServices(); + + const deps: DataSourceManagmentContext = { + chrome, + application, + savedObjects, + uiSettings, + notifications, + overlays, + http, + docLinks, + setBreadcrumbs: params.setBreadcrumbs, + }; + + ReactDOM.render( + + + + + + + + + + + + + + , + params.element + ); + + return () => { + chrome.docTitle.reset(); + ReactDOM.unmountComponentAtNode(params.element); + }; +} diff --git a/src/plugins/data_source_management/public/plugin.ts b/src/plugins/data_source_management/public/plugin.ts new file mode 100644 index 000000000000..19dd1eb0cafb --- /dev/null +++ b/src/plugins/data_source_management/public/plugin.ts @@ -0,0 +1,45 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { CoreSetup, CoreStart, Plugin } from '../../../core/public'; +import { DataSourceManagementPluginStart, DataSourceManagementSetupDependencies } from './types'; + +import { PLUGIN_NAME } from '../common'; + +const IPM_APP_ID = 'dataSources'; + +export class DataSourceManagementPlugin + implements Plugin { + public setup(core: CoreSetup, { management }: DataSourceManagementSetupDependencies) { + const opensearchDashboardsSection = management.sections.section.opensearchDashboards; + + if (!opensearchDashboardsSection) { + throw new Error('`opensearchDashboards` management section not found.'); + } + + opensearchDashboardsSection.registerApp({ + id: IPM_APP_ID, + title: PLUGIN_NAME, + order: 0, + mount: async (params) => { + const { mountManagementSection } = await import('./management_app'); + + return mountManagementSection(core.getStartServices, params); + }, + }); + } + + public start(core: CoreStart): DataSourceManagementPluginStart { + return {}; + } + + public stop() {} +} diff --git a/src/plugins/data_source_management/public/types.ts b/src/plugins/data_source_management/public/types.ts new file mode 100644 index 000000000000..11c8b303de46 --- /dev/null +++ b/src/plugins/data_source_management/public/types.ts @@ -0,0 +1,41 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { + ChromeStart, + ApplicationStart, + IUiSettingsClient, + OverlayStart, + SavedObjectsStart, + NotificationsStart, + DocLinksStart, + HttpSetup, +} from 'src/core/public'; +import { ManagementAppMountParams, ManagementSetup } from 'src/plugins/management/public'; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataSourceManagementPluginStart {} + +export interface DataSourceManagementSetupDependencies { + management: ManagementSetup; +} + +export interface DataSourceManagmentContext { + chrome: ChromeStart; + application: ApplicationStart; + savedObjects: SavedObjectsStart; + uiSettings: IUiSettingsClient; + notifications: NotificationsStart; + overlays: OverlayStart; + http: HttpSetup; + docLinks: DocLinksStart; + setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs']; +}