Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions site/src/pages/UserSettingsPage/SchedulePage/ScheduleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(":");
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions site/src/utils/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down