From 1f17928a3a6abf27e5fcd323c871fd96de659292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20C=C3=B4t=C3=A9?= Date: Thu, 4 Jun 2020 15:58:48 -0400 Subject: [PATCH] Hide action types in action form that don't have actionParamsFields set (#68171) * Hide action types in alert flyout that don't have actionParamsFields set * Fix jest tests --- .../action_form.test.tsx | 47 +++++++++++++++++-- .../action_connector_form/action_form.tsx | 1 + 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx index 925eabb64ce10..a794bf071d790 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { Fragment } from 'react'; +import React, { Fragment, lazy } from 'react'; import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; import { coreMock } from '../../../../../../../src/core/public/mocks'; import { ReactWrapper } from 'enzyme'; @@ -18,6 +18,13 @@ jest.mock('../../lib/action_connector_api', () => ({ const actionTypeRegistry = actionTypeRegistryMock.create(); describe('action_form', () => { let deps: any; + + const mockedActionParamsFields = lazy(async () => ({ + default() { + return ; + }, + })); + const alertType = { id: 'my-alert-type', iconClass: 'test', @@ -41,7 +48,7 @@ describe('action_form', () => { return validationResult; }, actionConnectorFields: null, - actionParamsFields: null, + actionParamsFields: mockedActionParamsFields, }; const disabledByConfigActionType = { @@ -56,7 +63,7 @@ describe('action_form', () => { return validationResult; }, actionConnectorFields: null, - actionParamsFields: null, + actionParamsFields: mockedActionParamsFields, }; const disabledByLicenseActionType = { @@ -71,7 +78,7 @@ describe('action_form', () => { return validationResult; }, actionConnectorFields: null, - actionParamsFields: null, + actionParamsFields: mockedActionParamsFields, }; const preconfiguredOnly = { @@ -86,6 +93,21 @@ describe('action_form', () => { return validationResult; }, actionConnectorFields: null, + actionParamsFields: mockedActionParamsFields, + }; + + const actionTypeWithoutParams = { + id: 'my-action-type-without-params', + iconClass: 'test', + selectMessage: 'test', + validateConnector: (): ValidationResult => { + return { errors: {} }; + }, + validateParams: (): ValidationResult => { + const validationResult = { errors: {} }; + return validationResult; + }, + actionConnectorFields: null, actionParamsFields: null, }; @@ -153,6 +175,7 @@ describe('action_form', () => { disabledByConfigActionType, disabledByLicenseActionType, preconfiguredOnly, + actionTypeWithoutParams, ]); actionTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.get.mockReturnValue(actionType); @@ -237,6 +260,14 @@ describe('action_form', () => { enabledInLicense: false, minimumLicenseRequired: 'gold', }, + { + id: actionTypeWithoutParams.id, + name: 'Action type without params', + enabled: true, + enabledInConfig: true, + enabledInLicense: true, + minimumLicenseRequired: 'basic', + }, ]} toastNotifications={deps!.toastNotifications} docLinks={deps.docLinks} @@ -340,5 +371,13 @@ describe('action_form', () => { .exists() ).toBeTruthy(); }); + + it(`shouldn't render action types without params component`, async () => { + await setup(); + const actionOption = wrapper.find( + `[data-test-subj="${actionTypeWithoutParams.id}-ActionTypeSelectOption"]` + ); + expect(actionOption.exists()).toBeFalsy(); + }); }); }); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.tsx index 9066bdfa18f43..55805a5939897 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.tsx @@ -536,6 +536,7 @@ export const ActionForm = ({ actionTypeNodes = actionTypeRegistry .list() .filter((item) => actionTypesIndex[item.id]) + .filter((item) => !!item.actionParamsFields) .sort((a, b) => actionTypeCompare(actionTypesIndex[a.id], actionTypesIndex[b.id], preconfiguredConnectors) )