Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaweiWu committed May 20, 2022
1 parent 0a12470 commit 35f0de5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,15 @@ const RuleStatusMenu: React.FunctionComponent<RuleStatusMenuProps> = ({

interface SnoozePanelProps {
interval?: string;
isLoading?: boolean;
applySnooze: (value: number | -1, unit?: SnoozeUnit) => void;
showCancel: boolean;
previousSnoozeInterval: string | null;
}

export const SnoozePanel: React.FunctionComponent<SnoozePanelProps> = ({
interval = '3d',
isLoading = false,
applySnooze,
showCancel,
previousSnoozeInterval,
Expand Down Expand Up @@ -453,7 +455,11 @@ export const SnoozePanel: React.FunctionComponent<SnoozePanelProps> = ({
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton onClick={onClickApplyButton} data-test-subj="ruleSnoozeApply">
<EuiButton
isLoading={isLoading}
onClick={onClickApplyButton}
data-test-subj="ruleSnoozeApply"
>
{i18n.translate('xpack.triggersActionsUI.sections.rulesList.applySnooze', {
defaultMessage: 'Apply',
})}
Expand Down Expand Up @@ -496,7 +502,12 @@ export const SnoozePanel: React.FunctionComponent<SnoozePanelProps> = ({
<EuiHorizontalRule margin="s" />
<EuiFlexGroup>
<EuiFlexItem grow>
<EuiButton color="danger" onClick={onCancelSnooze} data-test-subj="ruleSnoozeCancel">
<EuiButton
isLoading={isLoading}
color="danger"
onClick={onCancelSnooze}
data-test-subj="ruleSnoozeCancel"
>
Cancel snooze
</EuiButton>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import moment from 'moment';
import { EuiButton, EuiButtonIcon, EuiPopover, EuiText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -46,12 +46,14 @@ export const RulesListNotifyBadge: React.FunctionComponent<RulesListNotifyBadgeP
unsnoozeRule,
} = props;

const { snoozeEndTime, muteAll } = rule;
const { isSnoozedUntil, muteAll } = rule;

const [previousSnoozeInterval, setPreviousSnoozeInterval] = usePreviousSnoozeInterval(
propsPreviousSnoozeInterval
);

const [isLoading, setIsLoading] = useState<boolean>(false);

const isSnoozed = useMemo(() => {
return isRuleSnoozed(rule);
}, [rule]);
Expand All @@ -65,11 +67,11 @@ export const RulesListNotifyBadge: React.FunctionComponent<RulesListNotifyBadgeP
if (muteAll) {
return 'Indefinite';
}
if (!snoozeEndTime) {
if (!isSnoozedUntil) {
return '';
}
return moment(snoozeEndTime).format('MMM D');
}, [snoozeEndTime, muteAll]);
return moment(isSnoozedUntil).format('MMM D');
}, [isSnoozedUntil, muteAll]);

const button = useMemo(() => {
if (isSnoozed || isScheduled) {
Expand Down Expand Up @@ -119,6 +121,7 @@ export const RulesListNotifyBadge: React.FunctionComponent<RulesListNotifyBadgeP

const onChangeSnooze = useCallback(
async (value: number, unit?: SnoozeUnit) => {
setIsLoading(true);
try {
if (value === -1) {
await snoozeRuleAndStoreInterval(-1, null);
Expand All @@ -129,16 +132,18 @@ export const RulesListNotifyBadge: React.FunctionComponent<RulesListNotifyBadgeP
onRuleChanged();
} finally {
onClose();
setIsLoading(false);
}
},
[onRuleChanged, onClose, snoozeRuleAndStoreInterval, unsnoozeRule]
[onRuleChanged, onClose, snoozeRuleAndStoreInterval, unsnoozeRule, setIsLoading]
);

return (
<EuiPopover isOpen={isOpen} closePopover={onClose} button={button}>
<SnoozePanel
isLoading={isLoading}
applySnooze={onChangeSnooze}
interval={futureTimeToInterval(snoozeEndTime)}
interval={futureTimeToInterval(isSnoozedUntil)}
showCancel={isSnoozed}
previousSnoozeInterval={previousSnoozeInterval}
/>
Expand Down

0 comments on commit 35f0de5

Please sign in to comment.