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

[RAM] Disable rule status dropdown on readonly user #128971

Merged
merged 4 commits into from
Mar 31, 2022
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 @@ -22,6 +22,7 @@ describe('RuleStatusDropdown', () => {
enableRule,
snoozeRule,
unsnoozeRule,
isEditable: true,
previousSnoozeInterval: null,
item: {
id: '1',
Expand Down Expand Up @@ -115,4 +116,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 @@ -43,6 +43,7 @@ export interface ComponentOpts {
disableRule: () => Promise<void>;
snoozeRule: (snoozeEndTime: string | -1, interval: string | null) => Promise<void>;
unsnoozeRule: () => Promise<void>;
isEditable: boolean;
previousSnoozeInterval: string | null;
}

Expand All @@ -60,6 +61,7 @@ export const RuleStatusDropdown: React.FunctionComponent<ComponentOpts> = ({
enableRule,
snoozeRule,
unsnoozeRule,
isEditable,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this default to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer making it a required prop. We shouldn't be using this component in any context where we can't determine if the rule is editable or not.

previousSnoozeInterval,
}: ComponentOpts) => {
const [isEnabled, setIsEnabled] = useState<boolean>(item.enabled);
Expand Down Expand Up @@ -124,11 +126,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 @@ -150,24 +158,28 @@ export const RuleStatusDropdown: React.FunctionComponent<ComponentOpts> = ({
gutterSize="s"
>
<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}
previousSnoozeInterval={previousSnoozeInterval}
/>
</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}
previousSnoozeInterval={previousSnoozeInterval}
/>
</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 @@ -360,6 +360,7 @@ export const RulesList: React.FunctionComponent = () => {
unsnoozeRule={async () => await unsnoozeRule({ http, id: item.id })}
item={item}
onRuleChanged={() => loadRulesData()}
isEditable={item.isEditable && isRuleTypeEditableInContext(item.ruleTypeId)}
previousSnoozeInterval={previousSnoozeInterval}
/>
);
Expand Down