Skip to content

Commit

Permalink
Remove use of copied MANAGEMENT_BREADCRUMBS and use setBreadcrumbs
Browse files Browse the repository at this point in the history
…from management section's mount (elastic#57324)
  • Loading branch information
jloleysens committed Feb 11, 2020
1 parent 6a0f703 commit ac30840
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import React from 'react';
import { of } from 'rxjs';
import { ComponentType } from 'enzyme';
import {
chromeServiceMock,
docLinksServiceMock,
uiSettingsServiceMock,
notificationServiceMock,
Expand All @@ -31,8 +30,7 @@ class MockTimeBuckets {
export const mockContextValue = {
licenseStatus$: of<LicenseStatus>({ valid: true }),
docLinks: docLinksServiceMock.createStartContract(),
chrome: chromeServiceMock.createStartContract(),
MANAGEMENT_BREADCRUMB: { text: 'test' },
setBreadcrumbs: jest.fn(),
createTimeBuckets: () => new MockTimeBuckets(),
uiSettings: uiSettingsServiceMock.createSetupContract(),
toasts: notificationServiceMock.createSetupContract().toasts,
Expand Down
13 changes: 4 additions & 9 deletions x-pack/plugins/watcher/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

import React, { useEffect, useState } from 'react';
import { Observable } from 'rxjs';
import {
ChromeStart,
DocLinksStart,
HttpSetup,
ToastsSetup,
IUiSettingsClient,
} from 'kibana/public';
import { DocLinksStart, HttpSetup, ToastsSetup, IUiSettingsClient } from 'kibana/public';

import {
HashRouter,
Expand All @@ -27,6 +21,8 @@ import { EuiCallOut, EuiLink } from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';

import { RegisterManagementAppArgs } from '../../../../../src/plugins/management/public';

import { LicenseStatus } from '../../common/types/license_status';
import { WatchStatus } from './sections/watch_status/components/watch_status';
import { WatchEdit } from './sections/watch_edit/components/watch_edit';
Expand All @@ -42,15 +38,14 @@ const ShareRouter = withRouter(({ children, history }: RouteComponentProps & { c
});

export interface AppDeps {
chrome: ChromeStart;
docLinks: DocLinksStart;
toasts: ToastsSetup;
http: HttpSetup;
uiSettings: IUiSettingsClient;
theme: ChartsPluginSetup['theme'];
createTimeBuckets: () => any;
licenseStatus$: Observable<LicenseStatus>;
MANAGEMENT_BREADCRUMB: any;
setBreadcrumbs: Parameters<RegisterManagementAppArgs['mount']>[0]['setBreadcrumbs'];
}

export const App = (deps: AppDeps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const WatchEdit = ({
};
}) => {
// hooks
const { MANAGEMENT_BREADCRUMB, chrome } = useAppContext();
const { setBreadcrumbs } = useAppContext();
const [{ watch, loadError }, dispatch] = useReducer(watchReducer, { watch: null });

const setWatchProperty = (property: string, value: any) => {
Expand Down Expand Up @@ -128,12 +128,8 @@ export const WatchEdit = ({
}, [id, type]);

useEffect(() => {
chrome.setBreadcrumbs([
MANAGEMENT_BREADCRUMB,
listBreadcrumb,
id ? editBreadcrumb : createBreadcrumb,
]);
}, [id, chrome, MANAGEMENT_BREADCRUMB]);
setBreadcrumbs([listBreadcrumb, id ? editBreadcrumb : createBreadcrumb]);
}, [id, setBreadcrumbs]);

const errorCode = getPageErrorCode(loadError);
if (errorCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ import { useAppContext } from '../../../app_context';
export const WatchList = () => {
// hooks
const {
chrome,
MANAGEMENT_BREADCRUMB,
setBreadcrumbs,
links: { watcherGettingStartedUrl },
} = useAppContext();
const [selection, setSelection] = useState([]);
Expand All @@ -57,8 +56,8 @@ export const WatchList = () => {
const [deletedWatches, setDeletedWatches] = useState<string[]>([]);

useEffect(() => {
chrome.setBreadcrumbs([MANAGEMENT_BREADCRUMB, listBreadcrumb]);
}, [chrome, MANAGEMENT_BREADCRUMB]);
setBreadcrumbs([listBreadcrumb]);
}, [setBreadcrumbs]);

const { isLoading: isWatchesLoading, data: watches, error } = useLoadWatches(
REFRESH_INTERVALS.WATCH_LIST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const WatchStatus = ({
};
};
}) => {
const { chrome, MANAGEMENT_BREADCRUMB, toasts } = useAppContext();
const { setBreadcrumbs, toasts } = useAppContext();
const {
error: watchDetailError,
data: watchDetail,
Expand All @@ -80,8 +80,8 @@ export const WatchStatus = ({
const [isTogglingActivation, setIsTogglingActivation] = useState<boolean>(false);

useEffect(() => {
chrome.setBreadcrumbs([MANAGEMENT_BREADCRUMB, listBreadcrumb, statusBreadcrumb]);
}, [id, chrome, MANAGEMENT_BREADCRUMB]);
setBreadcrumbs([listBreadcrumb, statusBreadcrumb]);
}, [id, setBreadcrumbs]);

const errorCode = getPageErrorCode(watchDetailError);

Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/watcher/public/legacy/index.d.ts

This file was deleted.

9 changes: 0 additions & 9 deletions x-pack/plugins/watcher/public/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,4 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';

export { TimeBuckets } from './time_buckets';

export const MANAGEMENT_BREADCRUMB = Object.freeze({
text: i18n.translate('xpack.watcher.management.breadcrumb', {
defaultMessage: 'Management',
}),
href: '#/management',
});
9 changes: 4 additions & 5 deletions x-pack/plugins/watcher/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FeatureCatalogueCategory } from '../../../../src/plugins/home/public';
import { LicenseStatus } from '../common/types/license_status';

import { ILicense, LICENSE_CHECK_STATE } from '../../licensing/public';
import { TimeBuckets, MANAGEMENT_BREADCRUMB } from './legacy';
import { TimeBuckets } from './legacy';
import { PLUGIN } from '../common/constants';
import { Dependencies } from './types';

Expand All @@ -37,9 +37,9 @@ export class WatcherUIPlugin implements Plugin<void, void, Dependencies, any> {
'xpack.watcher.sections.watchList.managementSection.watcherDisplayName',
{ defaultMessage: 'Watcher' }
),
mount: async ({ element }) => {
mount: async ({ element, setBreadcrumbs }) => {
const [core] = await getStartServices();
const { chrome, i18n: i18nDep, docLinks, savedObjects } = core;
const { i18n: i18nDep, docLinks, savedObjects } = core;
const { boot } = await import('./application/boot');

return boot({
Expand All @@ -51,12 +51,11 @@ export class WatcherUIPlugin implements Plugin<void, void, Dependencies, any> {
http,
uiSettings,
docLinks,
chrome,
setBreadcrumbs,
theme: charts.theme,
savedObjects: savedObjects.client,
I18nContext: i18nDep.Context,
createTimeBuckets: () => new TimeBuckets(uiSettings, data),
MANAGEMENT_BREADCRUMB,
});
},
});
Expand Down

0 comments on commit ac30840

Please sign in to comment.