-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [Alerting] fixes buggy default message behaviour (#84202) This PR addresses some weird UX we've identified with default values in Action Params components and their inferred defaults when placed inside of an Alerts flyout. Key changes: 1. Typing of these components has been corrected to reflect that we expect these parameters to only be _partial_, as the form is used to set these values (for example, the `message` field of the Server Log action, might or might not be set, so it should be nullable, but in the typing we treated it as the _final_ valid state, which is message not being nullable). 2. When a default message is set by the params components, the are tracked against the value of the default, which means that if the default changes, then so will the value in the field. Custom values provided by the user will not be overridden when the default changes. This has to be handled by the component itself at the moment (hopefully in the future we can make this a concern of the flyout and not each component). 3. The concept of the "Recovered" action group has been removed from these components - that's an Alerting concern, not actions, and shouldn't appear in the action components' code. # Conflicts: # x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.test.tsx * Update server_log_params.test.tsx Removed unused var (caused by bad merge) Co-authored-by: Yuliia Naumenko <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
0b7ec8b
commit a260c44
Showing
9 changed files
with
218 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,97 @@ describe('EmailParamsFields renders', () => { | |
expect(wrapper.find('[data-test-subj="subjectInput"]').length > 0).toBeTruthy(); | ||
expect(wrapper.find('[data-test-subj="messageTextArea"]').length > 0).toBeTruthy(); | ||
}); | ||
|
||
test('message param field is rendered with default value if not set', () => { | ||
const actionParams = { | ||
cc: [], | ||
bcc: [], | ||
to: ['[email protected]'], | ||
subject: 'test', | ||
}; | ||
|
||
const editAction = jest.fn(); | ||
mountWithIntl( | ||
<EmailParamsFields | ||
actionParams={actionParams} | ||
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }} | ||
editAction={editAction} | ||
defaultMessage={'Some default message'} | ||
index={0} | ||
/> | ||
); | ||
|
||
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0); | ||
}); | ||
|
||
test('when the default message changes, so is the underlying message if it was set by the previous default', () => { | ||
const actionParams = { | ||
cc: [], | ||
bcc: [], | ||
to: ['[email protected]'], | ||
subject: 'test', | ||
}; | ||
|
||
const editAction = jest.fn(); | ||
const wrapper = mountWithIntl( | ||
<EmailParamsFields | ||
actionParams={actionParams} | ||
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }} | ||
editAction={editAction} | ||
defaultMessage={'Some default message'} | ||
index={0} | ||
/> | ||
); | ||
|
||
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0); | ||
|
||
wrapper.setProps({ | ||
defaultMessage: 'Some different default message', | ||
}); | ||
|
||
expect(editAction).toHaveBeenCalledWith('message', 'Some different default message', 0); | ||
}); | ||
|
||
test('when the default message changes, it doesnt change the underlying message if it wasnt set by a previous default', () => { | ||
const actionParams = { | ||
cc: [], | ||
bcc: [], | ||
to: ['[email protected]'], | ||
subject: 'test', | ||
}; | ||
|
||
const editAction = jest.fn(); | ||
const wrapper = mountWithIntl( | ||
<EmailParamsFields | ||
actionParams={actionParams} | ||
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }} | ||
editAction={editAction} | ||
defaultMessage={'Some default message'} | ||
index={0} | ||
/> | ||
); | ||
|
||
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0); | ||
|
||
// simulate value being updated | ||
const valueToSimulate = 'some new value'; | ||
wrapper | ||
.find('[data-test-subj="messageTextArea"]') | ||
.first() | ||
.simulate('change', { target: { value: valueToSimulate } }); | ||
expect(editAction).toHaveBeenCalledWith('message', valueToSimulate, 0); | ||
wrapper.setProps({ | ||
actionParams: { | ||
...actionParams, | ||
message: valueToSimulate, | ||
}, | ||
}); | ||
|
||
// simulate default changing | ||
wrapper.setProps({ | ||
defaultMessage: 'Some different default message', | ||
}); | ||
|
||
expect(editAction).not.toHaveBeenCalledWith('message', 'Some different default message', 0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters