mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-28 10:51:49 -05:00
add schedule form validation to ensure at least one occurrence
This commit is contained in:
@@ -20,6 +20,7 @@ import ScheduleFormFields from './ScheduleFormFields';
|
||||
import UnsupportedScheduleForm from './UnsupportedScheduleForm';
|
||||
import parseRuleObj, { UnsupportedRRuleError } from './parseRuleObj';
|
||||
import buildRuleObj from './buildRuleObj';
|
||||
import buildRuleSet from './buildRuleSet';
|
||||
|
||||
const NUM_DAYS_PER_FREQUENCY = {
|
||||
week: 7,
|
||||
@@ -411,6 +412,26 @@ function ScheduleForm({
|
||||
}
|
||||
});
|
||||
|
||||
if (values.exceptionFrequency.length > 0) {
|
||||
let rangeToCheck = 1;
|
||||
values.frequency.forEach((freq) => {
|
||||
if (NUM_DAYS_PER_FREQUENCY[freq] > rangeToCheck) {
|
||||
rangeToCheck = NUM_DAYS_PER_FREQUENCY[freq];
|
||||
}
|
||||
});
|
||||
const ruleSet = buildRuleSet(values, true);
|
||||
const startDate = DateTime.fromISO(values.startDate);
|
||||
const endDate = startDate.plus({ days: rangeToCheck });
|
||||
const instances = ruleSet.between(
|
||||
startDate.toJSDate(),
|
||||
endDate.toJSDate(),
|
||||
true
|
||||
);
|
||||
if (instances.length === 0) {
|
||||
errors.exceptionFrequency = t`This schedule has no occurrences due to the selected exceptions.`;
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user