Skip to content

Commit c428675

Browse files
committed
Fixed Webhook connector doesn't retain added HTTP header settings
1 parent ba0a4b1 commit c428675

2 files changed

Lines changed: 9 additions & 8 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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ 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-
4141
editActionConfig('method', 'post'); // set method to POST by default
4242

4343
const headerErrors = {
@@ -80,7 +80,7 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField
8080

8181
function viewHeaders() {
8282
setHasHeaders(!hasHeaders);
83-
if (!hasHeaders) {
83+
if (!hasHeaders && !headers) {
8484
editActionConfig('headers', {});
8585
}
8686
}
@@ -338,8 +338,8 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField
338338

339339
<EuiSpacer size="m" />
340340
<div>
341-
{hasHeaders && Object.keys(headers || {}).length > 0 ? (
342-
<Fragment>
341+
{Object.keys(headers || {}).length > 0 ? (
342+
<>
343343
<EuiSpacer size="m" />
344344
<EuiTitle size="xxs">
345345
<h5>
@@ -351,10 +351,10 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField
351351
</EuiTitle>
352352
<EuiSpacer size="s" />
353353
{headersList}
354-
</Fragment>
354+
</>
355355
) : null}
356356
<EuiSpacer size="m" />
357-
{headerControl}
357+
{hasHeaders && headerControl}
358358
<EuiSpacer size="m" />
359359
</div>
360360
</Fragment>

0 commit comments

Comments
 (0)