MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / ScheduleInput

Function ScheduleInput

frontend/src/components/forms/ScheduleInput.jsx:48–229  ·  view source on GitHub ↗
({
  // Schedule type
  scheduleType = 'interval',
  onScheduleTypeChange,

  // Cron
  cronValue = '',
  onCronChange,

  // Default interval input (used when children not provided)
  intervalValue = 0,
  onIntervalChange,
  intervalLabel = 'Refresh Interval (hours)',
  intervalDescription = 'How often to refresh (0 to disable)',
  min = 0,

  // Custom simple-mode content (replaces the default NumberInput)
  children,

  // Link text for toggling
  switchToCronLabel = 'Use cron schedule',
  switchToIntervalLabel = 'Use interval schedule',

  disabled = false,
})

Source from the content-addressed store, hash-verified

46import CronBuilder from './CronBuilder';
47
48export default function ScheduleInput({
49 // Schedule type
50 scheduleType = 'interval',
51 onScheduleTypeChange,
52
53 // Cron
54 cronValue = '',
55 onCronChange,
56
57 // Default interval input (used when children not provided)
58 intervalValue = 0,
59 onIntervalChange,
60 intervalLabel = 'Refresh Interval (hours)',
61 intervalDescription = 'How often to refresh (0 to disable)',
62 min = 0,
63
64 // Custom simple-mode content (replaces the default NumberInput)
65 children,
66
67 // Link text for toggling
68 switchToCronLabel = 'Use cron schedule',
69 switchToIntervalLabel = 'Use interval schedule',
70
71 disabled = false,
72}) {
73 const [cronError, setCronError] = useState(null);
74 const [builderOpened, setBuilderOpened] = useState(false);
75
76 // Validate cron whenever it changes
77 useEffect(() => {
78 if (scheduleType === 'cron' && cronValue) {
79 const v = validateCronExpression(cronValue);
80 setCronError(v.valid ? null : v.error);
81 } else {
82 setCronError(null);
83 }
84 }, [scheduleType, cronValue]);
85
86 const switchToCron = (e) => {
87 e.preventDefault();
88 onScheduleTypeChange('cron');
89 };
90
91 const switchToInterval = (e) => {
92 e.preventDefault();
93 onScheduleTypeChange('interval');
94 onCronChange('');
95 setCronError(null);
96 };
97
98 const handleCronChange = (val) => {
99 onCronChange(val);
100 if (val) {
101 const v = validateCronExpression(val);
102 setCronError(v.valid ? null : v.error);
103 } else {
104 setCronError(null);
105 }

Callers

nothing calls this directly

Calls 2

validateCronExpressionFunction · 0.90
handleCronChangeFunction · 0.85

Tested by

no test coverage detected