Skip to content

Commit

Permalink
Fixed Webhook connector doesn't retain added HTTP header settings (#7…
Browse files Browse the repository at this point in the history
…1924)

* Fixed Webhook connector doesn't retain added HTTP header settings

* fixed method
  • Loading branch information
YulNaumenko authored Jul 16, 2020
1 parent ba76476 commit 9da8b76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 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,14 +31,16 @@ 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
if (!method) {
editActionConfig('method', 'post'); // set method to POST by default
}

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

function viewHeaders() {
setHasHeaders(!hasHeaders);
if (!hasHeaders) {
if (!hasHeaders && !headers) {
editActionConfig('headers', {});
}
}
Expand Down Expand Up @@ -338,8 +340,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 +353,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 9da8b76

Please sign in to comment.