From ac30840b2ad36a03575081ff6975e9a7afa049fe Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Tue, 11 Feb 2020 18:33:21 +0100 Subject: [PATCH] Remove use of copied MANAGEMENT_BREADCRUMBS and use `setBreadcrumbs` from management section's mount (#57324) --- .../client_integration/helpers/app_context.mock.tsx | 4 +--- x-pack/plugins/watcher/public/application/app.tsx | 13 ++++--------- .../sections/watch_edit/components/watch_edit.tsx | 10 +++------- .../sections/watch_list/components/watch_list.tsx | 7 +++---- .../watch_status/components/watch_status.tsx | 6 +++--- x-pack/plugins/watcher/public/legacy/index.d.ts | 7 ------- x-pack/plugins/watcher/public/legacy/index.ts | 9 --------- x-pack/plugins/watcher/public/plugin.ts | 9 ++++----- 8 files changed, 18 insertions(+), 47 deletions(-) delete mode 100644 x-pack/plugins/watcher/public/legacy/index.d.ts diff --git a/x-pack/plugins/watcher/__jest__/client_integration/helpers/app_context.mock.tsx b/x-pack/plugins/watcher/__jest__/client_integration/helpers/app_context.mock.tsx index ecb284352b98c..27aa3ba93684e 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/helpers/app_context.mock.tsx +++ b/x-pack/plugins/watcher/__jest__/client_integration/helpers/app_context.mock.tsx @@ -8,7 +8,6 @@ import React from 'react'; import { of } from 'rxjs'; import { ComponentType } from 'enzyme'; import { - chromeServiceMock, docLinksServiceMock, uiSettingsServiceMock, notificationServiceMock, @@ -31,8 +30,7 @@ class MockTimeBuckets { export const mockContextValue = { licenseStatus$: of({ 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, diff --git a/x-pack/plugins/watcher/public/application/app.tsx b/x-pack/plugins/watcher/public/application/app.tsx index 7ca79bb558baa..f4b9441719386 100644 --- a/x-pack/plugins/watcher/public/application/app.tsx +++ b/x-pack/plugins/watcher/public/application/app.tsx @@ -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, @@ -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'; @@ -42,7 +38,6 @@ const ShareRouter = withRouter(({ children, history }: RouteComponentProps & { c }); export interface AppDeps { - chrome: ChromeStart; docLinks: DocLinksStart; toasts: ToastsSetup; http: HttpSetup; @@ -50,7 +45,7 @@ export interface AppDeps { theme: ChartsPluginSetup['theme']; createTimeBuckets: () => any; licenseStatus$: Observable; - MANAGEMENT_BREADCRUMB: any; + setBreadcrumbs: Parameters[0]['setBreadcrumbs']; } export const App = (deps: AppDeps) => { diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/watch_edit.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit/components/watch_edit.tsx index 59a6079d74b42..f125dde63f78d 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/watch_edit.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_edit/components/watch_edit.tsx @@ -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) => { @@ -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) { diff --git a/x-pack/plugins/watcher/public/application/sections/watch_list/components/watch_list.tsx b/x-pack/plugins/watcher/public/application/sections/watch_list/components/watch_list.tsx index 9f6a8ddbc843e..2d552d7fbdda6 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_list/components/watch_list.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_list/components/watch_list.tsx @@ -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([]); @@ -57,8 +56,8 @@ export const WatchList = () => { const [deletedWatches, setDeletedWatches] = useState([]); useEffect(() => { - chrome.setBreadcrumbs([MANAGEMENT_BREADCRUMB, listBreadcrumb]); - }, [chrome, MANAGEMENT_BREADCRUMB]); + setBreadcrumbs([listBreadcrumb]); + }, [setBreadcrumbs]); const { isLoading: isWatchesLoading, data: watches, error } = useLoadWatches( REFRESH_INTERVALS.WATCH_LIST diff --git a/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_status.tsx b/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_status.tsx index b15c047d06f67..5198b0e45c6dc 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_status.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_status.tsx @@ -67,7 +67,7 @@ export const WatchStatus = ({ }; }; }) => { - const { chrome, MANAGEMENT_BREADCRUMB, toasts } = useAppContext(); + const { setBreadcrumbs, toasts } = useAppContext(); const { error: watchDetailError, data: watchDetail, @@ -80,8 +80,8 @@ export const WatchStatus = ({ const [isTogglingActivation, setIsTogglingActivation] = useState(false); useEffect(() => { - chrome.setBreadcrumbs([MANAGEMENT_BREADCRUMB, listBreadcrumb, statusBreadcrumb]); - }, [id, chrome, MANAGEMENT_BREADCRUMB]); + setBreadcrumbs([listBreadcrumb, statusBreadcrumb]); + }, [id, setBreadcrumbs]); const errorCode = getPageErrorCode(watchDetailError); diff --git a/x-pack/plugins/watcher/public/legacy/index.d.ts b/x-pack/plugins/watcher/public/legacy/index.d.ts deleted file mode 100644 index 307e365040fb7..0000000000000 --- a/x-pack/plugins/watcher/public/legacy/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export declare const MANAGEMENT_BREADCRUMB: { text: string; href?: string }; diff --git a/x-pack/plugins/watcher/public/legacy/index.ts b/x-pack/plugins/watcher/public/legacy/index.ts index d14081a667acc..cdb656fc0cda8 100644 --- a/x-pack/plugins/watcher/public/legacy/index.ts +++ b/x-pack/plugins/watcher/public/legacy/index.ts @@ -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', -}); diff --git a/x-pack/plugins/watcher/public/plugin.ts b/x-pack/plugins/watcher/public/plugin.ts index 354edd2078676..cb9ad4eb21fcf 100644 --- a/x-pack/plugins/watcher/public/plugin.ts +++ b/x-pack/plugins/watcher/public/plugin.ts @@ -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'; @@ -37,9 +37,9 @@ export class WatcherUIPlugin implements Plugin { '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({ @@ -51,12 +51,11 @@ export class WatcherUIPlugin implements Plugin { http, uiSettings, docLinks, - chrome, + setBreadcrumbs, theme: charts.theme, savedObjects: savedObjects.client, I18nContext: i18nDep.Context, createTimeBuckets: () => new TimeBuckets(uiSettings, data), - MANAGEMENT_BREADCRUMB, }); }, });