From 6f7ba8fe4044d60c42982a766a78d4ddd539e6cb Mon Sep 17 00:00:00 2001 From: Mike Cote Date: Mon, 27 Jan 2020 16:05:29 -0500 Subject: [PATCH] Migrate UI capabilities to use new platform APIs --- .../np_ready/public/application/app.tsx | 8 +- .../np_ready/public/application/home.tsx | 7 +- .../action_connector_form.test.tsx | 27 +++-- .../action_connector_form.tsx | 9 +- .../action_type_menu.test.tsx | 27 +++-- .../connector_add_flyout.test.tsx | 27 +++-- .../connector_edit_flyout.test.tsx | 27 +++-- .../actions_connectors_list.test.tsx | 108 ++++++++++-------- .../components/actions_connectors_list.tsx | 10 +- .../components/alerts_list.test.tsx | 108 ++++++++++-------- .../alerts_list/components/alerts_list.tsx | 11 +- .../components/collapsed_item_actions.tsx | 9 +- .../np_ready/public/plugin.ts | 25 ++-- .../np_ready/public/types.ts | 2 - .../triggers_actions_ui/public/legacy.ts | 2 - 15 files changed, 215 insertions(+), 192 deletions(-) diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/app.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/app.tsx index 3ad6b5b7c697d..57e6fc4a9e18b 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/app.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/app.tsx @@ -11,6 +11,7 @@ import { ToastsSetup, HttpSetup, IUiSettingsClient, + ApplicationStart, } from 'kibana/public'; import { BASE_PATH, Section } from './constants'; import { TriggersActionsUIHome } from './home'; @@ -27,6 +28,7 @@ export interface AppDeps { http: HttpSetup; uiSettings: IUiSettingsClient; legacy: LegacyDependencies; + capabilities: ApplicationStart['capabilities']; actionTypeRegistry: TypeRegistry; alertTypeRegistry: TypeRegistry; } @@ -46,10 +48,8 @@ export const App = (appDeps: AppDeps) => { }; export const AppWithoutRouter = ({ sectionsRegex }: any) => { - const { - legacy: { capabilities }, - } = useAppDependencies(); - const canShowAlerts = hasShowAlertsCapability(capabilities.get()); + const { capabilities } = useAppDependencies(); + const canShowAlerts = hasShowAlertsCapability(capabilities); const DEFAULT_SECTION: Section = canShowAlerts ? 'alerts' : 'connectors'; return ( diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/home.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/home.tsx index 3312f1a103b29..5d518bce569e4 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/home.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/home.tsx @@ -39,11 +39,12 @@ export const TriggersActionsUIHome: React.FunctionComponent { const { chrome, - legacy: { MANAGEMENT_BREADCRUMB, capabilities }, + capabilities, + legacy: { MANAGEMENT_BREADCRUMB }, } = useAppDependencies(); - const canShowActions = hasShowActionsCapability(capabilities.get()); - const canShowAlerts = hasShowAlertsCapability(capabilities.get()); + const canShowActions = hasShowActionsCapability(capabilities); + const canShowAlerts = hasShowAlertsCapability(capabilities); const tabs: Array<{ id: Section; name: React.ReactNode; diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_connector_form.test.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_connector_form.test.tsx index c129ce73c7176..6896ac954bb06 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_connector_form.test.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_connector_form.test.tsx @@ -20,7 +20,13 @@ describe('action_connector_form', () => { beforeAll(async () => { const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -28,18 +34,15 @@ describe('action_connector_form', () => { injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + actions: { + delete: true, + save: true, + show: true, + }, + }, legacy: { - capabilities: { - get() { - return { - actions: { - delete: true, - save: true, - show: true, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: actionTypeRegistry as any, diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_connector_form.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_connector_form.tsx index 682c1fbb54b67..852e713b38ed7 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_connector_form.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_connector_form.tsx @@ -39,15 +39,10 @@ export const ActionConnectorForm = ({ actionTypeName, setFlyoutVisibility, }: ActionConnectorProps) => { - const { - http, - toastNotifications, - legacy: { capabilities }, - actionTypeRegistry, - } = useAppDependencies(); + const { http, toastNotifications, capabilities, actionTypeRegistry } = useAppDependencies(); const { reloadConnectors } = useActionsConnectorsContext(); - const canSave = hasSaveActionsCapability(capabilities.get()); + const canSave = hasSaveActionsCapability(capabilities); // hooks const [{ connector }, dispatch] = useReducer(connectorReducer, { connector: initialConnector }); diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_type_menu.test.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_type_menu.test.tsx index a9e2afb061720..6ef2f62315d9a 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_type_menu.test.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/action_type_menu.test.tsx @@ -18,7 +18,13 @@ describe('connector_add_flyout', () => { beforeAll(async () => { const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); deps = { chrome, docLinks, @@ -26,18 +32,15 @@ describe('connector_add_flyout', () => { injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + actions: { + delete: true, + save: true, + show: true, + }, + }, legacy: { - capabilities: { - get() { - return { - actions: { - delete: true, - save: true, - show: true, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: actionTypeRegistry as any, diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_add_flyout.test.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_add_flyout.test.tsx index 5095cc140f9c9..71ba52f047d61 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_add_flyout.test.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_add_flyout.test.tsx @@ -20,7 +20,13 @@ describe('connector_add_flyout', () => { beforeAll(async () => { const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -28,18 +34,15 @@ describe('connector_add_flyout', () => { injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + actions: { + delete: true, + save: true, + show: true, + }, + }, legacy: { - capabilities: { - get() { - return { - actions: { - delete: true, - save: true, - show: true, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: actionTypeRegistry as any, diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_edit_flyout.test.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_edit_flyout.test.tsx index d01539d7232fa..57e950a98eb2a 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_edit_flyout.test.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_edit_flyout.test.tsx @@ -17,7 +17,13 @@ let deps: any; describe('connector_edit_flyout', () => { beforeAll(async () => { const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); deps = { chrome, docLinks, @@ -25,18 +31,15 @@ describe('connector_edit_flyout', () => { injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + actions: { + delete: true, + save: true, + show: true, + }, + }, legacy: { - capabilities: { - get() { - return { - actions: { - delete: true, - save: true, - show: true, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: actionTypeRegistry as any, diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/actions_connectors_list/components/actions_connectors_list.test.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/actions_connectors_list/components/actions_connectors_list.test.tsx index 511deb8cf3b0d..da502fb86521b 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/actions_connectors_list/components/actions_connectors_list.test.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/actions_connectors_list/components/actions_connectors_list.test.tsx @@ -42,7 +42,13 @@ describe('actions_connectors_list component empty', () => { }, ]); const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -50,18 +56,15 @@ describe('actions_connectors_list component empty', () => { injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + siem: { + 'actions:show': true, + 'actions:save': true, + 'actions:delete': true, + }, + }, legacy: { - capabilities: { - get() { - return { - siem: { - 'actions:show': true, - 'actions:save': true, - 'actions:delete': true, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: actionTypeRegistry as any, @@ -136,7 +139,13 @@ describe('actions_connectors_list component with items', () => { ]); const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -144,18 +153,15 @@ describe('actions_connectors_list component with items', () => { injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + siem: { + 'actions:show': true, + 'actions:save': true, + 'actions:delete': true, + }, + }, legacy: { - capabilities: { - get() { - return { - siem: { - 'actions:show': true, - 'actions:save': true, - 'actions:delete': true, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: { @@ -217,7 +223,13 @@ describe('actions_connectors_list component empty with show only capability', () }, ]); const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -225,18 +237,15 @@ describe('actions_connectors_list component empty with show only capability', () injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + siem: { + 'actions:show': true, + 'actions:save': false, + 'actions:delete': false, + }, + }, legacy: { - capabilities: { - get() { - return { - siem: { - 'actions:show': true, - 'actions:save': false, - 'actions:delete': false, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: { @@ -303,7 +312,13 @@ describe('actions_connectors_list with show only capability', () => { }, ]); const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -311,18 +326,15 @@ describe('actions_connectors_list with show only capability', () => { injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + siem: { + 'actions:show': true, + 'actions:save': false, + 'actions:delete': false, + }, + }, legacy: { - capabilities: { - get() { - return { - siem: { - 'actions:show': true, - 'actions:save': false, - 'actions:delete': false, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: { diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx index 1990ffefdf84e..e98c3b2c08749 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx @@ -26,13 +26,9 @@ import { hasDeleteActionsCapability, hasSaveActionsCapability } from '../../../l import { DeleteConnectorsModal } from '../../../components/delete_connectors_modal'; export const ActionsConnectorsList: React.FunctionComponent = () => { - const { - http, - toastNotifications, - legacy: { capabilities }, - } = useAppDependencies(); - const canDelete = hasDeleteActionsCapability(capabilities.get()); - const canSave = hasSaveActionsCapability(capabilities.get()); + const { http, toastNotifications, capabilities } = useAppDependencies(); + const canDelete = hasDeleteActionsCapability(capabilities); + const canSave = hasSaveActionsCapability(capabilities); const [actionTypesIndex, setActionTypesIndex] = useState(undefined); const [actions, setActions] = useState([]); diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.test.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.test.tsx index 9f77bfb3f8760..ff1510ea873d3 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.test.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.test.tsx @@ -70,7 +70,13 @@ describe('alerts_list component empty', () => { }); const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -84,18 +90,15 @@ describe('alerts_list component empty', () => { } as any, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + siem: { + 'alerting:show': true, + 'alerting:save': true, + 'alerting:delete': true, + }, + }, legacy: { - capabilities: { - get() { - return { - siem: { - 'alerting:show': true, - 'alerting:save': true, - 'alerting:delete': true, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: actionTypeRegistry as any, @@ -193,7 +196,13 @@ describe('alerts_list component with items', () => { data: [], }); const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -207,18 +216,15 @@ describe('alerts_list component with items', () => { } as any, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + siem: { + 'alerting:show': true, + 'alerting:save': true, + 'alerting:delete': true, + }, + }, legacy: { - capabilities: { - get() { - return { - siem: { - 'alerting:show': true, - 'alerting:save': true, - 'alerting:delete': true, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: actionTypeRegistry as any, @@ -277,7 +283,13 @@ describe('alerts_list component empty with show only capability', () => { data: [], }); const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -291,18 +303,15 @@ describe('alerts_list component empty with show only capability', () => { } as any, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + siem: { + 'alerting:show': true, + 'alerting:save': false, + 'alerting:delete': false, + }, + }, legacy: { - capabilities: { - get() { - return { - siem: { - 'alerting:show': true, - 'alerting:save': false, - 'alerting:delete': false, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: { @@ -396,7 +405,13 @@ describe('alerts_list with show only capability', () => { data: [], }); const mockes = coreMock.createSetup(); - const [{ chrome, docLinks }] = await mockes.getStartServices(); + const [ + { + chrome, + docLinks, + application: { capabilities }, + }, + ] = await mockes.getStartServices(); const deps = { chrome, docLinks, @@ -410,18 +425,15 @@ describe('alerts_list with show only capability', () => { } as any, http: mockes.http, uiSettings: mockes.uiSettings, + capabilities: { + ...capabilities, + siem: { + 'alerting:show': true, + 'alerting:save': false, + 'alerting:delete': false, + }, + }, legacy: { - capabilities: { - get() { - return { - siem: { - 'alerting:show': true, - 'alerting:save': false, - 'alerting:delete': false, - }, - }; - }, - } as any, MANAGEMENT_BREADCRUMB: { set: () => {} } as any, }, actionTypeRegistry: actionTypeRegistry as any, diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.tsx index 4b5e0d1948bfb..12122983161bd 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.tsx @@ -43,14 +43,9 @@ interface AlertState { } export const AlertsList: React.FunctionComponent = () => { - const { - http, - injectedMetadata, - toastNotifications, - legacy: { capabilities }, - } = useAppDependencies(); - const canDelete = hasDeleteAlertsCapability(capabilities.get()); - const canSave = hasSaveAlertsCapability(capabilities.get()); + const { http, injectedMetadata, toastNotifications, capabilities } = useAppDependencies(); + const canDelete = hasDeleteAlertsCapability(capabilities); + const canSave = hasSaveAlertsCapability(capabilities); const createAlertUiEnabled = injectedMetadata.getInjectedVar('createAlertUiEnabled'); const [actionTypes, setActionTypes] = useState([]); diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/collapsed_item_actions.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/collapsed_item_actions.tsx index dc6fb15f0f236..aa1c6dd7c5b9a 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/collapsed_item_actions.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/collapsed_item_actions.tsx @@ -36,13 +36,10 @@ export const CollapsedItemActions: React.FunctionComponent = ({ item, onAlertChanged, }: ComponentOpts) => { - const { - http, - legacy: { capabilities }, - } = useAppDependencies(); + const { http, capabilities } = useAppDependencies(); - const canDelete = hasDeleteAlertsCapability(capabilities.get()); - const canSave = hasSaveAlertsCapability(capabilities.get()); + const canDelete = hasDeleteAlertsCapability(capabilities); + const canSave = hasSaveAlertsCapability(capabilities); const [isPopoverOpen, setIsPopoverOpen] = useState(false); diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/plugin.ts b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/plugin.ts index 0b0f8a4ee6790..00dd2f51feaee 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/plugin.ts +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/plugin.ts @@ -42,12 +42,6 @@ export class Plugin implements CorePlugin { { application, notifications, http, uiSettings, injectedMetadata }: CoreSetup, { __LEGACY }: LegacyPlugins ): Setup { - const canShowActions = hasShowActionsCapability(__LEGACY.capabilities.get()); - const canShowAlerts = hasShowAlertsCapability(__LEGACY.capabilities.get()); - - if (!canShowActions && !canShowAlerts) { - return; - } registerBuiltInActionTypes({ actionTypeRegistry: this.actionTypeRegistry, }); @@ -61,6 +55,7 @@ export class Plugin implements CorePlugin { mount: async ( { core: { + application: applicationStart, docLinks, chrome, // Waiting for types to be updated. @@ -71,6 +66,16 @@ export class Plugin implements CorePlugin { }, { element } ) => { + const { capabilities } = applicationStart; + + const canShowActions = hasShowActionsCapability(capabilities); + const canShowAlerts = hasShowAlertsCapability(capabilities); + + if (!canShowActions && !canShowAlerts) { + // Render nothing + return () => {}; + } + const { boot } = await import('./application/boot'); return boot({ element, @@ -85,6 +90,7 @@ export class Plugin implements CorePlugin { legacy: { ...__LEGACY, }, + capabilities, actionTypeRegistry: this.actionTypeRegistry, alertTypeRegistry: this.alertTypeRegistry, }); @@ -93,9 +99,10 @@ export class Plugin implements CorePlugin { } public start(core: CoreStart, { __LEGACY }: LegacyPlugins) { - const { capabilities } = __LEGACY; - const canShowActions = hasShowActionsCapability(capabilities.get()); - const canShowAlerts = hasShowAlertsCapability(capabilities.get()); + const { capabilities } = core.application; + + const canShowActions = hasShowActionsCapability(capabilities); + const canShowAlerts = hasShowAlertsCapability(capabilities); // Don't register routes when user doesn't have access to the application if (!canShowActions && !canShowAlerts) { diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/types.ts b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/types.ts index 7a8a0ead5e8c5..ed63ade903104 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/types.ts +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/types.ts @@ -3,7 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { capabilities } from 'ui/capabilities'; import { TypeRegistry } from './application/type_registry'; import { SanitizedAlert as Alert } from '../../../alerting/common'; export { SanitizedAlert as Alert, AlertAction } from '../../../alerting/common'; @@ -94,5 +93,4 @@ export interface IErrorObject { export interface LegacyDependencies { MANAGEMENT_BREADCRUMB: { text: string; href?: string }; - capabilities: typeof capabilities; } diff --git a/x-pack/legacy/plugins/triggers_actions_ui/public/legacy.ts b/x-pack/legacy/plugins/triggers_actions_ui/public/legacy.ts index bae9104081267..95cac99630fb4 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/public/legacy.ts +++ b/x-pack/legacy/plugins/triggers_actions_ui/public/legacy.ts @@ -67,7 +67,6 @@ routes.when(`${BASE_PATH}:section?/:subsection?/:view?/:id?`, { ...(npSetup.plugins as typeof npSetup.plugins), __LEGACY: { MANAGEMENT_BREADCRUMB, - capabilities, }, }); @@ -75,7 +74,6 @@ routes.when(`${BASE_PATH}:section?/:subsection?/:view?/:id?`, { ...(npSetup.plugins as typeof npSetup.plugins), __LEGACY: { MANAGEMENT_BREADCRUMB, - capabilities, }, });