mirror of
https://github.com/ZwareBear/awx.git
synced 2026-03-20 07:43:35 -05:00
Merge pull request #12778 from keithjgrant/12542-schedule-exceptions
Schedule exceptions
This commit is contained in:
@@ -29,4 +29,8 @@ export default styled(DetailList)`
|
|||||||
--column-count: 3;
|
--column-count: 3;
|
||||||
}
|
}
|
||||||
`}
|
`}
|
||||||
|
|
||||||
|
& + & {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -10,7 +10,13 @@ const Label = styled.div`
|
|||||||
font-weight: var(--pf-global--FontWeight--bold);
|
font-weight: var(--pf-global--FontWeight--bold);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function FrequencyDetails({ type, label, options, timezone }) {
|
export default function FrequencyDetails({
|
||||||
|
type,
|
||||||
|
label,
|
||||||
|
options,
|
||||||
|
timezone,
|
||||||
|
isException,
|
||||||
|
}) {
|
||||||
const getRunEveryLabel = () => {
|
const getRunEveryLabel = () => {
|
||||||
const { interval } = options;
|
const { interval } = options;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -77,11 +83,17 @@ export default function FrequencyDetails({ type, label, options, timezone }) {
|
|||||||
6: t`Sunday`,
|
6: t`Sunday`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const prefix = isException ? `exception-${type}` : `frequency-${type}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Label>{label}</Label>
|
<Label>{label}</Label>
|
||||||
<DetailList gutter="sm">
|
<DetailList gutter="sm">
|
||||||
<Detail label={t`Run every`} value={getRunEveryLabel()} />
|
<Detail
|
||||||
|
label={isException ? t`Skip every` : t`Run every`}
|
||||||
|
value={getRunEveryLabel()}
|
||||||
|
dataCy={`${prefix}-run-every`}
|
||||||
|
/>
|
||||||
{type === 'week' ? (
|
{type === 'week' ? (
|
||||||
<Detail
|
<Detail
|
||||||
label={t`On days`}
|
label={t`On days`}
|
||||||
@@ -89,10 +101,15 @@ export default function FrequencyDetails({ type, label, options, timezone }) {
|
|||||||
.sort(sortWeekday)
|
.sort(sortWeekday)
|
||||||
.map((d) => weekdays[d.weekday])
|
.map((d) => weekdays[d.weekday])
|
||||||
.join(', ')}
|
.join(', ')}
|
||||||
|
dataCy={`${prefix}-days-of-week`}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
<RunOnDetail type={type} options={options} />
|
<RunOnDetail type={type} options={options} prefix={prefix} />
|
||||||
<Detail label={t`End`} value={getEndValue(type, options, timezone)} />
|
<Detail
|
||||||
|
label={t`End`}
|
||||||
|
value={getEndValue(type, options, timezone)}
|
||||||
|
dataCy={`${prefix}-end`}
|
||||||
|
/>
|
||||||
</DetailList>
|
</DetailList>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -104,11 +121,15 @@ function sortWeekday(a, b) {
|
|||||||
return a.weekday - b.weekday;
|
return a.weekday - b.weekday;
|
||||||
}
|
}
|
||||||
|
|
||||||
function RunOnDetail({ type, options }) {
|
function RunOnDetail({ type, options, prefix }) {
|
||||||
if (type === 'month') {
|
if (type === 'month') {
|
||||||
if (options.runOn === 'day') {
|
if (options.runOn === 'day') {
|
||||||
return (
|
return (
|
||||||
<Detail label={t`Run on`} value={t`Day ${options.runOnDayNumber}`} />
|
<Detail
|
||||||
|
label={t`Run on`}
|
||||||
|
value={t`Day ${options.runOnDayNumber}`}
|
||||||
|
dataCy={`${prefix}-run-on-day`}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const dayOfWeek = options.runOnTheDay;
|
const dayOfWeek = options.runOnTheDay;
|
||||||
@@ -129,6 +150,7 @@ function RunOnDetail({ type, options }) {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
dataCy={`${prefix}-run-on-day`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -152,6 +174,7 @@ function RunOnDetail({ type, options }) {
|
|||||||
<Detail
|
<Detail
|
||||||
label={t`Run on`}
|
label={t`Run on`}
|
||||||
value={`${months[options.runOnTheMonth]} ${options.runOnDayMonth}`}
|
value={`${months[options.runOnTheMonth]} ${options.runOnDayMonth}`}
|
||||||
|
dataCy={`${prefix}-run-on-day`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -186,6 +209,7 @@ function RunOnDetail({ type, options }) {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
dataCy={`${prefix}-run-on-day`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import 'styled-components/macro';
|
|||||||
import React, { useCallback, useEffect } from 'react';
|
import React, { useCallback, useEffect } from 'react';
|
||||||
import { Link, useHistory, useLocation } from 'react-router-dom';
|
import { Link, useHistory, useLocation } from 'react-router-dom';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Chip, Divider, Title, Button } from '@patternfly/react-core';
|
import { Chip, Divider, Title, Button } from '@patternfly/react-core';
|
||||||
import { Schedule } from 'types';
|
import { Schedule } from 'types';
|
||||||
@@ -60,6 +59,10 @@ const FrequencyDetailsContainer = styled.div`
|
|||||||
padding-bottom: var(--pf-global--spacer--md);
|
padding-bottom: var(--pf-global--spacer--md);
|
||||||
border-bottom: 1px solid var(--pf-global--palette--black-300);
|
border-bottom: 1px solid var(--pf-global--palette--black-300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& + & {
|
||||||
|
margin-top: calc(var(--pf-global--spacer--lg) * -1);
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
||||||
@@ -161,10 +164,14 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
|||||||
month: t`Month`,
|
month: t`Month`,
|
||||||
year: t`Year`,
|
year: t`Year`,
|
||||||
};
|
};
|
||||||
const { frequency, frequencyOptions } = parseRuleObj(schedule);
|
const { frequency, frequencyOptions, exceptionFrequency, exceptionOptions } =
|
||||||
|
parseRuleObj(schedule);
|
||||||
const repeatFrequency = frequency.length
|
const repeatFrequency = frequency.length
|
||||||
? frequency.map((f) => frequencies[f]).join(', ')
|
? frequency.map((f) => frequencies[f]).join(', ')
|
||||||
: t`None (Run Once)`;
|
: t`None (Run Once)`;
|
||||||
|
const exceptionRepeatFrequency = exceptionFrequency.length
|
||||||
|
? exceptionFrequency.map((f) => frequencies[f]).join(', ')
|
||||||
|
: t`None (Run Once)`;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ask_credential_on_launch,
|
ask_credential_on_launch,
|
||||||
@@ -271,43 +278,84 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
|||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
/>
|
/>
|
||||||
<DetailList gutter="sm">
|
<DetailList gutter="sm">
|
||||||
<Detail label={t`Name`} value={name} />
|
<Detail label={t`Name`} value={name} dataCy="schedule-name" />
|
||||||
<Detail label={t`Description`} value={description} />
|
<Detail
|
||||||
|
label={t`Description`}
|
||||||
|
value={description}
|
||||||
|
dataCy="schedule-description"
|
||||||
|
/>
|
||||||
<Detail
|
<Detail
|
||||||
label={t`First Run`}
|
label={t`First Run`}
|
||||||
value={formatDateString(dtstart, timezone)}
|
value={formatDateString(dtstart, timezone)}
|
||||||
|
dataCy="schedule-first-run"
|
||||||
/>
|
/>
|
||||||
<Detail
|
<Detail
|
||||||
label={t`Next Run`}
|
label={t`Next Run`}
|
||||||
value={formatDateString(next_run, timezone)}
|
value={formatDateString(next_run, timezone)}
|
||||||
|
dataCy="schedule-next-run"
|
||||||
/>
|
/>
|
||||||
<Detail label={t`Last Run`} value={formatDateString(dtend, timezone)} />
|
<Detail label={t`Last Run`} value={formatDateString(dtend, timezone)} />
|
||||||
<Detail
|
<Detail
|
||||||
label={t`Local Time Zone`}
|
label={t`Local Time Zone`}
|
||||||
value={timezone}
|
value={timezone}
|
||||||
helpText={helpText.localTimeZone(config)}
|
helpText={helpText.localTimeZone(config)}
|
||||||
|
dataCy="schedule-timezone"
|
||||||
|
/>
|
||||||
|
<Detail
|
||||||
|
label={t`Repeat Frequency`}
|
||||||
|
value={repeatFrequency}
|
||||||
|
dataCy="schedule-repeat-frequency"
|
||||||
|
/>
|
||||||
|
<Detail
|
||||||
|
label={t`Exception Frequency`}
|
||||||
|
value={exceptionRepeatFrequency}
|
||||||
|
dataCy="schedule-exception-frequency"
|
||||||
/>
|
/>
|
||||||
<Detail label={t`Repeat Frequency`} value={repeatFrequency} />
|
|
||||||
</DetailList>
|
</DetailList>
|
||||||
{frequency.length ? (
|
{frequency.length ? (
|
||||||
<FrequencyDetailsContainer>
|
<FrequencyDetailsContainer>
|
||||||
<p>
|
<div ouia-component-id="schedule-frequency-details">
|
||||||
<strong>{t`Frequency Details`}</strong>
|
<p>
|
||||||
</p>
|
<strong>{t`Frequency Details`}</strong>
|
||||||
{frequency.map((freq) => (
|
</p>
|
||||||
<FrequencyDetails
|
{frequency.map((freq) => (
|
||||||
key={freq}
|
<FrequencyDetails
|
||||||
type={freq}
|
key={freq}
|
||||||
label={frequencies[freq]}
|
type={freq}
|
||||||
options={frequencyOptions[freq]}
|
label={frequencies[freq]}
|
||||||
timezone={timezone}
|
options={frequencyOptions[freq]}
|
||||||
/>
|
timezone={timezone}
|
||||||
))}
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</FrequencyDetailsContainer>
|
||||||
|
) : null}
|
||||||
|
{exceptionFrequency.length ? (
|
||||||
|
<FrequencyDetailsContainer>
|
||||||
|
<div ouia-component-id="schedule-exception-details">
|
||||||
|
<p css="border-top: 0">
|
||||||
|
<strong>{t`Frequency Exception Details`}</strong>
|
||||||
|
</p>
|
||||||
|
{exceptionFrequency.map((freq) => (
|
||||||
|
<FrequencyDetails
|
||||||
|
key={freq}
|
||||||
|
type={freq}
|
||||||
|
label={frequencies[freq]}
|
||||||
|
options={exceptionOptions[freq]}
|
||||||
|
timezone={timezone}
|
||||||
|
isException
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</FrequencyDetailsContainer>
|
</FrequencyDetailsContainer>
|
||||||
) : null}
|
) : null}
|
||||||
<DetailList gutter="sm">
|
<DetailList gutter="sm">
|
||||||
{hasDaysToKeepField ? (
|
{hasDaysToKeepField ? (
|
||||||
<Detail label={t`Days of Data to Keep`} value={daysToKeep} />
|
<Detail
|
||||||
|
label={t`Days of Data to Keep`}
|
||||||
|
value={daysToKeep}
|
||||||
|
dataCy="schedule-days-to-keep"
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
<ScheduleOccurrences preview={preview} tz={timezone} />
|
<ScheduleOccurrences preview={preview} tz={timezone} />
|
||||||
<UserDateDetail
|
<UserDateDetail
|
||||||
@@ -327,7 +375,11 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
|||||||
<PromptDivider />
|
<PromptDivider />
|
||||||
<PromptDetailList>
|
<PromptDetailList>
|
||||||
{ask_job_type_on_launch && (
|
{ask_job_type_on_launch && (
|
||||||
<Detail label={t`Job Type`} value={job_type} />
|
<Detail
|
||||||
|
label={t`Job Type`}
|
||||||
|
value={job_type}
|
||||||
|
dataCy="shedule-job-type"
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{showInventoryDetail && (
|
{showInventoryDetail && (
|
||||||
<Detail
|
<Detail
|
||||||
@@ -347,19 +399,31 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
|||||||
' '
|
' '
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
dataCy="schedule-inventory"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{ask_verbosity_on_launch && (
|
{ask_verbosity_on_launch && (
|
||||||
<Detail label={t`Verbosity`} value={VERBOSITY()[verbosity]} />
|
<Detail
|
||||||
|
label={t`Verbosity`}
|
||||||
|
value={VERBOSITY()[verbosity]}
|
||||||
|
dataCy="schedule-verbosity"
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{ask_scm_branch_on_launch && (
|
{ask_scm_branch_on_launch && (
|
||||||
<Detail label={t`Source Control Branch`} value={scm_branch} />
|
<Detail
|
||||||
|
label={t`Source Control Branch`}
|
||||||
|
value={scm_branch}
|
||||||
|
dataCy="schedule-scm-branch"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{ask_limit_on_launch && (
|
||||||
|
<Detail label={t`Limit`} value={limit} dataCy="schedule-limit" />
|
||||||
)}
|
)}
|
||||||
{ask_limit_on_launch && <Detail label={t`Limit`} value={limit} />}
|
|
||||||
{showDiffModeDetail && (
|
{showDiffModeDetail && (
|
||||||
<Detail
|
<Detail
|
||||||
label={t`Show Changes`}
|
label={t`Show Changes`}
|
||||||
value={diff_mode ? t`On` : t`Off`}
|
value={diff_mode ? t`On` : t`Off`}
|
||||||
|
dataCy="schedule-show-changes"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showCredentialsDetail && (
|
{showCredentialsDetail && (
|
||||||
@@ -382,6 +446,7 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
|||||||
))}
|
))}
|
||||||
</ChipGroup>
|
</ChipGroup>
|
||||||
}
|
}
|
||||||
|
dataCy="schedule-credentials"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showTagsDetail && (
|
{showTagsDetail && (
|
||||||
@@ -405,6 +470,7 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
|||||||
))}
|
))}
|
||||||
</ChipGroup>
|
</ChipGroup>
|
||||||
}
|
}
|
||||||
|
dataCy="schedule-job-tags"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showSkipTagsDetail && (
|
{showSkipTagsDetail && (
|
||||||
@@ -428,6 +494,7 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
|||||||
))}
|
))}
|
||||||
</ChipGroup>
|
</ChipGroup>
|
||||||
}
|
}
|
||||||
|
dataCy="schedule-skip-tags"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showVariablesDetail && (
|
{showVariablesDetail && (
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ const Checkbox = styled(_Checkbox)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const FrequencyDetailSubform = ({ frequency, prefix }) => {
|
const FrequencyDetailSubform = ({ frequency, prefix, isException }) => {
|
||||||
const id = prefix.replace('.', '-');
|
const id = prefix.replace('.', '-');
|
||||||
const [runOnDayMonth] = useField({
|
const [runOnDayMonth] = useField({
|
||||||
name: `${prefix}.runOnDayMonth`,
|
name: `${prefix}.runOnDayMonth`,
|
||||||
@@ -220,7 +220,7 @@ const FrequencyDetailSubform = ({ frequency, prefix }) => {
|
|||||||
validated={
|
validated={
|
||||||
!intervalMeta.touched || !intervalMeta.error ? 'default' : 'error'
|
!intervalMeta.touched || !intervalMeta.error ? 'default' : 'error'
|
||||||
}
|
}
|
||||||
label={t`Run every`}
|
label={isException ? t`Skip every` : t`Run every`}
|
||||||
>
|
>
|
||||||
<div css="display: flex">
|
<div css="display: flex">
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import ScheduleFormFields from './ScheduleFormFields';
|
|||||||
import UnsupportedScheduleForm from './UnsupportedScheduleForm';
|
import UnsupportedScheduleForm from './UnsupportedScheduleForm';
|
||||||
import parseRuleObj, { UnsupportedRRuleError } from './parseRuleObj';
|
import parseRuleObj, { UnsupportedRRuleError } from './parseRuleObj';
|
||||||
import buildRuleObj from './buildRuleObj';
|
import buildRuleObj from './buildRuleObj';
|
||||||
|
import buildRuleSet from './buildRuleSet';
|
||||||
|
|
||||||
const NUM_DAYS_PER_FREQUENCY = {
|
const NUM_DAYS_PER_FREQUENCY = {
|
||||||
week: 7,
|
week: 7,
|
||||||
@@ -411,6 +412,10 @@ function ScheduleForm({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (values.exceptionFrequency.length > 0 && !scheduleHasInstances(values)) {
|
||||||
|
errors.exceptionFrequency = t`This schedule has no occurrences due to the selected exceptions.`;
|
||||||
|
}
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -518,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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ const mockSchedule = {
|
|||||||
|
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
const defaultFieldsVisible = () => {
|
const defaultFieldsVisible = (isExceptionsVisible) => {
|
||||||
expect(wrapper.find('FormGroup[label="Name"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Name"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Description"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Description"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Start date/time"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Start date/time"]').length).toBe(1);
|
||||||
@@ -94,7 +94,11 @@ const defaultFieldsVisible = () => {
|
|||||||
expect(
|
expect(
|
||||||
wrapper.find('FormGroup[label="Local time zone"]').find('HelpIcon').length
|
wrapper.find('FormGroup[label="Local time zone"]').find('HelpIcon').length
|
||||||
).toBe(1);
|
).toBe(1);
|
||||||
expect(wrapper.find('FrequencySelect').length).toBe(1);
|
if (isExceptionsVisible) {
|
||||||
|
expect(wrapper.find('FrequencySelect').length).toBe(2);
|
||||||
|
} else {
|
||||||
|
expect(wrapper.find('FrequencySelect').length).toBe(1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const nonRRuleValuesMatch = () => {
|
const nonRRuleValuesMatch = () => {
|
||||||
@@ -513,7 +517,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
runFrequencySelect.invoke('onChange')(['minute']);
|
runFrequencySelect.invoke('onChange')(['minute']);
|
||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
||||||
@@ -547,7 +551,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
runFrequencySelect.invoke('onChange')(['hour']);
|
runFrequencySelect.invoke('onChange')(['hour']);
|
||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
||||||
@@ -579,7 +583,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
runFrequencySelect.invoke('onChange')(['day']);
|
runFrequencySelect.invoke('onChange')(['day']);
|
||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
||||||
@@ -611,7 +615,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
runFrequencySelect.invoke('onChange')(['week']);
|
runFrequencySelect.invoke('onChange')(['week']);
|
||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(1);
|
||||||
@@ -643,7 +647,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
runFrequencySelect.invoke('onChange')(['month']);
|
runFrequencySelect.invoke('onChange')(['month']);
|
||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
||||||
@@ -692,7 +696,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
runFrequencySelect.invoke('onChange')(['year']);
|
runFrequencySelect.invoke('onChange')(['year']);
|
||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
||||||
@@ -1058,7 +1062,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
|
|
||||||
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Occurrences"]').length).toBe(0);
|
expect(wrapper.find('FormGroup[label="Occurrences"]').length).toBe(0);
|
||||||
@@ -1113,7 +1117,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
|
|
||||||
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Occurrences"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Occurrences"]').length).toBe(1);
|
||||||
@@ -1171,7 +1175,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
|
|
||||||
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
expect(wrapper.find('FormGroup[label="On days"]').length).toBe(0);
|
||||||
@@ -1224,7 +1228,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
|
|
||||||
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="End date/time"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End date/time"]').length).toBe(1);
|
||||||
@@ -1318,10 +1322,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
|
|
||||||
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
|
|
||||||
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
|
||||||
defaultFieldsVisible();
|
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Run on"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run on"]').length).toBe(1);
|
||||||
@@ -1394,7 +1395,7 @@ describe('<ScheduleForm />', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
|
|
||||||
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
expect(wrapper.find('ScheduleForm').length).toBe(1);
|
||||||
defaultFieldsVisible();
|
defaultFieldsVisible(true);
|
||||||
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="End"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run every"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Run on"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Run on"]').length).toBe(1);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useField } from 'formik';
|
|||||||
import { FormGroup, Title } from '@patternfly/react-core';
|
import { FormGroup, Title } from '@patternfly/react-core';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import 'styled-components/macro';
|
||||||
import FormField from 'components/FormField';
|
import FormField from 'components/FormField';
|
||||||
import { required } from 'util/validators';
|
import { required } from 'util/validators';
|
||||||
import { useConfig } from 'contexts/Config';
|
import { useConfig } from 'contexts/Config';
|
||||||
@@ -54,11 +55,11 @@ export default function ScheduleFormFields({
|
|||||||
}
|
}
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
|
|
||||||
// const [exceptionFrequency, exceptionFrequencyMeta, exceptionFrequencyHelper] =
|
const [exceptionFrequency, exceptionFrequencyMeta, exceptionFrequencyHelper] =
|
||||||
// useField({
|
useField({
|
||||||
// name: 'exceptionFrequency',
|
name: 'exceptionFrequency',
|
||||||
// validate: required(t`Select a value for this field`),
|
validate: required(t`Select a value for this field`),
|
||||||
// });
|
});
|
||||||
|
|
||||||
const updateFrequency = (setFrequency) => (values) => {
|
const updateFrequency = (setFrequency) => (values) => {
|
||||||
setFrequency(values.sort(sortFrequencies));
|
setFrequency(values.sort(sortFrequencies));
|
||||||
@@ -152,42 +153,53 @@ export default function ScheduleFormFields({
|
|||||||
/>
|
/>
|
||||||
</FormColumnLayout>
|
</FormColumnLayout>
|
||||||
))}
|
))}
|
||||||
{/* <Title size="md" headingLevel="h4">{t`Exceptions`}</Title>
|
<Title
|
||||||
<FormGroup
|
size="md"
|
||||||
name="exceptions"
|
headingLevel="h4"
|
||||||
fieldId="exception-frequency"
|
css="margin-top: var(--pf-c-card--child--PaddingRight)"
|
||||||
helperTextInvalid={exceptionFrequencyMeta.error}
|
>{t`Exceptions`}</Title>
|
||||||
validated={
|
<FormColumnLayout stacked>
|
||||||
!exceptionFrequencyMeta.touched || !exceptionFrequencyMeta.error
|
<FormGroup
|
||||||
? 'default'
|
name="exceptions"
|
||||||
: 'error'
|
fieldId="exception-frequency"
|
||||||
}
|
helperTextInvalid={exceptionFrequencyMeta.error}
|
||||||
label={t`Add exceptions`}
|
validated={
|
||||||
>
|
!exceptionFrequencyMeta.touched || !exceptionFrequencyMeta.error
|
||||||
<FrequencySelect
|
? 'default'
|
||||||
variant={SelectVariant.checkbox}
|
: 'error'
|
||||||
onChange={exceptionFrequencyHelper.setValue}
|
}
|
||||||
value={exceptionFrequency.value}
|
label={t`Add exceptions`}
|
||||||
placeholderText={t`None`}
|
|
||||||
onBlur={exceptionFrequencyHelper.setTouched}
|
|
||||||
>
|
>
|
||||||
<SelectClearOption value="none">{t`None`}</SelectClearOption>
|
<FrequencySelect
|
||||||
<SelectOption value="minute">{t`Minute`}</SelectOption>
|
id="exception-frequency"
|
||||||
<SelectOption value="hour">{t`Hour`}</SelectOption>
|
onChange={updateFrequency(exceptionFrequencyHelper.setValue)}
|
||||||
<SelectOption value="day">{t`Day`}</SelectOption>
|
value={exceptionFrequency.value}
|
||||||
<SelectOption value="week">{t`Week`}</SelectOption>
|
placeholderText={
|
||||||
<SelectOption value="month">{t`Month`}</SelectOption>
|
exceptionFrequency.value.length
|
||||||
<SelectOption value="year">{t`Year`}</SelectOption>
|
? t`Select frequency`
|
||||||
</FrequencySelect>
|
: t`None`
|
||||||
</FormGroup>
|
}
|
||||||
|
onBlur={exceptionFrequencyHelper.setTouched}
|
||||||
|
>
|
||||||
|
<SelectClearOption value="none">{t`None`}</SelectClearOption>
|
||||||
|
<SelectOption value="minute">{t`Minute`}</SelectOption>
|
||||||
|
<SelectOption value="hour">{t`Hour`}</SelectOption>
|
||||||
|
<SelectOption value="day">{t`Day`}</SelectOption>
|
||||||
|
<SelectOption value="week">{t`Week`}</SelectOption>
|
||||||
|
<SelectOption value="month">{t`Month`}</SelectOption>
|
||||||
|
<SelectOption value="year">{t`Year`}</SelectOption>
|
||||||
|
</FrequencySelect>
|
||||||
|
</FormGroup>
|
||||||
|
</FormColumnLayout>
|
||||||
{exceptionFrequency.value.map((val) => (
|
{exceptionFrequency.value.map((val) => (
|
||||||
<FormColumnLayout key={val} stacked>
|
<FormColumnLayout key={val} stacked>
|
||||||
<FrequencyDetailSubform
|
<FrequencyDetailSubform
|
||||||
frequency={val}
|
frequency={val}
|
||||||
prefix={`exceptionOptions.${val}`}
|
prefix={`exceptionOptions.${val}`}
|
||||||
|
isException
|
||||||
/>
|
/>
|
||||||
</FormColumnLayout>
|
</FormColumnLayout>
|
||||||
))} */}
|
))}
|
||||||
</SubFormLayout>
|
</SubFormLayout>
|
||||||
) : null}
|
) : null}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -36,11 +36,19 @@ function pad(num) {
|
|||||||
return num < 10 ? `0${num}` : num;
|
return num < 10 ? `0${num}` : num;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function buildRuleObj(values) {
|
export default function buildRuleObj(values, includeStart) {
|
||||||
const ruleObj = {
|
const ruleObj = {
|
||||||
interval: values.interval,
|
interval: values.interval,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (includeStart) {
|
||||||
|
ruleObj.dtstart = buildDateTime(
|
||||||
|
values.startDate,
|
||||||
|
values.startTime,
|
||||||
|
values.timezone
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
switch (values.frequency) {
|
switch (values.frequency) {
|
||||||
case 'none':
|
case 'none':
|
||||||
ruleObj.count = 1;
|
ruleObj.count = 1;
|
||||||
@@ -91,16 +99,11 @@ export default function buildRuleObj(values) {
|
|||||||
ruleObj.count = values.occurrences;
|
ruleObj.count = values.occurrences;
|
||||||
break;
|
break;
|
||||||
case 'onDate': {
|
case 'onDate': {
|
||||||
const [endHour, endMinute] = parseTime(values.endTime);
|
ruleObj.until = buildDateTime(
|
||||||
const localEndDate = DateTime.fromISO(`${values.endDate}T000000`, {
|
values.endDate,
|
||||||
zone: values.timezone,
|
values.endTime,
|
||||||
});
|
values.timezone
|
||||||
const localEndTime = localEndDate.set({
|
);
|
||||||
hour: endHour,
|
|
||||||
minute: endMinute,
|
|
||||||
second: 0,
|
|
||||||
});
|
|
||||||
ruleObj.until = localEndTime.toJSDate();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -110,3 +113,16 @@ export default function buildRuleObj(values) {
|
|||||||
|
|
||||||
return ruleObj;
|
return ruleObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildDateTime(dateString, timeString, timezone) {
|
||||||
|
const localDate = DateTime.fromISO(`${dateString}T000000`, {
|
||||||
|
zone: timezone,
|
||||||
|
});
|
||||||
|
const [hour, minute] = parseTime(timeString);
|
||||||
|
const localTime = localDate.set({
|
||||||
|
hour,
|
||||||
|
minute,
|
||||||
|
second: 0,
|
||||||
|
});
|
||||||
|
return localTime.toJSDate();
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,24 +4,29 @@ import buildRuleObj, { buildDtStartObj } from './buildRuleObj';
|
|||||||
window.RRuleSet = RRuleSet;
|
window.RRuleSet = RRuleSet;
|
||||||
|
|
||||||
const frequencies = ['minute', 'hour', 'day', 'week', 'month', 'year'];
|
const frequencies = ['minute', 'hour', 'day', 'week', 'month', 'year'];
|
||||||
export default function buildRuleSet(values) {
|
export default function buildRuleSet(values, useUTCStart) {
|
||||||
const set = new RRuleSet();
|
const set = new RRuleSet();
|
||||||
|
|
||||||
const startRule = buildDtStartObj({
|
if (!useUTCStart) {
|
||||||
startDate: values.startDate,
|
const startRule = buildDtStartObj({
|
||||||
startTime: values.startTime,
|
|
||||||
timezone: values.timezone,
|
|
||||||
});
|
|
||||||
set.rrule(startRule);
|
|
||||||
|
|
||||||
if (values.frequency.length === 0) {
|
|
||||||
const rule = buildRuleObj({
|
|
||||||
startDate: values.startDate,
|
startDate: values.startDate,
|
||||||
startTime: values.startTime,
|
startTime: values.startTime,
|
||||||
timezone: values.timezone,
|
timezone: values.timezone,
|
||||||
frequency: 'none',
|
|
||||||
interval: 1,
|
|
||||||
});
|
});
|
||||||
|
set.rrule(startRule);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (values.frequency.length === 0) {
|
||||||
|
const rule = buildRuleObj(
|
||||||
|
{
|
||||||
|
startDate: values.startDate,
|
||||||
|
startTime: values.startTime,
|
||||||
|
timezone: values.timezone,
|
||||||
|
frequency: 'none',
|
||||||
|
interval: 1,
|
||||||
|
},
|
||||||
|
useUTCStart
|
||||||
|
);
|
||||||
set.rrule(new RRule(rule));
|
set.rrule(new RRule(rule));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,17 +34,35 @@ export default function buildRuleSet(values) {
|
|||||||
if (!values.frequency.includes(frequency)) {
|
if (!values.frequency.includes(frequency)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const rule = buildRuleObj({
|
const rule = buildRuleObj(
|
||||||
startDate: values.startDate,
|
{
|
||||||
startTime: values.startTime,
|
startDate: values.startDate,
|
||||||
timezone: values.timezone,
|
startTime: values.startTime,
|
||||||
frequency,
|
timezone: values.timezone,
|
||||||
...values.frequencyOptions[frequency],
|
frequency,
|
||||||
});
|
...values.frequencyOptions[frequency],
|
||||||
|
},
|
||||||
|
useUTCStart
|
||||||
|
);
|
||||||
set.rrule(new RRule(rule));
|
set.rrule(new RRule(rule));
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: exclusions
|
frequencies.forEach((frequency) => {
|
||||||
|
if (!values.exceptionFrequency?.includes(frequency)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const rule = buildRuleObj(
|
||||||
|
{
|
||||||
|
startDate: values.startDate,
|
||||||
|
startTime: values.startTime,
|
||||||
|
timezone: values.timezone,
|
||||||
|
frequency,
|
||||||
|
...values.exceptionOptions[frequency],
|
||||||
|
},
|
||||||
|
useUTCStart
|
||||||
|
);
|
||||||
|
set.exrule(new RRule(rule));
|
||||||
|
});
|
||||||
|
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,4 +243,257 @@ RRULE:INTERVAL=1;FREQ=MONTHLY;BYSETPOS=2;BYDAY=MO;UNTIL=20260602T170000Z`);
|
|||||||
expect(ruleSet.toString()).toEqual(`DTSTART:20220613T123000Z
|
expect(ruleSet.toString()).toEqual(`DTSTART:20220613T123000Z
|
||||||
RRULE:INTERVAL=1;COUNT=1;FREQ=MINUTELY`);
|
RRULE:INTERVAL=1;COUNT=1;FREQ=MINUTELY`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should build minutely exception', () => {
|
||||||
|
const values = {
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
frequency: ['minute'],
|
||||||
|
frequencyOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['minute'],
|
||||||
|
exceptionOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 3,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const ruleSet = buildRuleSet(values);
|
||||||
|
expect(ruleSet.toString()).toEqual(
|
||||||
|
[
|
||||||
|
'DTSTART:20220613T123000Z',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=MINUTELY',
|
||||||
|
'EXRULE:INTERVAL=3;FREQ=MINUTELY',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should build hourly exception', () => {
|
||||||
|
const values = {
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
frequency: ['minute'],
|
||||||
|
frequencyOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['hour'],
|
||||||
|
exceptionOptions: {
|
||||||
|
hour: {
|
||||||
|
interval: 3,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const ruleSet = buildRuleSet(values);
|
||||||
|
expect(ruleSet.toString()).toEqual(
|
||||||
|
[
|
||||||
|
'DTSTART:20220613T123000Z',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=MINUTELY',
|
||||||
|
'EXRULE:INTERVAL=3;FREQ=HOURLY',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should build daily exception', () => {
|
||||||
|
const values = {
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
frequency: ['minute'],
|
||||||
|
frequencyOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['day'],
|
||||||
|
exceptionOptions: {
|
||||||
|
day: {
|
||||||
|
interval: 3,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const ruleSet = buildRuleSet(values);
|
||||||
|
expect(ruleSet.toString()).toEqual(
|
||||||
|
[
|
||||||
|
'DTSTART:20220613T123000Z',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=MINUTELY',
|
||||||
|
'EXRULE:INTERVAL=3;FREQ=DAILY',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should build weekly exception', () => {
|
||||||
|
const values = {
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
frequency: ['minute'],
|
||||||
|
frequencyOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['week'],
|
||||||
|
exceptionOptions: {
|
||||||
|
week: {
|
||||||
|
interval: 3,
|
||||||
|
end: 'never',
|
||||||
|
daysOfWeek: [RRule.SU],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const ruleSet = buildRuleSet(values);
|
||||||
|
expect(ruleSet.toString()).toEqual(
|
||||||
|
[
|
||||||
|
'DTSTART:20220613T123000Z',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=MINUTELY',
|
||||||
|
'EXRULE:INTERVAL=3;FREQ=WEEKLY;BYDAY=SU',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should build monthly exception by day', () => {
|
||||||
|
const values = {
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
frequency: ['minute'],
|
||||||
|
frequencyOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['month'],
|
||||||
|
exceptionOptions: {
|
||||||
|
month: {
|
||||||
|
interval: 3,
|
||||||
|
end: 'never',
|
||||||
|
runOn: 'day',
|
||||||
|
runOnDayNumber: 15,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const ruleSet = buildRuleSet(values);
|
||||||
|
expect(ruleSet.toString()).toEqual(
|
||||||
|
[
|
||||||
|
'DTSTART:20220613T123000Z',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=MINUTELY',
|
||||||
|
'EXRULE:INTERVAL=3;FREQ=MONTHLY;BYMONTHDAY=15',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should build monthly exception by weekday', () => {
|
||||||
|
const values = {
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
frequency: ['minute'],
|
||||||
|
frequencyOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['month'],
|
||||||
|
exceptionOptions: {
|
||||||
|
month: {
|
||||||
|
interval: 3,
|
||||||
|
end: 'never',
|
||||||
|
runOn: 'the',
|
||||||
|
runOnTheOccurrence: 2,
|
||||||
|
runOnTheDay: 'monday',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const ruleSet = buildRuleSet(values);
|
||||||
|
expect(ruleSet.toString()).toEqual(
|
||||||
|
[
|
||||||
|
'DTSTART:20220613T123000Z',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=MINUTELY',
|
||||||
|
'EXRULE:INTERVAL=3;FREQ=MONTHLY;BYSETPOS=2;BYDAY=MO',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should build annual exception by day', () => {
|
||||||
|
const values = {
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
frequency: ['minute'],
|
||||||
|
frequencyOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['year'],
|
||||||
|
exceptionOptions: {
|
||||||
|
year: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
runOn: 'day',
|
||||||
|
runOnDayMonth: 3,
|
||||||
|
runOnDayNumber: 15,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const ruleSet = buildRuleSet(values);
|
||||||
|
expect(ruleSet.toString()).toEqual(
|
||||||
|
[
|
||||||
|
'DTSTART:20220613T123000Z',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=MINUTELY',
|
||||||
|
'EXRULE:INTERVAL=1;FREQ=YEARLY;BYMONTH=3;BYMONTHDAY=15',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should build annual exception by weekday', () => {
|
||||||
|
const values = {
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
frequency: ['minute'],
|
||||||
|
frequencyOptions: {
|
||||||
|
minute: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['year'],
|
||||||
|
exceptionOptions: {
|
||||||
|
year: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
runOn: 'the',
|
||||||
|
runOnTheOccurrence: 4,
|
||||||
|
runOnTheDay: 'monday',
|
||||||
|
runOnTheMonth: 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const ruleSet = buildRuleSet(values);
|
||||||
|
expect(ruleSet.toString()).toEqual(
|
||||||
|
[
|
||||||
|
'DTSTART:20220613T123000Z',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=MINUTELY',
|
||||||
|
'EXRULE:INTERVAL=1;FREQ=YEARLY;BYSETPOS=4;BYDAY=MO;BYMONTH=6',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ export default function parseRuleObj(schedule) {
|
|||||||
case 'RRULE':
|
case 'RRULE':
|
||||||
values = parseRrule(ruleString, schedule, values);
|
values = parseRrule(ruleString, schedule, values);
|
||||||
break;
|
break;
|
||||||
|
case 'EXRULE':
|
||||||
|
values = parseExRule(ruleString, schedule, values);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedRRuleError(`Unsupported rrule type: ${type}`);
|
throw new UnsupportedRRuleError(`Unsupported rrule type: ${type}`);
|
||||||
}
|
}
|
||||||
@@ -79,6 +82,54 @@ const frequencyTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function parseRrule(rruleString, schedule, values) {
|
function parseRrule(rruleString, schedule, values) {
|
||||||
|
const { frequency, options } = parseRule(
|
||||||
|
rruleString,
|
||||||
|
schedule,
|
||||||
|
values.exceptionFrequency
|
||||||
|
);
|
||||||
|
|
||||||
|
if (values.frequencyOptions[frequency]) {
|
||||||
|
throw new UnsupportedRRuleError(
|
||||||
|
'Duplicate exception frequency types not supported'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...values,
|
||||||
|
frequency: [...values.frequency, frequency].sort(sortFrequencies),
|
||||||
|
frequencyOptions: {
|
||||||
|
...values.frequencyOptions,
|
||||||
|
[frequency]: options,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseExRule(exruleString, schedule, values) {
|
||||||
|
const { frequency, options } = parseRule(
|
||||||
|
exruleString,
|
||||||
|
schedule,
|
||||||
|
values.exceptionFrequency
|
||||||
|
);
|
||||||
|
|
||||||
|
if (values.exceptionOptions[frequency]) {
|
||||||
|
throw new UnsupportedRRuleError(
|
||||||
|
'Duplicate exception frequency types not supported'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...values,
|
||||||
|
exceptionFrequency: [...values.exceptionFrequency, frequency].sort(
|
||||||
|
sortFrequencies
|
||||||
|
),
|
||||||
|
exceptionOptions: {
|
||||||
|
...values.exceptionOptions,
|
||||||
|
[frequency]: options,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseRule(ruleString, schedule, frequencies) {
|
||||||
const {
|
const {
|
||||||
origOptions: {
|
origOptions: {
|
||||||
bymonth,
|
bymonth,
|
||||||
@@ -90,7 +141,7 @@ function parseRrule(rruleString, schedule, values) {
|
|||||||
interval,
|
interval,
|
||||||
until,
|
until,
|
||||||
},
|
},
|
||||||
} = RRule.fromString(rruleString);
|
} = RRule.fromString(ruleString);
|
||||||
|
|
||||||
const now = DateTime.now();
|
const now = DateTime.now();
|
||||||
const closestQuarterHour = DateTime.fromMillis(
|
const closestQuarterHour = DateTime.fromMillis(
|
||||||
@@ -127,7 +178,7 @@ function parseRrule(rruleString, schedule, values) {
|
|||||||
throw new Error(`Unexpected rrule frequency: ${freq}`);
|
throw new Error(`Unexpected rrule frequency: ${freq}`);
|
||||||
}
|
}
|
||||||
const frequency = frequencyTypes[freq];
|
const frequency = frequencyTypes[freq];
|
||||||
if (values.frequency.includes(frequency)) {
|
if (frequencies.includes(frequency)) {
|
||||||
throw new Error(`Duplicate frequency types not supported (${frequency})`);
|
throw new Error(`Duplicate frequency types not supported (${frequency})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,17 +222,9 @@ function parseRrule(rruleString, schedule, values) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (values.frequencyOptions.frequency) {
|
|
||||||
throw new UnsupportedRRuleError('Duplicate frequency types not supported');
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...values,
|
frequency,
|
||||||
frequency: [...values.frequency, frequency].sort(sortFrequencies),
|
options,
|
||||||
frequencyOptions: {
|
|
||||||
...values.frequencyOptions,
|
|
||||||
[frequency]: options,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -241,4 +241,51 @@ RRULE:INTERVAL=1;FREQ=MONTHLY;BYSETPOS=2;BYDAY=MO;UNTIL=20260602T170000Z`;
|
|||||||
|
|
||||||
expect(parsed).toEqual(values);
|
expect(parsed).toEqual(values);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should parse exemptions', () => {
|
||||||
|
const schedule = {
|
||||||
|
rrule: [
|
||||||
|
'DTSTART;TZID=US/Eastern:20220608T123000',
|
||||||
|
'RRULE:INTERVAL=1;FREQ=WEEKLY;BYDAY=MO',
|
||||||
|
'EXRULE:INTERVAL=1;FREQ=MONTHLY;BYSETPOS=1;BYDAY=MO',
|
||||||
|
].join(' '),
|
||||||
|
dtstart: '2022-06-13T16:30:00Z',
|
||||||
|
timezone: 'US/Eastern',
|
||||||
|
until: '',
|
||||||
|
dtend: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const parsed = parseRuleObj(schedule);
|
||||||
|
|
||||||
|
expect(parsed).toEqual({
|
||||||
|
startDate: '2022-06-13',
|
||||||
|
startTime: '12:30 PM',
|
||||||
|
timezone: 'US/Eastern',
|
||||||
|
frequency: ['week'],
|
||||||
|
frequencyOptions: {
|
||||||
|
week: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
occurrences: 1,
|
||||||
|
endDate: '2022-06-02',
|
||||||
|
endTime: '1:00 PM',
|
||||||
|
daysOfWeek: [RRule.MO],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exceptionFrequency: ['month'],
|
||||||
|
exceptionOptions: {
|
||||||
|
month: {
|
||||||
|
interval: 1,
|
||||||
|
end: 'never',
|
||||||
|
endDate: '2022-06-02',
|
||||||
|
endTime: '1:00 PM',
|
||||||
|
occurrences: 1,
|
||||||
|
runOn: 'the',
|
||||||
|
runOnDayNumber: 1,
|
||||||
|
runOnTheOccurrence: 1,
|
||||||
|
runOnTheDay: 'monday',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user