Skip to content

Commit

Permalink
fix: hide cron options for hours/minutes/days of week for infrequent …
Browse files Browse the repository at this point in the history
…schedules
  • Loading branch information
garethgeorge committed Aug 15, 2024
1 parent 5374273 commit 7c091e0
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions webui/src/components/ScheduleFormItem.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import {
Checkbox,
Col,
Form,
InputNumber,
Radio,
Row,
Segmented,
Tooltip,
} from "antd";
import { NamePath } from "antd/es/form/interface";
import { Checkbox, Form, InputNumber, Radio, Row, Tooltip } from "antd";
import React from "react";
import Cron from "react-js-cron";
import Cron, { CronType, PeriodType } from "react-js-cron";

interface ScheduleDefaults {
maxFrequencyDays: number;
maxFrequencyHours: number;
cron: string;
cronPeriods?: PeriodType[];
cronDropdowns?: CronType[];
}

export const ScheduleDefaultsInfrequent: ScheduleDefaults = {
maxFrequencyDays: 30,
maxFrequencyHours: 30 * 24,
// midnight on the first day of the month
cron: "0 0 1 * *",
cronDropdowns: ["period", "months", "month-days"],
cronPeriods: ["month"],
};

export const ScheduleDefaultsDaily: ScheduleDefaults = {
maxFrequencyDays: 1,
maxFrequencyHours: 24,
// midnight every day
cron: "0 0 * * *",
cronDropdowns: [
"period",
"months",
"month-days",
"hours",
"minutes",
"week-days",
],
cronPeriods: ["day", "hour", "month", "week"],
};

export const ScheduleFormItem = ({
Expand Down Expand Up @@ -79,15 +82,8 @@ export const ScheduleFormItem = ({
setValue={(val: string) => {
form.setFieldValue(name.concat(["cron"]), val);
}}
allowedDropdowns={[
"period",
"months",
"month-days",
"hours",
"minutes",
"week-days",
]}
allowedPeriods={["day", "hour", "month", "week"]}
allowedDropdowns={defaults.cronDropdowns}
allowedPeriods={defaults.cronPeriods}
clearButton={false}
/>
</Form.Item>
Expand Down

0 comments on commit 7c091e0

Please sign in to comment.