Skip to content

Commit f48bc33

Browse files
authored
chore: remove cron schedule from quiet hours schedule page (#10187)
1 parent 91555c3 commit f48bc33

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

site/src/pages/UserSettingsPage/SchedulePage/ScheduleForm.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import MenuItem from "@mui/material/MenuItem";
1414
import { Stack } from "components/Stack/Stack";
1515
import { timeZones, getPreferredTimezone } from "utils/timeZones";
1616
import { Alert } from "components/Alert/Alert";
17-
import { timeToCron, quietHoursDisplay } from "utils/schedule";
17+
import { timeToCron, quietHoursDisplay, validTime } from "utils/schedule";
1818

1919
export interface ScheduleFormValues {
2020
time: string;
@@ -25,7 +25,7 @@ const validationSchema = Yup.object({
2525
time: Yup.string()
2626
.ensure()
2727
.test("is-time-string", "Time must be in HH:mm format.", (value) => {
28-
if (!/^[0-9][0-9]:[0-9][0-9]$/.test(value)) {
28+
if (!validTime(value)) {
2929
return false;
3030
}
3131
const parts = value.split(":");
@@ -116,13 +116,6 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
116116
</TextField>
117117
</Stack>
118118

119-
<TextField
120-
disabled
121-
fullWidth
122-
label="Cron schedule"
123-
value={timeToCron(form.values.time, form.values.timezone)}
124-
/>
125-
126119
<TextField
127120
disabled
128121
fullWidth

site/src/pages/UserSettingsPage/SchedulePage/SchedulePage.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,8 @@ describe("SchedulePage", () => {
8686
),
8787
);
8888

89-
const expectedCronSchedule = `CRON_TZ=${test.timezone} ${test.minute} ${test.hour} * * *`;
9089
renderWithAuth(<SchedulePage />);
9190
await fillForm(test);
92-
const cron = screen.getByLabelText("Cron schedule");
93-
expect(cron.getAttribute("value")).toEqual(expectedCronSchedule);
94-
9591
await submitForm();
9692
const successMessage = await screen.findByText(
9793
"Schedule updated successfully",

site/src/utils/schedule.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@ export const getMaxDeadlineChange = (
156156
extremeDeadline: dayjs.Dayjs,
157157
): number => Math.abs(deadline.diff(extremeDeadline, "hours"));
158158

159+
export const validTime = (time: string): boolean => {
160+
return /^[0-9][0-9]:[0-9][0-9]$/.test(time);
161+
};
162+
159163
export const timeToCron = (time: string, tz?: string) => {
164+
if (!validTime(time)) {
165+
throw new Error(`Invalid time: ${time}`);
166+
}
160167
const [HH, mm] = time.split(":");
161168
let prefix = "";
162169
if (tz) {
@@ -170,6 +177,10 @@ export const quietHoursDisplay = (
170177
tz: string,
171178
now: Date | undefined,
172179
): string => {
180+
if (!validTime(time)) {
181+
return "Invalid time";
182+
}
183+
173184
// The cron-parser package doesn't accept a timezone in the cron string, but
174185
// accepts it as an option.
175186
const cron = timeToCron(time);

0 commit comments

Comments
 (0)