Skip to content

Commit

Permalink
Merge pull request #10898 from kialam/fix-10718-null-datetime
Browse files Browse the repository at this point in the history
Validate that start/end datetime creates at least 1 schedule.
  • Loading branch information
kialam authored Aug 20, 2021
2 parents b7c0f02 + da2bf4c commit c6a63d0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
14 changes: 7 additions & 7 deletions awx/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion awx/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"react-error-boundary": "^3.1.3",
"react-router-dom": "^5.1.2",
"react-virtualized": "^9.21.1",
"rrule": "^2.6.4",
"rrule": "2.6.4",
"sanitize-html": "2.4.0",
"styled-components": "5.3.0"
},
Expand Down
21 changes: 20 additions & 1 deletion awx/ui/src/components/Schedule/shared/ScheduleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import {
import FrequencyDetailSubform from './FrequencyDetailSubform';
import SchedulePromptableFields from './SchedulePromptableFields';
import DateTimePicker from './DateTimePicker';
import buildRuleObj from './buildRuleObj';

const NUM_DAYS_PER_FREQUENCY = {
week: 7,
month: 31,
year: 365,
};

const generateRunOnTheDay = (days = []) => {
if (
Expand Down Expand Up @@ -555,6 +562,19 @@ function ScheduleForm({
startDate,
} = values;

if (
end === 'onDate' &&
DateTime.fromISO(endDate)
.diff(DateTime.fromISO(startDate), 'days')
.toObject().days < NUM_DAYS_PER_FREQUENCY[frequency]
) {
const rule = new RRule(buildRuleObj(values));
if (rule.all().length === 0) {
errors.startDate = t`Selected date range must have at least 1 schedule occurrence.`;
errors.endDate = t`Selected date range must have at least 1 schedule occurrence.`;
}
}

if (
end === 'onDate' &&
DateTime.fromISO(startDate) >= DateTime.fromISO(endDate)
Expand All @@ -569,7 +589,6 @@ function ScheduleForm({
) {
errors.runOn = t`Please select a day number between 1 and 31.`;
}

return errors;
}}
>
Expand Down

0 comments on commit c6a63d0

Please sign in to comment.