Skip to content

Commit

Permalink
Fixed Webhook connector doesn't retain added HTTP header settings
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Jul 15, 2020
1 parent ba0a4b1 commit c428675
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('WebhookActionConnectorFields renders', () => {
/>
);
expect(wrapper.find('[data-test-subj="webhookViewHeadersSwitch"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="webhookHeaderText"]').length > 0).toBeTruthy();
wrapper.find('[data-test-subj="webhookViewHeadersSwitch"]').first().simulate('click');
expect(wrapper.find('[data-test-subj="webhookMethodSelect"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="webhookUrlText"]').length > 0).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ const HTTP_VERBS = ['post', 'put'];
const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsProps<
WebhookActionConnector
>> = ({ action, editActionConfig, editActionSecrets, errors }) => {
const { user, password } = action.secrets;
const { method, url, headers } = action.config;

const [httpHeaderKey, setHttpHeaderKey] = useState<string>('');
const [httpHeaderValue, setHttpHeaderValue] = useState<string>('');
const [hasHeaders, setHasHeaders] = useState<boolean>(false);

const { user, password } = action.secrets;
const { method, url, headers } = action.config;

editActionConfig('method', 'post'); // set method to POST by default

const headerErrors = {
Expand Down Expand Up @@ -80,7 +80,7 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField

function viewHeaders() {
setHasHeaders(!hasHeaders);
if (!hasHeaders) {
if (!hasHeaders && !headers) {
editActionConfig('headers', {});
}
}
Expand Down Expand Up @@ -338,8 +338,8 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField

<EuiSpacer size="m" />
<div>
{hasHeaders && Object.keys(headers || {}).length > 0 ? (
<Fragment>
{Object.keys(headers || {}).length > 0 ? (
<>
<EuiSpacer size="m" />
<EuiTitle size="xxs">
<h5>
Expand All @@ -351,10 +351,10 @@ const WebhookActionConnectorFields: React.FunctionComponent<ActionConnectorField
</EuiTitle>
<EuiSpacer size="s" />
{headersList}
</Fragment>
</>
) : null}
<EuiSpacer size="m" />
{headerControl}
{hasHeaders && headerControl}
<EuiSpacer size="m" />
</div>
</Fragment>
Expand Down

0 comments on commit c428675

Please sign in to comment.