Skip to content

Commit

Permalink
Fixing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Mar 21, 2022
1 parent 7037966 commit fe3ccf4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 38 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/alerting/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const sampleRuleType: RuleType<never, never, never, never, never, 'default'> = {
defaultActionGroupId: 'default',
producer: 'test',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: {
max: 1000,
Expand Down
21 changes: 0 additions & 21 deletions x-pack/plugins/alerting/server/rule_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand All @@ -84,7 +83,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -123,7 +121,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -153,7 +150,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -186,7 +182,6 @@ describe('Create Lifecycle', () => {
producer: 'alerts',
defaultScheduleInterval: 'foobar',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -280,7 +275,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -315,7 +309,6 @@ describe('Create Lifecycle', () => {
minimumLicenseRequired: 'basic',
isExportable: true,
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -354,7 +347,6 @@ describe('Create Lifecycle', () => {
minimumLicenseRequired: 'basic',
isExportable: true,
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -397,7 +389,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -429,7 +420,6 @@ describe('Create Lifecycle', () => {
producer: 'alerts',
ruleTaskTimeout: '20m',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -467,7 +457,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -496,7 +485,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand All @@ -518,7 +506,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -546,7 +533,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -576,10 +562,6 @@ describe('Create Lifecycle', () => {
"max": 1000,
},
},
"minimumScheduleInterval": Object {
"enforce": false,
"value": "1m",
},
},
"defaultActionGroupId": "default",
"executor": [MockFunction],
Expand Down Expand Up @@ -630,7 +612,6 @@ describe('Create Lifecycle', () => {
executor: jest.fn(),
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -730,7 +711,6 @@ describe('Create Lifecycle', () => {
minimumLicenseRequired: 'basic',
recoveryActionGroup: { id: 'recovered', name: 'Recovered' },
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down Expand Up @@ -769,7 +749,6 @@ function ruleTypeWithVariables<ActionGroupIds extends string>(
async executor() {},
producer: 'alerts',
config: {
minimumScheduleInterval: { value: '1m', enforce: false },
execution: {
actions: { max: 1000 },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const RuleAdd = ({
const [ruleTypeIndex, setRuleTypeIndex] = useState<RuleTypeIndex | undefined>(
props.ruleTypeIndex
);
const [changedFromDefaultInterval, setChangedFromDefaultInterval] = useState<boolean>(false);

const setRule = (value: InitialRule) => {
dispatch({ command: { type: 'setRule' }, payload: { key: 'rule', value } });
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit fe3ccf4

Please sign in to comment.