Skip to content

Commit

Permalink
[Backport workspace] patch with retire dashboard management and add u…
Browse files Browse the repository at this point in the history
…nit test for mountWrapper (#224)

* feat: add unit test for mountWrapper (#223)

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
(cherry picked from commit 0906bf4)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* feat: add patch

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: some update

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update snapshot

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: tygao <tygao@amazon.com>
Co-authored-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
4 people authored Oct 12, 2023
1 parent b22111a commit e36a7b6
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 117 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';
import { PageWrapper } from './page_wrapper';

describe('PageWrapper', () => {
it('should render normally', async () => {
const { findByText, container } = render(<PageWrapper>Foo</PageWrapper>);
await findByText('Foo');
expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import { EuiPageContent } from '@elastic/eui';
import React from 'react';

export const PageWrapper = (props: { fullWidth?: boolean; children?: React.ReactChild }) => {
export const PageWrapper = (props: { children?: React.ReactChild }) => {
return (
<EuiPageContent
style={props.fullWidth ? {} : { maxWidth: '75%', marginTop: '20px' }}
style={{ maxWidth: '75%', marginTop: '20px' }}
hasShadow={false}
hasBorder={false}
panelPaddingSize="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ import { Router, Switch, Route } from 'react-router-dom';

import { i18n } from '@osd/i18n';
import { I18nProvider } from '@osd/i18n/react';
import {
AppMountParameters,
ChromeBreadcrumb,
ScopedHistory,
StartServicesAccessor,
} from 'src/core/public';
import { AppMountParameters, ChromeBreadcrumb, StartServicesAccessor } from 'src/core/public';

import { AdvancedSettings } from './advanced_settings';
import { ComponentRegistry } from '../types';
Expand All @@ -51,7 +46,7 @@ import './index.scss';
const title = i18n.translate('advancedSettings.advancedSettingsLabel', {
defaultMessage: 'Advanced settings',
});
const crumb = [{ text: title }];
const crumb: ChromeBreadcrumb[] = [{ text: title }];

const readOnlyBadge = {
text: i18n.translate('advancedSettings.badge.readOnly.text', {
Expand All @@ -69,15 +64,12 @@ export async function mountAdvancedSettingsManagementSection(
componentRegistry: ComponentRegistry['start']
) {
const [{ uiSettings, notifications, docLinks, application, chrome }] = await getStartServices();
const setBreadcrumbsScoped = (crumbs: ChromeBreadcrumb[] = []) => {
const wrapBreadcrumb = (item: ChromeBreadcrumb, scopedHistory: ScopedHistory) => ({
chrome.setBreadcrumbs([
...crumb.map((item) => ({
...item,
...(item.href ? reactRouterNavigate(scopedHistory, item.href) : {}),
});

chrome.setBreadcrumbs([...crumbs.map((item) => wrapBreadcrumb(item, params.history))]);
};
setBreadcrumbsScoped(crumb);
...(item.href ? reactRouterNavigate(params.history, item.href) : {}),
})),
]);

const canSave = application.capabilities.advancedSettings.save as boolean;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';
import { PageWrapper } from './page_wrapper';

describe('PageWrapper', () => {
it('should render normally', async () => {
const { findByText, container } = render(<PageWrapper>Foo</PageWrapper>);
await findByText('Foo');
expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import { EuiPageContent } from '@elastic/eui';
import React from 'react';

export const PageWrapper = (props: { fullWidth?: boolean; children?: React.ReactChild }) => {
export const PageWrapper = (props: { children?: React.ReactChild }) => {
return (
<EuiPageContent
style={props.fullWidth ? {} : { maxWidth: '75%', marginTop: '20px' }}
style={{ maxWidth: '75%', marginTop: '20px' }}
hasShadow={false}
hasBorder={false}
panelPaddingSize="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export const NewThemeModal: FC<Props> = ({ addBasePath, onClose }) => {
modes. You or your administrator can change to the previous theme by visiting {advancedSettingsLink}."
values={{
advancedSettingsLink: (
<EuiLink
href={addBasePath('/app/management/opensearch-dashboards/settings#appearance')}
>
<EuiLink href={addBasePath('/app/settings#appearance')}>
<FormattedMessage
id="home.newThemeModal.previewDescription.advancedSettingsLinkText"
defaultMessage="Advanced Settings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"server": true,
"ui": true,
"optionalPlugins": ["dataSource"],
"requiredPlugins": ["management", "data", "urlForwarding"],
"requiredPlugins": ["data", "urlForwarding"],
"requiredBundles": ["opensearchDashboardsReact", "opensearchDashboardsUtils"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ 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 { EuiPage, EuiPageBody } from '@elastic/eui';
import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public';
import { ManagementAppMountParams } from '../../../management/public';
import {
OpenSearchDashboardsContextProvider,
reactRouterNavigate,
} from '../../../opensearch_dashboards_react/public';
import {
IndexPatternTableWithRouter,
EditIndexPatternContainer,
Expand All @@ -60,7 +67,7 @@ const readOnlyBadge = {

export async function mountManagementSection(
getStartServices: StartServicesAccessor<IndexPatternManagementStartDependencies>,
params: ManagementAppMountParams,
params: AppMountParameters,
getMlCardState: () => MlCardState
) {
const [
Expand All @@ -75,6 +82,17 @@ export async function mountManagementSection(
chrome.setBadge(readOnlyBadge);
}

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

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

const deps: IndexPatternManagmentContext = {
chrome,
application,
Expand All @@ -86,40 +104,36 @@ export async function mountManagementSection(
docLinks,
data,
indexPatternManagementStart: indexPatternManagementStart as IndexPatternManagementStart,
setBreadcrumbs: params.setBreadcrumbs,
setBreadcrumbs: setBreadcrumbsScope,
getMlCardState,
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>
);

const content = (
<EuiPage restrictWidth="1200px">
<EuiPageBody component="main">{router}</EuiPageBody>
</EuiPage>
);

ReactDOM.render(
<OpenSearchDashboardsContextProvider services={deps}>
<I18nProvider>{content}</I18nProvider>
</OpenSearchDashboardsContextProvider>,
<EuiPage restrictWidth="1200px">
<EuiPageBody component="main">
<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>
</OpenSearchDashboardsContextProvider>
</EuiPageBody>
</EuiPage>,
params.element
);

Expand Down
11 changes: 2 additions & 9 deletions src/plugins/index_pattern_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ import {
IndexPatternManagementServiceStart,
} from './service';

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

export interface IndexPatternManagementSetupDependencies {
management: ManagementSetup;
urlForwarding: UrlForwardingSetup;
}

Expand Down Expand Up @@ -85,14 +84,8 @@ export class IndexPatternManagementPlugin

public setup(
core: CoreSetup<IndexPatternManagementStartDependencies, IndexPatternManagementStart>,
{ management, urlForwarding }: IndexPatternManagementSetupDependencies
{ urlForwarding }: IndexPatternManagementSetupDependencies
) {
const opensearchDashboardsSection = management.sections.section.opensearchDashboards;

if (!opensearchDashboardsSection) {
throw new Error('`opensearchDashboards` management section not found.');
}

const newAppPath = IPM_APP_ID;
const legacyPatternsPath = 'management/opensearch-dashboards/index_patterns';

Expand Down
Loading

0 comments on commit e36a7b6

Please sign in to comment.