chore: remove cron schedule from quiet hours schedule page (#10187)

This commit is contained in:
Dean Sheather
2023-10-10 19:55:28 +00:00
committed by GitHub
parent 91555c3a85
commit f48bc33e00
3 changed files with 13 additions and 13 deletions
@@ -14,7 +14,7 @@ import MenuItem from "@mui/material/MenuItem";
import { Stack } from "components/Stack/Stack";
import { timeZones, getPreferredTimezone } from "utils/timeZones";
import { Alert } from "components/Alert/Alert";
import { timeToCron, quietHoursDisplay } from "utils/schedule";
import { timeToCron, quietHoursDisplay, validTime } from "utils/schedule";
export interface ScheduleFormValues {
time: string;
@@ -25,7 +25,7 @@ const validationSchema = Yup.object({
time: Yup.string()
.ensure()
.test("is-time-string", "Time must be in HH:mm format.", (value) => {
if (!/^[0-9][0-9]:[0-9][0-9]$/.test(value)) {
if (!validTime(value)) {
return false;
}
const parts = value.split(":");
@@ -116,13 +116,6 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
</TextField>
</Stack>
<TextField
disabled
fullWidth
label="Cron schedule"
value={timeToCron(form.values.time, form.values.timezone)}
/>
<TextField
disabled
fullWidth
@@ -86,12 +86,8 @@ describe("SchedulePage", () => {
),
);
const expectedCronSchedule = `CRON_TZ=${test.timezone} ${test.minute} ${test.hour} * * *`;
renderWithAuth(<SchedulePage />);
await fillForm(test);
const cron = screen.getByLabelText("Cron schedule");
expect(cron.getAttribute("value")).toEqual(expectedCronSchedule);
await submitForm();
const successMessage = await screen.findByText(
"Schedule updated successfully",
+11
View File
@@ -156,7 +156,14 @@ export const getMaxDeadlineChange = (
extremeDeadline: dayjs.Dayjs,
): number => Math.abs(deadline.diff(extremeDeadline, "hours"));
export const validTime = (time: string): boolean => {
return /^[0-9][0-9]:[0-9][0-9]$/.test(time);
};
export const timeToCron = (time: string, tz?: string) => {
if (!validTime(time)) {
throw new Error(`Invalid time: ${time}`);
}
const [HH, mm] = time.split(":");
let prefix = "";
if (tz) {
@@ -170,6 +177,10 @@ export const quietHoursDisplay = (
tz: string,
now: Date | undefined,
): string => {
if (!validTime(time)) {
return "Invalid time";
}
// The cron-parser package doesn't accept a timezone in the cron string, but
// accepts it as an option.
const cron = timeToCron(time);