Skip to content

Commit

Permalink
feat: move data source / advanced settings / saved objects management…
Browse files Browse the repository at this point in the history
… out of Dashboard management

Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Sep 28, 2023
1 parent 5bc2ddf commit 7c8b69c
Show file tree
Hide file tree
Showing 34 changed files with 359 additions and 194 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
24 changes: 14 additions & 10 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 @@ -42,18 +43,21 @@ 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({
public setup(core: CoreSetup, { home }: AdvancedSettingsPluginSetup) {
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 All @@ -66,7 +70,7 @@ export class AdvancedSettingsPlugin
'Customize your OpenSearch Dashboards experience — change the date format, turn on dark mode, and more.',
}),
icon: 'gear',
path: '/app/management/opensearch-dashboards/settings',
path: '/app/settings',
showOnHomePage: false,
category: FeatureCatalogueCategory.ADMIN,
});
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data_source/server/saved_objects/data_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const dataSource: SavedObjectsType = {
return obj.attributes.title;
},
getEditUrl(obj) {
return `/management/opensearch-dashboards/dataSources/${encodeURIComponent(obj.id)}`;
return `/dataSources/${encodeURIComponent(obj.id)}`;
},
getInAppUrl(obj) {
return {
path: `/app/management/opensearch-dashboards/dataSources/${encodeURIComponent(obj.id)}`,
path: `/app/dataSources/${encodeURIComponent(obj.id)}`,
uiCapabilitiesPath: 'management.opensearchDashboards.dataSources',
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "opensearchDashboards",
"server": false,
"ui": true,
"requiredPlugins": ["management", "dataSource", "indexPatternManagement"],
"requiredPlugins": ["dataSource", "indexPatternManagement"],
"optionalPlugins": [],
"requiredBundles": ["opensearchDashboardsReact"],
"extraPublicDirs": ["public/components/utils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ export class DataSourceColumn implements IndexPatternTableColumn<DataSourceMap>
?.map((dataSource) => {
return {
...dataSource,
relativeUrl: basePath.prepend(
`/app/management/opensearch-dashboards/dataSources/${encodeURIComponent(
dataSource.id
)}`
),
relativeUrl: basePath.prepend(`/app/dataSources/${encodeURIComponent(dataSource.id)}`),
};
})
?.reduce(
Expand Down
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 @@ -3,4 +3,4 @@
* SPDX-License-Identifier: Apache-2.0
*/

export { mountManagementSection } from './mount_management_section';
export { mountDataSourcesManagementSection } from './mount_management_section';
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,42 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { StartServicesAccessor } from 'src/core/public';
import {
AppMountParameters,
ChromeBreadcrumb,
ScopedHistory,
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 { DataPublicPluginStart } from 'src/plugins/data/public';
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 { DataSourceManagementContext } from '../types';
import { DataSourceManagementContext, DataSourceManagementStartDependencies } from '../types';
import { EditDataSourceWithRouter } from '../components/edit_data_source';
import { PageWrapper } from '../components/page_wrapper';
import { reactRouterNavigate } from '../../../opensearch_dashboards_react/public';

export interface DataSourceManagementStartDependencies {
data: DataPublicPluginStart;
}

export async function mountManagementSection(
export async function mountDataSourcesManagementSection(
getStartServices: StartServicesAccessor<DataSourceManagementStartDependencies>,
params: ManagementAppMountParams
params: AppMountParameters
) {
const [
{ chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks },
] = 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))]);
};

const deps: DataSourceManagementContext = {
chrome,
application,
Expand All @@ -39,27 +48,29 @@ export async function mountManagementSection(
overlays,
http,
docLinks,
setBreadcrumbs: params.setBreadcrumbs,
setBreadcrumbs: setBreadcrumbsScoped,
};

ReactDOM.render(
<OpenSearchDashboardsContextProvider services={deps}>
<I18nProvider>
<Router history={params.history}>
<Switch>
<Route path={['/create']}>
<CreateDataSourceWizardWithRouter />
</Route>
<Route path={['/:id']}>
<EditDataSourceWithRouter />
</Route>
<Route path={['/']}>
<DataSourceTableWithRouter />
</Route>
</Switch>
</Router>
</I18nProvider>
</OpenSearchDashboardsContextProvider>,
<PageWrapper>
<OpenSearchDashboardsContextProvider services={deps}>
<I18nProvider>
<Router history={params.history}>
<Switch>
<Route path={['/create']}>
<CreateDataSourceWizardWithRouter />
</Route>
<Route path={['/:id']}>
<EditDataSourceWithRouter />
</Route>
<Route path={['/']}>
<DataSourceTableWithRouter />
</Route>
</Switch>
</Router>
</I18nProvider>
</OpenSearchDashboardsContextProvider>
</PageWrapper>,
params.element
);

Expand Down
Loading

0 comments on commit 7c8b69c

Please sign in to comment.