Skip to content

Commit

Permalink
Skip rendering empty add action variables button as disabled (#96342) (
Browse files Browse the repository at this point in the history
…#96541)

* Skip rendering empty add action variables button

* Fix jest tests

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Mike Côté <[email protected]>
  • Loading branch information
kibanamachine and mikecote authored Apr 8, 2021
1 parent 8589455 commit ed3d8b5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useState } from 'react';
import React, { useState, Fragment } from 'react';
import { i18n } from '@kbn/i18n';
import {
EuiPopover,
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(`{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ed3d8b5

Please sign in to comment.