From 9f2d66c8bf0bd52584573fca945c02961789c009 Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Thu, 1 Oct 2020 19:06:07 +0100 Subject: [PATCH 1/8] make savedObjectId field optional --- x-pack/plugins/actions/common/types.ts | 12 ++++++ .../builtin_action_types/jira/schema.ts | 2 +- .../builtin_action_types/servicenow/schema.ts | 2 +- .../extract_action_variable.ts | 15 ++++++++ .../jira/jira_params.test.tsx | 23 ++++++++++- .../builtin_action_types/jira/jira_params.tsx | 30 ++++++++++++++- .../resilient/resilient_params.test.tsx | 23 ++++++++++- .../resilient/resilient_params.tsx | 30 ++++++++++++++- .../servicenow/servicenow_params.test.tsx | 38 ++++++++++++++++++- .../servicenow/servicenow_params.tsx | 31 ++++++++++++++- .../application/lib/action_connector_api.ts | 2 +- .../connector_edit_flyout.tsx | 24 +++++++++--- 12 files changed, 218 insertions(+), 14 deletions(-) create mode 100644 x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/extract_action_variable.ts diff --git a/x-pack/plugins/actions/common/types.ts b/x-pack/plugins/actions/common/types.ts index 41ec4d2a88e9f..d8e91bd3c1470 100644 --- a/x-pack/plugins/actions/common/types.ts +++ b/x-pack/plugins/actions/common/types.ts @@ -34,3 +34,15 @@ export interface ActionTypeExecutorResult { data?: Data; retry?: null | boolean | Date; } + +export function isActionTypeExecutorResult( + result: unknown +): result is ActionTypeExecutorResult { + const unsafeResult = result as ActionTypeExecutorResult; + return ( + unsafeResult && + typeof unsafeResult === 'object' && + unsafeResult?.actionId === 'string' && + (unsafeResult?.status === 'ok' || unsafeResult?.status === 'error') + ); +} diff --git a/x-pack/plugins/actions/server/builtin_action_types/jira/schema.ts b/x-pack/plugins/actions/server/builtin_action_types/jira/schema.ts index 4c31691280c2c..513ca2cf18e6c 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/jira/schema.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/jira/schema.ts @@ -37,7 +37,7 @@ export const ExecutorSubActionSchema = schema.oneOf([ ]); export const ExecutorSubActionPushParamsSchema = schema.object({ - savedObjectId: schema.string(), + savedObjectId: schema.nullable(schema.string()), title: schema.string(), description: schema.nullable(schema.string()), externalId: schema.nullable(schema.string()), diff --git a/x-pack/plugins/actions/server/builtin_action_types/servicenow/schema.ts b/x-pack/plugins/actions/server/builtin_action_types/servicenow/schema.ts index 9896d4175954c..0dd70ea36636e 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/servicenow/schema.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/servicenow/schema.ts @@ -34,7 +34,7 @@ export const ExecutorSubActionSchema = schema.oneOf([ ]); export const ExecutorSubActionPushParamsSchema = schema.object({ - savedObjectId: schema.string(), + savedObjectId: schema.nullable(schema.string()), title: schema.string(), description: schema.nullable(schema.string()), comment: schema.nullable(schema.string()), diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/extract_action_variable.ts b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/extract_action_variable.ts new file mode 100644 index 0000000000000..bb42951b9435d --- /dev/null +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/extract_action_variable.ts @@ -0,0 +1,15 @@ +/* + * 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. + */ + +import { fromNullable, Option } from 'fp-ts/lib/Option'; +import { ActionVariable } from '../../../types'; + +export function extractActionVariable( + actionVariables: ActionVariable[], + variableName: string +): Option { + return fromNullable(actionVariables?.find((variable) => variable.name === variableName)); +} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.test.tsx index 416f6f7b18755..3ce4fcd9d5e8c 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.test.tsx @@ -89,7 +89,7 @@ describe('JiraParamsFields renders', () => { errors={{ title: [] }} editAction={() => {}} index={0} - messageVariables={[]} + messageVariables={[{ name: 'alertId', description: '' }]} docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart} toastNotifications={mocks.notifications.toasts} http={mocks.http} @@ -106,6 +106,27 @@ describe('JiraParamsFields renders', () => { expect(wrapper.find('[data-test-subj="descriptionTextArea"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="labelsComboBox"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="commentsTextArea"]').length > 0).toBeTruthy(); + + // ensure savedObjectIdInput isnt rendered + expect(wrapper.find('[data-test-subj="savedObjectIdInput"]').length === 0).toBeTruthy(); + }); + + test('the savedObjectId fields is rendered if we cant find an alertId in the messageVariables', () => { + const wrapper = mountWithIntl( + {}} + index={0} + messageVariables={[]} + docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart} + toastNotifications={mocks.notifications.toasts} + http={mocks.http} + actionConnector={connector} + /> + ); + + expect(wrapper.find('[data-test-subj="savedObjectIdInput"]').length > 0).toBeTruthy(); }); test('it shows loading when loading issue types', () => { diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx index c19d2c4048665..7080c61a7dfbe 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx @@ -6,6 +6,7 @@ import React, { Fragment, useEffect, useState, useMemo } from 'react'; import { map } from 'lodash/fp'; +import { isSome } from 'fp-ts/lib/Option'; import { EuiFormRow, EuiComboBox, EuiSelectOption, EuiHorizontalRule } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { EuiSelect } from '@elastic/eui'; @@ -20,6 +21,7 @@ import { JiraActionParams } from './types'; import { useGetIssueTypes } from './use_get_issue_types'; import { useGetFieldsByIssueType } from './use_get_fields_by_issue_type'; import { SearchIssues } from './search_issues'; +import { extractActionVariable } from '../extract_action_variable'; const JiraParamsFields: React.FunctionComponent> = ({ actionParams, @@ -38,6 +40,10 @@ const JiraParamsFields: React.FunctionComponent([]); + const isActionBeingConfiguredByAnAlert = messageVariables + ? isSome(extractActionVariable(messageVariables, 'alertId')) + : false; + useEffect(() => { setFirstLoad(true); }, []); @@ -127,7 +133,7 @@ const JiraParamsFields: React.FunctionComponent variable.name === 'alertId')) { + if (!savedObjectId && isActionBeingConfiguredByAnAlert) { editSubActionProperty('savedObjectId', '{{alertId}}'); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -240,6 +246,28 @@ const JiraParamsFields: React.FunctionComponent )} + {!isActionBeingConfiguredByAnAlert && ( + + + + + + + )} { errors={{ title: [] }} editAction={() => {}} index={0} - messageVariables={[]} + messageVariables={[{ name: 'alertId', description: '' }]} docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart} toastNotifications={mocks.notifications.toasts} http={mocks.http} @@ -100,6 +100,27 @@ describe('ResilientParamsFields renders', () => { expect(wrapper.find('[data-test-subj="titleInput"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="descriptionTextArea"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="commentsTextArea"]').length > 0).toBeTruthy(); + + // ensure savedObjectIdInput isnt rendered + expect(wrapper.find('[data-test-subj="savedObjectIdInput"]').length === 0).toBeTruthy(); + }); + + test('the savedObjectId fields is rendered if we cant find an alertId in the messageVariables', () => { + const wrapper = mountWithIntl( + {}} + index={0} + messageVariables={[]} + docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart} + toastNotifications={mocks.notifications.toasts} + http={mocks.http} + actionConnector={connector} + /> + ); + + expect(wrapper.find('[data-test-subj="savedObjectIdInput"]').length > 0).toBeTruthy(); }); test('it shows loading when loading incident types', () => { diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx index b150c97506b69..218ff49ab3063 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx @@ -15,6 +15,7 @@ import { EuiSelectOption, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; +import { isSome } from 'fp-ts/lib/Option'; import { ActionParamsProps } from '../../../../types'; import { ResilientActionParams } from './types'; @@ -23,6 +24,7 @@ import { TextFieldWithMessageVariables } from '../../text_field_with_message_var import { useGetIncidentTypes } from './use_get_incident_types'; import { useGetSeverity } from './use_get_severity'; +import { extractActionVariable } from '../extract_action_variable'; const ResilientParamsFields: React.FunctionComponent> = ({ actionParams, @@ -38,6 +40,10 @@ const ResilientParamsFields: React.FunctionComponent> >([]); @@ -98,7 +104,7 @@ const ResilientParamsFields: React.FunctionComponent variable.name === 'alertId')) { + if (!savedObjectId && isActionBeingConfiguredByAnAlert) { editSubActionProperty('savedObjectId', '{{alertId}}'); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -218,6 +224,28 @@ const ResilientParamsFields: React.FunctionComponent + {!isActionBeingConfiguredByAnAlert && ( + + + + + + + )} { errors={{ title: [] }} editAction={() => {}} index={0} - messageVariables={[]} + messageVariables={[{ name: 'alertId', description: '' }]} docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart} toastNotifications={mocks.notifications.toasts} http={mocks.http} @@ -46,5 +46,41 @@ describe('ServiceNowParamsFields renders', () => { expect(wrapper.find('[data-test-subj="titleInput"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="descriptionTextArea"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="commentTextArea"]').length > 0).toBeTruthy(); + + // ensure savedObjectIdInput isnt rendered + expect(wrapper.find('[data-test-subj="savedObjectIdInput"]').length === 0).toBeTruthy(); + }); + + test('the savedObjectId fields is rendered if we cant find an alertId in the messageVariables', () => { + const mocks = coreMock.createSetup(); + const actionParams = { + subAction: 'pushToService', + subActionParams: { + title: 'sn title', + description: 'some description', + comment: 'comment for sn', + severity: '1', + urgency: '2', + impact: '3', + savedObjectId: '123', + externalId: null, + }, + }; + + const wrapper = mountWithIntl( + {}} + index={0} + messageVariables={[]} + docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart} + toastNotifications={mocks.notifications.toasts} + http={mocks.http} + /> + ); + + // ensure savedObjectIdInput isnt rendered + expect(wrapper.find('[data-test-subj="savedObjectIdInput"]').length > 0).toBeTruthy(); }); }); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx index 2a2efdfbe35b1..bb9425b402056 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx @@ -12,16 +12,23 @@ import { EuiFlexGroup } from '@elastic/eui'; import { EuiFlexItem } from '@elastic/eui'; import { EuiSpacer } from '@elastic/eui'; import { EuiTitle } from '@elastic/eui'; +import { isSome } from 'fp-ts/lib/Option'; import { ActionParamsProps } from '../../../../types'; import { ServiceNowActionParams } from './types'; import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables'; import { TextFieldWithMessageVariables } from '../../text_field_with_message_variables'; +import { extractActionVariable } from '../extract_action_variable'; const ServiceNowParamsFields: React.FunctionComponent> = ({ actionParams, editAction, index, errors, messageVariables }) => { const { title, description, comment, severity, urgency, impact, savedObjectId } = actionParams.subActionParams || {}; + + const isActionBeingConfiguredByAnAlert = messageVariables + ? isSome(extractActionVariable(messageVariables, 'alertId')) + : false; + const selectOptions = [ { value: '1', @@ -61,7 +68,7 @@ const ServiceNowParamsFields: React.FunctionComponent variable.name === 'alertId')) { + if (!savedObjectId && isActionBeingConfiguredByAnAlert) { editSubActionProperty('savedObjectId', '{{alertId}}'); } if (!urgency) { @@ -174,6 +181,28 @@ const ServiceNowParamsFields: React.FunctionComponent + {!isActionBeingConfiguredByAnAlert && ( + + + + + + + )} ; }): Promise> { - return await http.post(`${BASE_ACTION_API_PATH}/action/${id}/_execute`, { + return http.post(`${BASE_ACTION_API_PATH}/action/${id}/_execute`, { body: JSON.stringify({ params }), }); } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/connector_edit_flyout.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/connector_edit_flyout.tsx index 7b985ab85cd4e..9b5bbad025dae 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/connector_edit_flyout.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/connector_edit_flyout.tsx @@ -32,7 +32,10 @@ import { updateActionConnector, executeAction } from '../../lib/action_connector import { hasSaveActionsCapability } from '../../lib/capabilities'; import { useActionsConnectorsContext } from '../../context/actions_connectors_context'; import { PLUGIN } from '../../constants/plugin'; -import { ActionTypeExecutorResult } from '../../../../../actions/common'; +import { + ActionTypeExecutorResult, + isActionTypeExecutorResult, +} from '../../../../../actions/common'; import './connector_edit_flyout.scss'; export interface ConnectorEditProps { @@ -202,13 +205,24 @@ export const ConnectorEditFlyout = ({ const onExecutAction = () => { setIsExecutinAction(true); - return executeAction({ id: connector.id, params: testExecutionActionParams, http }).then( - (result) => { + return executeAction({ id: connector.id, params: testExecutionActionParams, http }) + .then((result) => { setIsExecutinAction(false); setTestExecutionResult(some(result)); return result; - } - ); + }) + .catch((ex: Error | ActionTypeExecutorResult) => { + const result: ActionTypeExecutorResult = isActionTypeExecutorResult(ex) + ? ex + : { + actionId: connector.id, + status: 'error', + message: ex.message, + }; + setIsExecutinAction(false); + setTestExecutionResult(some(result)); + return result; + }); }; const onSaveClicked = async (closeAfterSave: boolean = true) => { From e62c1e6f34801f5a6db6731961b66db28b69d7d8 Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Thu, 1 Oct 2020 19:12:12 +0100 Subject: [PATCH 2/8] corrected i18n ids --- .../builtin_action_types/resilient/resilient_params.tsx | 2 +- .../builtin_action_types/servicenow/servicenow_params.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx index 218ff49ab3063..9d75fef1b81c6 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx @@ -229,7 +229,7 @@ const ResilientParamsFields: React.FunctionComponent Date: Mon, 5 Oct 2020 09:05:29 +0100 Subject: [PATCH 3/8] corrected copy and added tooltips --- .../builtin_action_types/jira/jira_params.tsx | 78 ++++++++++++------- .../resilient/resilient_params.tsx | 33 ++++++-- .../servicenow/servicenow_params.tsx | 47 +++++++---- 3 files changed, 109 insertions(+), 49 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx index 7080c61a7dfbe..c847666686641 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx @@ -7,12 +7,19 @@ import React, { Fragment, useEffect, useState, useMemo } from 'react'; import { map } from 'lodash/fp'; import { isSome } from 'fp-ts/lib/Option'; -import { EuiFormRow, EuiComboBox, EuiSelectOption, EuiHorizontalRule } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { EuiSelect } from '@elastic/eui'; -import { EuiFlexGroup } from '@elastic/eui'; -import { EuiFlexItem } from '@elastic/eui'; -import { EuiSpacer } from '@elastic/eui'; +import { + EuiFormRow, + EuiComboBox, + EuiSelectOption, + EuiHorizontalRule, + EuiSelect, + EuiFormControlLayout, + EuiIconTip, + EuiFlexGroup, + EuiFlexItem, + EuiSpacer, +} from '@elastic/eui'; import { ActionParamsProps } from '../../../../types'; import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables'; @@ -246,28 +253,6 @@ const JiraParamsFields: React.FunctionComponent )} - {!isActionBeingConfiguredByAnAlert && ( - - - - - - - )} + {!isActionBeingConfiguredByAnAlert && ( + + + + + } + > + + + + + + + )} {hasLabels && ( <> diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx index 9d75fef1b81c6..978b77e3595cc 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx @@ -13,6 +13,8 @@ import { EuiTitle, EuiComboBoxOptionOption, EuiSelectOption, + EuiFormControlLayout, + EuiIconTip, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { isSome } from 'fp-ts/lib/Option'; @@ -231,17 +233,32 @@ const ResilientParamsFields: React.FunctionComponent - + + } + > + + diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx index 299152090c93b..f53e03ac75bc3 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx @@ -5,13 +5,17 @@ */ import React, { Fragment, useEffect } from 'react'; -import { EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { EuiSelect } from '@elastic/eui'; -import { EuiFlexGroup } from '@elastic/eui'; -import { EuiFlexItem } from '@elastic/eui'; -import { EuiSpacer } from '@elastic/eui'; -import { EuiTitle } from '@elastic/eui'; +import { + EuiFormRow, + EuiSelect, + EuiFlexGroup, + EuiFlexItem, + EuiSpacer, + EuiTitle, + EuiFormControlLayout, + EuiIconTip, +} from '@elastic/eui'; import { isSome } from 'fp-ts/lib/Option'; import { ActionParamsProps } from '../../../../types'; import { ServiceNowActionParams } from './types'; @@ -188,17 +192,32 @@ const ServiceNowParamsFields: React.FunctionComponent - + + } + > + + From 7097aa96ab788f09835b6468d9829497785d32d3 Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Mon, 5 Oct 2020 14:11:17 +0100 Subject: [PATCH 4/8] fixed type check --- x-pack/plugins/actions/common/types.ts | 2 +- .../actions/server/builtin_action_types/resilient/schema.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/actions/common/types.ts b/x-pack/plugins/actions/common/types.ts index d8e91bd3c1470..1cb754482f39f 100644 --- a/x-pack/plugins/actions/common/types.ts +++ b/x-pack/plugins/actions/common/types.ts @@ -42,7 +42,7 @@ export function isActionTypeExecutorResult( return ( unsafeResult && typeof unsafeResult === 'object' && - unsafeResult?.actionId === 'string' && + typeof unsafeResult?.actionId === 'string' && (unsafeResult?.status === 'ok' || unsafeResult?.status === 'error') ); } diff --git a/x-pack/plugins/actions/server/builtin_action_types/resilient/schema.ts b/x-pack/plugins/actions/server/builtin_action_types/resilient/schema.ts index 151f703dcc07e..b6e3a9525dfd4 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/resilient/schema.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/resilient/schema.ts @@ -37,7 +37,7 @@ export const ExecutorSubActionSchema = schema.oneOf([ ]); export const ExecutorSubActionPushParamsSchema = schema.object({ - savedObjectId: schema.string(), + savedObjectId: schema.nullable(schema.string()), title: schema.string(), description: schema.nullable(schema.string()), externalId: schema.nullable(schema.string()), From 9e07238d718d4cfde82fda55344e959df0a23f9b Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Mon, 5 Oct 2020 14:37:19 +0100 Subject: [PATCH 5/8] corrected tests --- .../actions/builtin_action_types/jira.ts | 20 +------------------ .../actions/builtin_action_types/resilient.ts | 20 +------------------ .../builtin_action_types/servicenow.ts | 20 +------------------ 3 files changed, 3 insertions(+), 57 deletions(-) diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/jira.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/jira.ts index 1a56a9dfcb4db..39f64dd037945 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/jira.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/jira.ts @@ -351,25 +351,7 @@ export default function jiraTest({ getService }: FtrProviderContext) { status: 'error', retry: false, message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.savedObjectId]: expected value of type [string] but got [undefined]\n- [3.subAction]: expected value to equal [issueTypes]\n- [4.subAction]: expected value to equal [fieldsByIssueType]\n- [5.subAction]: expected value to equal [issues]\n- [6.subAction]: expected value to equal [issue]', - }); - }); - }); - - it('should handle failing with a simulated success without savedObjectId', async () => { - await supertest - .post(`/api/actions/action/${simulatedActionId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { subAction: 'pushToService', subActionParams: {} }, - }) - .then((resp: any) => { - expect(resp.body).to.eql({ - actionId: simulatedActionId, - status: 'error', - retry: false, - message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.savedObjectId]: expected value of type [string] but got [undefined]\n- [3.subAction]: expected value to equal [issueTypes]\n- [4.subAction]: expected value to equal [fieldsByIssueType]\n- [5.subAction]: expected value to equal [issues]\n- [6.subAction]: expected value to equal [issue]', + 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.title]: expected value of type [string] but got [undefined]\n- [3.subAction]: expected value to equal [issueTypes]\n- [4.subAction]: expected value to equal [fieldsByIssueType]\n- [5.subAction]: expected value to equal [issues]\n- [6.subAction]: expected value to equal [issue]', }); }); }); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/resilient.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/resilient.ts index d1d19da423e65..5d54ea99889c1 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/resilient.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/resilient.ts @@ -352,25 +352,7 @@ export default function resilientTest({ getService }: FtrProviderContext) { status: 'error', retry: false, message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.savedObjectId]: expected value of type [string] but got [undefined]\n- [3.subAction]: expected value to equal [incidentTypes]\n- [4.subAction]: expected value to equal [severity]', - }); - }); - }); - - it('should handle failing with a simulated success without savedObjectId', async () => { - await supertest - .post(`/api/actions/action/${simulatedActionId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { subAction: 'pushToService', subActionParams: {} }, - }) - .then((resp: any) => { - expect(resp.body).to.eql({ - actionId: simulatedActionId, - status: 'error', - retry: false, - message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.savedObjectId]: expected value of type [string] but got [undefined]\n- [3.subAction]: expected value to equal [incidentTypes]\n- [4.subAction]: expected value to equal [severity]', + 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.title]: expected value of type [string] but got [undefined]\n- [3.subAction]: expected value to equal [incidentTypes]\n- [4.subAction]: expected value to equal [severity]', }); }); }); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts index 3f8341df3d295..60b908e2ae228 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts @@ -343,25 +343,7 @@ export default function servicenowTest({ getService }: FtrProviderContext) { status: 'error', retry: false, message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.savedObjectId]: expected value of type [string] but got [undefined]', - }); - }); - }); - - it('should handle failing with a simulated success without savedObjectId', async () => { - await supertest - .post(`/api/actions/action/${simulatedActionId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { subAction: 'pushToService', subActionParams: {} }, - }) - .then((resp: any) => { - expect(resp.body).to.eql({ - actionId: simulatedActionId, - status: 'error', - retry: false, - message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.savedObjectId]: expected value of type [string] but got [undefined]', + 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.title]: expected value of type [string] but got [undefined]', }); }); }); From 9453c18e217a77a6ff3507fd03d569a53298d76e Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Mon, 5 Oct 2020 14:52:12 +0100 Subject: [PATCH 6/8] refactor isActionTypeExecutorResult --- x-pack/plugins/actions/common/types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/actions/common/types.ts b/x-pack/plugins/actions/common/types.ts index 1cb754482f39f..01d6e237df27c 100644 --- a/x-pack/plugins/actions/common/types.ts +++ b/x-pack/plugins/actions/common/types.ts @@ -26,9 +26,10 @@ export interface ActionResult { } // the result returned from an action type executor function +const ActionTypeExecutorResultStatusValues = ['ok', 'error'] as const; export interface ActionTypeExecutorResult { actionId: string; - status: 'ok' | 'error'; + status: typeof ActionTypeExecutorResultStatusValues[number]; message?: string; serviceMessage?: string; data?: Data; @@ -41,8 +42,7 @@ export function isActionTypeExecutorResult( const unsafeResult = result as ActionTypeExecutorResult; return ( unsafeResult && - typeof unsafeResult === 'object' && typeof unsafeResult?.actionId === 'string' && - (unsafeResult?.status === 'ok' || unsafeResult?.status === 'error') + ActionTypeExecutorResultStatusValues.includes(unsafeResult?.status) ); } From 32964a78563955941daba3084994874bea8ab8cb Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Mon, 5 Oct 2020 14:53:49 +0100 Subject: [PATCH 7/8] refactor isActionTypeExecutorResult again --- x-pack/plugins/actions/common/types.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/actions/common/types.ts b/x-pack/plugins/actions/common/types.ts index 01d6e237df27c..9ff1379894a29 100644 --- a/x-pack/plugins/actions/common/types.ts +++ b/x-pack/plugins/actions/common/types.ts @@ -27,9 +27,11 @@ export interface ActionResult { // the result returned from an action type executor function const ActionTypeExecutorResultStatusValues = ['ok', 'error'] as const; +type ActionTypeExecutorResultStatus = typeof ActionTypeExecutorResultStatusValues[number]; + export interface ActionTypeExecutorResult { actionId: string; - status: typeof ActionTypeExecutorResultStatusValues[number]; + status: ActionTypeExecutorResultStatus; message?: string; serviceMessage?: string; data?: Data; From 5253b255fb1e0885b56459f9742172dd1b72d272 Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Mon, 5 Oct 2020 16:43:50 +0100 Subject: [PATCH 8/8] copy update --- .../components/builtin_action_types/jira/jira_params.tsx | 2 +- .../builtin_action_types/resilient/resilient_params.tsx | 2 +- .../builtin_action_types/servicenow/servicenow_params.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx index c847666686641..880e39aada444 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/jira/jira_params.tsx @@ -294,7 +294,7 @@ const JiraParamsFields: React.FunctionComponent diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx index 978b77e3595cc..996e83b87f059 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/resilient/resilient_params.tsx @@ -245,7 +245,7 @@ const ResilientParamsFields: React.FunctionComponent diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx index f53e03ac75bc3..3e59f2199153b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_params.tsx @@ -204,7 +204,7 @@ const ServiceNowParamsFields: React.FunctionComponent