Skip to content

Commit

Permalink
Hide snooze panel in rules list
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaweiWu committed May 18, 2022
1 parent 68e38d8 commit 354242a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const allowedExperimentalValues = Object.freeze({
ruleTagFilter: true,
ruleStatusFilter: true,
rulesDetailLogs: true,
rulesListNotify: false,
});

type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface ComponentOpts {
isEditable: boolean;
previousSnoozeInterval?: string | null;
direction?: 'column' | 'row';
hideSnoozeOption?: boolean;
}

const COMMON_SNOOZE_TIMES: Array<[number, SnoozeUnit]> = [
Expand Down Expand Up @@ -83,6 +84,7 @@ export const RuleStatusDropdown: React.FunctionComponent<ComponentOpts> = ({
unsnoozeRule,
isEditable,
previousSnoozeInterval: propsPreviousSnoozeInterval,
hideSnoozeOption = false,
direction = 'column',
}: ComponentOpts) => {
const [isEnabled, setIsEnabled] = useState<boolean>(rule.enabled);
Expand Down Expand Up @@ -217,6 +219,7 @@ export const RuleStatusDropdown: React.FunctionComponent<ComponentOpts> = ({
isSnoozed={isSnoozed}
snoozeEndTime={rule.snoozeEndTime}
previousSnoozeInterval={previousSnoozeInterval}
hideSnoozeOption={hideSnoozeOption}
/>
</EuiPopover>
) : (
Expand All @@ -238,6 +241,7 @@ interface RuleStatusMenuProps {
isSnoozed: boolean;
snoozeEndTime?: Date | null;
previousSnoozeInterval: string | null;
hideSnoozeOption?: boolean;
}

const RuleStatusMenu: React.FunctionComponent<RuleStatusMenuProps> = ({
Expand All @@ -248,6 +252,7 @@ const RuleStatusMenu: React.FunctionComponent<RuleStatusMenuProps> = ({
isSnoozed,
snoozeEndTime,
previousSnoozeInterval,
hideSnoozeOption = false,
}) => {
const enableRule = useCallback(() => {
if (isSnoozed) {
Expand Down Expand Up @@ -283,6 +288,44 @@ const RuleStatusMenu: React.FunctionComponent<RuleStatusMenuProps> = ({
);
}

const getSnoozeMenuItem = () => {
if (!hideSnoozeOption) {
return [
{
name: snoozeButtonTitle,
icon: isEnabled && isSnoozed ? 'check' : 'empty',
panel: 1,
disabled: !isEnabled,
'data-test-subj': 'statusDropdownSnoozeItem',
},
];
}
return [];
};

const getSnoozePanel = () => {
if (!hideSnoozeOption) {
return [
{
id: 1,
width: 360,
title: SNOOZE,
content: (
<EuiPanel paddingSize="none">
<SnoozePanel
applySnooze={onApplySnooze}
interval={futureTimeToInterval(snoozeEndTime)}
showCancel={isSnoozed}
previousSnoozeInterval={previousSnoozeInterval}
/>
</EuiPanel>
),
},
];
}
return [];
};

const panels = [
{
id: 0,
Expand All @@ -298,30 +341,10 @@ const RuleStatusMenu: React.FunctionComponent<RuleStatusMenuProps> = ({
icon: !isEnabled ? 'check' : 'empty',
onClick: disableRule,
},
{
name: snoozeButtonTitle,
icon: isEnabled && isSnoozed ? 'check' : 'empty',
panel: 1,
disabled: !isEnabled,
'data-test-subj': 'statusDropdownSnoozeItem',
},
...getSnoozeMenuItem(),
],
},
{
id: 1,
width: 360,
title: SNOOZE,
content: (
<EuiPanel paddingSize="none">
<SnoozePanel
applySnooze={onApplySnooze}
interval={futureTimeToInterval(snoozeEndTime)}
showCancel={isSnoozed}
previousSnoozeInterval={previousSnoozeInterval}
/>
</EuiPanel>
),
},
...getSnoozePanel(),
];

return <EuiContextMenu data-test-subj="ruleStatusMenu" initialPanelId={0} panels={panels} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import { RuleDurationFormat } from './rule_duration_format';
import { checkRuleTypeEnabled } from '../../../lib/check_rule_type_enabled';
import { getFormattedSuccessRatio } from '../../../lib/monitoring_utils';
import { hasAllPrivilege } from '../../../lib/capabilities';
import { getIsExperimentalFeatureEnabled } from '../../../../common/get_experimental_features';
import { RuleTagBadge } from './rule_tag_badge';
import { RuleStatusDropdown } from './rule_status_dropdown';
import { RulesListNotifyBadge } from './rules_list_notify_badge';
Expand Down Expand Up @@ -177,8 +176,6 @@ export const RulesListTable = (props: RulesListTableProps) => {
const [tagPopoverOpenIndex, setTagPopoverOpenIndex] = useState<number>(-1);
const [currentlyOpenNotify, setCurrentlyOpenNotify] = useState<string>();

const isRulesListNotifyEnabled = getIsExperimentalFeatureEnabled('rulesListNotify');

const selectedPercentile = useMemo(() => {
const selectedOption = percentileOptions.find((option) => option.checked === 'on');
if (selectedOption) {
Expand Down Expand Up @@ -225,6 +222,7 @@ export const RulesListTable = (props: RulesListTableProps) => {
const renderRuleStatusDropdown = (ruleEnabled: boolean | undefined, rule: RuleTableItem) => {
return (
<RuleStatusDropdown
hideSnoozeOption
disableRule={async () => await onDisableRule(rule)}
enableRule={async () => await onEnableRule(rule)}
snoozeRule={async (snoozeEndTime: string | -1, interval: string | null) => {
Expand Down Expand Up @@ -286,35 +284,6 @@ export const RulesListTable = (props: RulesListTableProps) => {
);
};

const getRulesListNotifyColumn = () => {
if (isRulesListNotifyEnabled) {
return [
{
name: 'Notify',
width: '16%',
'data-test-subj': 'rulesTableCell-rulesListNotify',
render: (rule: RuleTableItem) => {
return (
<RulesListNotifyBadge
rule={rule}
isOpen={currentlyOpenNotify === rule.id}
onClick={() => setCurrentlyOpenNotify(rule.id)}
onClose={() => setCurrentlyOpenNotify('')}
onRuleChanged={onRuleChanged}
snoozeRule={async (snoozeEndTime: string | -1, interval: string | null) => {
await onSnoozeRule(rule, snoozeEndTime);
}}
unsnoozeRule={async () => await onUnsnoozeRule(rule)}
/>
);
},
},
];
}

return [];
};

const getRulesTableColumns = (): Array<
| EuiTableFieldDataColumnType<RuleTableItem>
| EuiTableComputedColumnType<RuleTableItem>
Expand Down Expand Up @@ -425,7 +394,26 @@ export const RulesListTable = (props: RulesListTableProps) => {
}
},
},
...getRulesListNotifyColumn(),
{
name: 'Notify',
width: '16%',
'data-test-subj': 'rulesTableCell-rulesListNotify',
render: (rule: RuleTableItem) => {
return (
<RulesListNotifyBadge
rule={rule}
isOpen={currentlyOpenNotify === rule.id}
onClick={() => setCurrentlyOpenNotify(rule.id)}
onClose={() => setCurrentlyOpenNotify('')}
onRuleChanged={onRuleChanged}
snoozeRule={async (snoozeEndTime: string | -1, interval: string | null) => {
await onSnoozeRule(rule, snoozeEndTime);
}}
unsnoozeRule={async () => await onUnsnoozeRule(rule)}
/>
);
},
},
{
field: 'schedule.interval',
width: '6%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('getIsExperimentalFeatureEnabled', () => {
ruleTagFilter: true,
ruleStatusFilter: true,
internalShareableComponentsSandbox: true,
rulesListNotify: true,
},
});

Expand Down Expand Up @@ -49,10 +48,6 @@ describe('getIsExperimentalFeatureEnabled', () => {

expect(result).toEqual(true);

result = getIsExperimentalFeatureEnabled('rulesListNotify');

expect(result).toEqual(true);

expect(() => getIsExperimentalFeatureEnabled('doesNotExist' as any)).toThrowError(
`Invalid enable value doesNotExist. Allowed values are: ${allowedExperimentalValueKeys.join(
', '
Expand Down

0 comments on commit 354242a

Please sign in to comment.