diff --git a/x-pack/plugins/alerting/server/plugin.test.ts b/x-pack/plugins/alerting/server/plugin.test.ts index 05b7526a376fb..3f1737f6e1fdf 100644 --- a/x-pack/plugins/alerting/server/plugin.test.ts +++ b/x-pack/plugins/alerting/server/plugin.test.ts @@ -50,7 +50,6 @@ const sampleRuleType: RuleType = { defaultActionGroupId: 'default', producer: 'test', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000, diff --git a/x-pack/plugins/alerting/server/rule_type_registry.test.ts b/x-pack/plugins/alerting/server/rule_type_registry.test.ts index d6417e8f2f806..34dca1faa79ca 100644 --- a/x-pack/plugins/alerting/server/rule_type_registry.test.ts +++ b/x-pack/plugins/alerting/server/rule_type_registry.test.ts @@ -57,7 +57,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -84,7 +83,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -123,7 +121,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -153,7 +150,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -186,7 +182,6 @@ describe('Create Lifecycle', () => { producer: 'alerts', defaultScheduleInterval: 'foobar', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -280,7 +275,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -315,7 +309,6 @@ describe('Create Lifecycle', () => { minimumLicenseRequired: 'basic', isExportable: true, config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -354,7 +347,6 @@ describe('Create Lifecycle', () => { minimumLicenseRequired: 'basic', isExportable: true, config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -397,7 +389,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -429,7 +420,6 @@ describe('Create Lifecycle', () => { producer: 'alerts', ruleTaskTimeout: '20m', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -467,7 +457,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -496,7 +485,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -518,7 +506,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -546,7 +533,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -576,10 +562,6 @@ describe('Create Lifecycle', () => { "max": 1000, }, }, - "minimumScheduleInterval": Object { - "enforce": false, - "value": "1m", - }, }, "defaultActionGroupId": "default", "executor": [MockFunction], @@ -630,7 +612,6 @@ describe('Create Lifecycle', () => { executor: jest.fn(), producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -730,7 +711,6 @@ describe('Create Lifecycle', () => { minimumLicenseRequired: 'basic', recoveryActionGroup: { id: 'recovered', name: 'Recovered' }, config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, @@ -769,7 +749,6 @@ function ruleTypeWithVariables( async executor() {}, producer: 'alerts', config: { - minimumScheduleInterval: { value: '1m', enforce: false }, execution: { actions: { max: 1000 }, }, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_add.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_add.tsx index f2287163edc1c..2d6a7ec4bf63d 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_add.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_add.tsx @@ -79,6 +79,7 @@ const RuleAdd = ({ const [ruleTypeIndex, setRuleTypeIndex] = useState( props.ruleTypeIndex ); + const [changedFromDefaultInterval, setChangedFromDefaultInterval] = useState(false); const setRule = (value: InitialRule) => { dispatch({ command: { type: 'setRule' }, payload: { key: 'rule', value } }); @@ -146,28 +147,28 @@ const RuleAdd = ({ })(); }, [rule, actionTypeRegistry]); + useEffect(() => { + if (config.minimumScheduleInterval && !initialValues?.schedule?.interval) { + setRuleProperty('schedule', { + interval: getInitialInterval(config.minimumScheduleInterval.value), + }); + } + }, [config.minimumScheduleInterval, initialValues]); + useEffect(() => { if (rule.ruleTypeId && ruleTypeIndex) { - // rule type selected const type = ruleTypeIndex.get(rule.ruleTypeId); - if (type?.defaultScheduleInterval) { + if (type?.defaultScheduleInterval && !changedFromDefaultInterval) { setRuleProperty('schedule', { interval: type.defaultScheduleInterval }); } - } else { - // no rule type selection and no initial value set; set schedule to global default or configured minimum, whichever is larger - if (!initialValues?.schedule?.interval) { - setRuleProperty('schedule', { - interval: getInitialInterval(config.minimumScheduleInterval?.value), - }); - } } - }, [ - initialValues, - rule.ruleTypeId, - ruleTypeIndex, - rule.schedule.interval, - config.minimumScheduleInterval, - ]); + }, [rule.ruleTypeId, ruleTypeIndex, rule.schedule.interval, changedFromDefaultInterval]); + + useEffect(() => { + if (rule.schedule.interval !== DEFAULT_RULE_INTERVAL && !changedFromDefaultInterval) { + setChangedFromDefaultInterval(true); + } + }, [rule.schedule.interval, changedFromDefaultInterval]); const checkForChangesAndCloseFlyout = () => { if (