import { SegmentedControl } from '@/components/ui/segmented-control'; import { Label } from '@/components/ui/label'; import { Input } from '@/components/ui/input'; import { DatePicker } from '@/components/ui/date-picker'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { getCronDescription, type SimpleFrequency, type SimpleSchedule } from '@/lib/scheduling'; import { cn } from '@/lib/utils'; const FREQUENCY_OPTIONS: { value: SimpleFrequency; label: string }[] = [ { value: 'once', label: 'Once' }, { value: 'hourly', label: 'Hourly' }, { value: 'daily', label: 'Daily' }, { value: 'weekly', label: 'Weekly' }, { value: 'monthly', label: 'Monthly' }, ]; const WEEKDAYS: { value: number; short: string; full: string }[] = [ { value: 0, short: 'Su', full: 'Sunday' }, { value: 1, short: 'Mo', full: 'Monday' }, { value: 2, short: 'Tu', full: 'Tuesday' }, { value: 3, short: 'We', full: 'Wednesday' }, { value: 4, short: 'Th', full: 'Thursday' }, { value: 5, short: 'Fr', full: 'Friday' }, { value: 6, short: 'Sa', full: 'Saturday' }, ]; const pad2 = (n: number) => String(n).padStart(2, '0'); const numInputValue = (n: number) => (Number.isNaN(n) ? '' : n); /** A compact 0..count-1 dropdown rendered with the design-system Select. */ function UnitSelect({ value, count, ariaLabel, onValueChange }: { value: number; count: number; ariaLabel: string; onValueChange: (n: number) => void; }) { return ( ); } interface ScheduleSimplePanelProps { value: SimpleSchedule; onChange: (next: SimpleSchedule) => void; derivedCron: string; error: string | null; } export function ScheduleSimplePanel({ value, onChange, derivedCron, error }: ScheduleSimplePanelProps) { const patch = (partial: Partial) => onChange({ ...value, ...partial }); const toggleWeekday = (day: number, checked: boolean) => { patch({ weekdays: checked ? [...value.weekdays, day] : value.weekdays.filter(d => d !== day) }); }; const timeControl = (
patch({ hour })} /> : patch({ minute })} />
); return (
value={value.frequency} options={FREQUENCY_OPTIONS} onChange={freq => patch({ frequency: freq })} ariaLabel="Schedule frequency" fullWidth />
{value.frequency === 'once' && (
patch({ date: date ?? null })} />
)} {value.frequency === 'weekly' && (
{WEEKDAYS.map(d => { const active = value.weekdays.includes(d.value); return ( ); })}
)} {value.frequency === 'monthly' && (
patch({ dayOfMonth: Number.parseInt(e.target.value, 10) })} className="w-24" />
)} {value.frequency === 'hourly' ? (
patch({ minute })} /> past every hour
) : ( timeControl )}
{error ? (

{error}

) : (

{getCronDescription(derivedCron)} ยท {derivedCron}

)}

Runs in the node's local timezone.

); }