mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 02:19:58 -03:30
improve frequency validation performance
This commit is contained in:
parent
16da9b784a
commit
35e9d00beb
@ -412,24 +412,8 @@ 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.`;
|
||||
}
|
||||
if (values.exceptionFrequency.length > 0 && !scheduleHasInstances(values)) {
|
||||
errors.exceptionFrequency = t`This schedule has no occurrences due to the selected exceptions.`;
|
||||
}
|
||||
|
||||
return errors;
|
||||
@ -539,3 +523,24 @@ ScheduleForm.defaultProps = {
|
||||
};
|
||||
|
||||
export default ScheduleForm;
|
||||
|
||||
function scheduleHasInstances(values) {
|
||||
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,
|
||||
(date, i) => i === 0
|
||||
);
|
||||
|
||||
return instances.length > 0;
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ export default function ScheduleFormFields({
|
||||
>
|
||||
<FrequencySelect
|
||||
id="exception-frequency"
|
||||
onChange={exceptionFrequencyHelper.setValue}
|
||||
onChange={updateFrequency(exceptionFrequencyHelper.setValue)}
|
||||
value={exceptionFrequency.value}
|
||||
placeholderText={
|
||||
exceptionFrequency.value.length
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user