Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Fixed Webhook connector doesn't retain added HTTP header settings (#71924) #72162

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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