diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.tsx index eacdf20747fdc..1030ce34d2569 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.tsx @@ -11,7 +11,6 @@ import { ActionParamsProps } from '../../../../types'; import { EmailActionParams } from '../types'; import { TextFieldWithMessageVariables } from '../../text_field_with_message_variables'; import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables'; -import { resolvedActionGroupMessage } from '../../../constants'; export const EmailParamsFields = ({ actionParams, @@ -28,17 +27,19 @@ export const EmailParamsFields = ({ const [addCC, setAddCC] = useState(false); const [addBCC, setAddBCC] = useState(false); + const [[isUsingDefault, defaultMessageUsed], setDefaultMessageUsage] = useState< + [boolean, string | undefined] + >([false, defaultMessage]); useEffect(() => { - if (defaultMessage === resolvedActionGroupMessage) { - editAction('message', defaultMessage, index); - } else if ( - (!message || message === resolvedActionGroupMessage) && - defaultMessage && - defaultMessage.length > 0 + if ( + !actionParams?.message || + (isUsingDefault && + actionParams?.message === defaultMessageUsed && + defaultMessageUsed !== defaultMessage) ) { + setDefaultMessageUsage([true, defaultMessage]); editAction('message', defaultMessage, index); } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [defaultMessage]); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx index e8c427371c4a5..ea734439ef41a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx @@ -3,17 +3,16 @@ * 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, useEffect } from 'react'; +import React, { Fragment, useEffect, useState } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiSelect, EuiFormRow } from '@elastic/eui'; import { ActionParamsProps } from '../../../../types'; import { ServerLogActionParams } from '.././types'; import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables'; -import { resolvedActionGroupMessage } from '../../../constants'; -export const ServerLogParamsFields: React.FunctionComponent< - ActionParamsProps -> = ({ actionParams, editAction, index, errors, messageVariables, defaultMessage }) => { +export const ServerLogParamsFields: React.FunctionComponent> = ({ actionParams, editAction, index, errors, messageVariables, defaultMessage }) => { const { message, level } = actionParams; const levelOptions = [ { value: 'trace', text: 'Trace' }, @@ -23,7 +22,6 @@ export const ServerLogParamsFields: React.FunctionComponent< { value: 'error', text: 'Error' }, { value: 'fatal', text: 'Fatal' }, ]; - useEffect(() => { if (!actionParams?.level) { editAction('level', 'info', index); @@ -31,17 +29,19 @@ export const ServerLogParamsFields: React.FunctionComponent< // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + const [[isUsingDefault, defaultMessageUsed], setDefaultMessageUsage] = useState< + [boolean, string | undefined] + >([false, defaultMessage]); useEffect(() => { - if (defaultMessage === resolvedActionGroupMessage) { - editAction('message', defaultMessage, index); - } else if ( - (!message || message === resolvedActionGroupMessage) && - defaultMessage && - defaultMessage.length > 0 + if ( + !actionParams?.message || + (isUsingDefault && + actionParams?.message === defaultMessageUsed && + defaultMessageUsed !== defaultMessage) ) { + setDefaultMessageUsage([true, defaultMessage]); editAction('message', defaultMessage, index); } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [defaultMessage]); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack/slack_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack/slack_params.tsx index d1498567218d3..40818c327af60 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack/slack_params.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack/slack_params.tsx @@ -3,12 +3,11 @@ * 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, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import { i18n } from '@kbn/i18n'; import { ActionParamsProps } from '../../../../types'; import { SlackActionParams } from '../types'; import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables'; -import { resolvedActionGroupMessage } from '../../../constants'; const SlackParamsFields: React.FunctionComponent> = ({ actionParams, @@ -19,17 +18,19 @@ const SlackParamsFields: React.FunctionComponent { const { message } = actionParams; + const [[isUsingDefault, defaultMessageUsed], setDefaultMessageUsage] = useState< + [boolean, string | undefined] + >([false, defaultMessage]); useEffect(() => { - if (defaultMessage === resolvedActionGroupMessage) { - editAction('message', defaultMessage, index); - } else if ( - (!message || message === resolvedActionGroupMessage) && - defaultMessage && - defaultMessage.length > 0 + if ( + !actionParams?.message || + (isUsingDefault && + actionParams?.message === defaultMessageUsed && + defaultMessageUsed !== defaultMessage) ) { + setDefaultMessageUsage([true, defaultMessage]); editAction('message', defaultMessage, index); } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [defaultMessage]);