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