Skip to content

Commit b021eaf

Browse files
committed
Fixed Webhook connector doesn't retain added HTTP header settings (#71924)
* Fixed Webhook connector doesn't retain added HTTP header settings * fixed method
1 parent 7401c61 commit b021eaf

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/webhook/webhook_connectors.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('WebhookActionConnectorFields renders', () => {
3636
/>
3737
);
3838
expect(wrapper.find('[data-test-subj="webhookViewHeadersSwitch"]').length > 0).toBeTruthy();
39+
expect(wrapper.find('[data-test-subj="webhookHeaderText"]').length > 0).toBeTruthy();
3940
wrapper.find('[data-test-subj="webhookViewHeadersSwitch"]').first().simulate('click');
4041
expect(wrapper.find('[data-test-subj="webhookMethodSelect"]').length > 0).toBeTruthy();
4142
expect(wrapper.find('[data-test-subj="webhookUrlText"]').length > 0).toBeTruthy();

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/webhook/webhook_connectors.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ const HTTP_VERBS = ['post', 'put'];
3131
const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsProps<
3232
WebhookActionConnector
3333
>> = ({ action, editActionConfig, editActionSecrets, errors }) => {
34+
const { user, password } = action.secrets;
35+
const { method, url, headers } = action.config;
36+
3437
const [httpHeaderKey, setHttpHeaderKey] = useState<string>('');
3538
const [httpHeaderValue, setHttpHeaderValue] = useState<string>('');
3639
const [hasHeaders, setHasHeaders] = useState<boolean>(false);
3740

38-
const { user, password } = action.secrets;
39-
const { method, url, headers } = action.config;
40-
41-
editActionConfig('method', 'post'); // set method to POST by default
41+
if (!method) {
42+
editActionConfig('method', 'post'); // set method to POST by default
43+
}
4244

4345
const headerErrors = {
4446
keyHeader: new Array<string>(),
@@ -80,7 +82,7 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField
8082

8183
function viewHeaders() {
8284
setHasHeaders(!hasHeaders);
83-
if (!hasHeaders) {
85+
if (!hasHeaders && !headers) {
8486
editActionConfig('headers', {});
8587
}
8688
}
@@ -338,8 +340,8 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField
338340

339341
<EuiSpacer size="m" />
340342
<div>
341-
{hasHeaders && Object.keys(headers || {}).length > 0 ? (
342-
<Fragment>
343+
{Object.keys(headers || {}).length > 0 ? (
344+
<>
343345
<EuiSpacer size="m" />
344346
<EuiTitle size="xxs">
345347
<h5>
@@ -351,10 +353,10 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField
351353
</EuiTitle>
352354
<EuiSpacer size="s" />
353355
{headersList}
354-
</Fragment>
356+
</>
355357
) : null}
356358
<EuiSpacer size="m" />
357-
{headerControl}
359+
{hasHeaders && headerControl}
358360
<EuiSpacer size="m" />
359361
</div>
360362
</Fragment>

0 commit comments

Comments
 (0)