Skip to content

Commit

Permalink
Merge branch '8.2' of https://github.com/elastic/kibana into backport…
Browse files Browse the repository at this point in the history
…/8.2/pr-128925
  • Loading branch information
XavierM committed Apr 3, 2022
2 parents 0d18685 + 8374636 commit 4894663
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('RuleStatusDropdown', () => {
enableRule,
snoozeRule,
unsnoozeRule,
isEditable: true,
item: {
id: '1',
name: 'test rule',
Expand Down Expand Up @@ -114,4 +115,19 @@ describe('RuleStatusDropdown', () => {
'Disabled'
);
});

test('renders read-only status control when isEditable is false', () => {
const wrapper = mountWithIntl(
<RuleStatusDropdown
{...{
...props,
item: { ...props.item, snoozeEndTime: SNOOZE_END_TIME },
}}
isEditable={false}
/>
);
expect(wrapper.find('[data-test-subj="statusDropdownReadonly"]').first().props().children).toBe(
'Enabled'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ export const RuleStatusDropdown: React.FunctionComponent<ComponentOpts> = ({
</EuiToolTip>
) : null;

const badge = (
const nonEditableBadge = (
<EuiBadge color={badgeColor} data-test-subj="statusDropdownReadonly">
{badgeMessage}
</EuiBadge>
);

const editableBadge = (
<EuiBadge
color={badgeColor}
iconSide="right"
iconType={!isUpdating ? 'arrowDown' : undefined}
iconType={!isUpdating && isEditable ? 'arrowDown' : undefined}
onClick={onClickBadge}
iconOnClick={onClickBadge}
onClickAriaLabel={OPEN_MENU_ARIA_LABEL}
Expand All @@ -142,23 +148,27 @@ export const RuleStatusDropdown: React.FunctionComponent<ComponentOpts> = ({
responsive={false}
>
<EuiFlexItem grow={false}>
<EuiPopover
button={badge}
isOpen={isPopoverOpen}
closePopover={onClosePopover}
panelPaddingSize="s"
data-test-subj="statusDropdown"
title={badgeMessage}
>
<RuleStatusMenu
onClosePopover={onClosePopover}
onChangeEnabledStatus={onChangeEnabledStatus}
onChangeSnooze={onChangeSnooze}
isEnabled={isEnabled}
isSnoozed={isSnoozed}
snoozeEndTime={item.snoozeEndTime}
/>
</EuiPopover>
{isEditable ? (
<EuiPopover
button={editableBadge}
isOpen={isPopoverOpen && isEditable}
closePopover={onClosePopover}
panelPaddingSize="s"
data-test-subj="statusDropdown"
title={badgeMessage}
>
<RuleStatusMenu
onClosePopover={onClosePopover}
onChangeEnabledStatus={onChangeEnabledStatus}
onChangeSnooze={onChangeSnooze}
isEnabled={isEnabled}
isSnoozed={isSnoozed}
snoozeEndTime={item.snoozeEndTime}
/>
</EuiPopover>
) : (
nonEditableBadge
)}
</EuiFlexItem>
<EuiFlexItem data-test-subj="remainingSnoozeTime" grow={false}>
{remainingSnoozeTime}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export const RulesList: React.FunctionComponent = () => {
unsnoozeRule={async () => await unsnoozeRule({ http, id: item.id })}
item={item}
onRuleChanged={() => loadRulesData()}
isEditable={item.isEditable && isRuleTypeEditableInContext(item.ruleTypeId)}
/>
);
};
Expand Down

0 comments on commit 4894663

Please sign in to comment.