mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[RAM] Prevent negative snooze intervals (#134934)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
a52957760a
commit
a7c4f36ac7
2 changed files with 13 additions and 2 deletions
|
@ -76,6 +76,7 @@ export const BaseSnoozePanel: React.FunctionComponent<BaseSnoozePanelProps> = ({
|
|||
const snoozeRuleAndStoreInterval = useCallback(
|
||||
(newSnoozeEndTime: string | -1, intervalToStore: string | null) => {
|
||||
if (intervalToStore) {
|
||||
if (intervalToStore.startsWith('-')) throw new Error('Cannot store a negative interval');
|
||||
setPreviousSnoozeInterval(intervalToStore);
|
||||
}
|
||||
const newSnoozeSchedule = {
|
||||
|
@ -170,7 +171,7 @@ export const BaseSnoozePanel: React.FunctionComponent<BaseSnoozePanelProps> = ({
|
|||
<EuiFlexGroup data-test-subj="snoozePanel" gutterSize="xs">
|
||||
<EuiFlexItem>
|
||||
<EuiFieldNumber
|
||||
min={0}
|
||||
min={1}
|
||||
value={intervalValue}
|
||||
onChange={onChangeValue}
|
||||
aria-label={i18n.translate(
|
||||
|
@ -201,6 +202,7 @@ export const BaseSnoozePanel: React.FunctionComponent<BaseSnoozePanelProps> = ({
|
|||
</EuiFlexItem>
|
||||
<EuiFlexItem grow={false}>
|
||||
<EuiButton
|
||||
disabled={!intervalValue || intervalValue < 1}
|
||||
isLoading={isLoading}
|
||||
onClick={onClickApplyButton}
|
||||
data-test-subj="ruleSnoozeApply"
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import moment from 'moment';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { parseInterval } from '../../../../../../../common';
|
||||
import { RecurrenceSchedule, SnoozeSchedule } from '../../../../../../types';
|
||||
import { recurrenceSummary } from '../recurrence_scheduler/helpers';
|
||||
import { SnoozeUnit } from './constants';
|
||||
|
@ -17,7 +18,15 @@ const PREV_SNOOZE_INTERVAL_KEY = 'triggersActionsUi_previousSnoozeInterval';
|
|||
export const usePreviousSnoozeInterval: (
|
||||
p?: string | null
|
||||
) => [string | null, (n: string) => void] = (propsInterval) => {
|
||||
const intervalFromStorage = localStorage.getItem(PREV_SNOOZE_INTERVAL_KEY);
|
||||
let intervalFromStorage = localStorage.getItem(PREV_SNOOZE_INTERVAL_KEY);
|
||||
if (intervalFromStorage) {
|
||||
try {
|
||||
parseInterval(intervalFromStorage);
|
||||
} catch (e) {
|
||||
intervalFromStorage = null;
|
||||
localStorage.removeItem(PREV_SNOOZE_INTERVAL_KEY);
|
||||
}
|
||||
}
|
||||
const usePropsInterval = typeof propsInterval !== 'undefined';
|
||||
const interval = usePropsInterval ? propsInterval : intervalFromStorage;
|
||||
const [previousSnoozeInterval, setPreviousSnoozeInterval] = useState<string | null>(interval);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue