Skip rendering empty add action variables button as disabled (#96342)

* Skip rendering empty add action variables button

* Fix jest tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Mike Côté 2021-04-08 05:24:16 -04:00 committed by GitHub
parent f9317281d1
commit 81ba969cfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 2 deletions

View file

@ -117,4 +117,16 @@ describe('AddMessageVariables', () => {
wrapper.find('button[data-test-subj="variableMenuButton-deprecatedVar"]').getDOMNode()
).toBeDisabled();
});
test(`it does't render when no variables exist`, () => {
const wrapper = mountWithIntl(
<AddMessageVariables
messageVariables={[]}
paramsProperty="foo"
onSelectEventHandler={jest.fn()}
/>
);
expect(wrapper.find('[data-test-subj="fooAddVariableButton"]')).toHaveLength(0);
});
});

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import React, { useState } from 'react';
import React, { useState, Fragment } from 'react';
import { i18n } from '@kbn/i18n';
import {
EuiPopover,
@ -61,13 +61,16 @@ export const AddMessageVariables: React.FunctionComponent<Props> = ({
}
);
if ((messageVariables?.length ?? 0) === 0) {
return <Fragment />;
}
return (
<EuiPopover
button={
<EuiButtonIcon
id={`${paramsProperty}AddVariableButton`}
data-test-subj={`${paramsProperty}AddVariableButton`}
isDisabled={(messageVariables?.length ?? 0) === 0}
title={addVariableButtonTitle}
onClick={() => setIsVariablesPopoverOpen(true)}
iconType="indexOpen"

View file

@ -22,6 +22,13 @@ describe('IndexParamsFields renders', () => {
errors={{ index: [] }}
editAction={() => {}}
index={0}
messageVariables={[
{
name: 'myVar',
description: 'My variable description',
useWithTripleBracesInTemplates: true,
},
]}
/>
);
expect(wrapper.find('[data-test-subj="documentsJsonEditor"]').first().prop('value')).toBe(`{

View file

@ -30,6 +30,13 @@ describe('PagerDutyParamsFields renders', () => {
errors={{ summary: [], timestamp: [], dedupKey: [] }}
editAction={() => {}}
index={0}
messageVariables={[
{
name: 'myVar',
description: 'My variable description',
useWithTripleBracesInTemplates: true,
},
]}
/>
);
expect(wrapper.find('[data-test-subj="severitySelect"]').length > 0).toBeTruthy();

View file

@ -21,6 +21,13 @@ describe('WebhookParamsFields renders', () => {
errors={{ body: [] }}
editAction={() => {}}
index={0}
messageVariables={[
{
name: 'myVar',
description: 'My variable description',
useWithTripleBracesInTemplates: true,
},
]}
/>
);
expect(wrapper.find('[data-test-subj="bodyJsonEditor"]').length > 0).toBeTruthy();