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:
parent
f9317281d1
commit
81ba969cfa
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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(`{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue