diff --git a/frontend/src/components/procedural-editor/MaintenanceScheduleSection.tsx b/frontend/src/components/procedural-editor/MaintenanceScheduleSection.tsx index d41fdbcb..0e513ac0 100644 --- a/frontend/src/components/procedural-editor/MaintenanceScheduleSection.tsx +++ b/frontend/src/components/procedural-editor/MaintenanceScheduleSection.tsx @@ -76,7 +76,7 @@ export function MaintenanceScheduleSection({ treeId, onScheduleLoaded }: Mainten } } load() - }, [treeId]) + }, [treeId, onScheduleLoaded]) const hydrateFromSchedule = (s: MaintenanceSchedule) => { const parts = s.cron_expression.split(' ') @@ -239,26 +239,3 @@ export function MaintenanceScheduleSection({ treeId, onScheduleLoaded }: Mainten ) } - -export function getScheduleSummary(schedule: MaintenanceSchedule | null, targetList?: TargetList | null): string { - if (!schedule) return 'No schedule configured' - - const parts = schedule.cron_expression.split(' ') - const min = parts[0] ?? '0' - const hour = parts[1] ?? '0' - const timeStr = `${hour.padStart(2, '0')}:${min.padStart(2, '0')}` - - const dayOfWeek = parts[4] - const dayOfMonth = parts[2] - let freqStr = 'Custom' - if (dayOfMonth === '1') { - freqStr = 'Monthly (1st)' - } else if (dayOfMonth === '*' && parts[3] === '*') { - if (dayOfWeek === '*') freqStr = 'Daily' - else if (dayOfWeek === '1') freqStr = 'Every Monday' - else if (dayOfWeek === '5') freqStr = 'Every Friday' - } - - const targetStr = targetList ? ` \u00b7 ${targetList.targets.length} target${targetList.targets.length !== 1 ? 's' : ''}` : '' - return `${freqStr} at ${timeStr} ${schedule.timezone}${targetStr}` -} diff --git a/frontend/src/components/procedural-editor/scheduleUtils.ts b/frontend/src/components/procedural-editor/scheduleUtils.ts new file mode 100644 index 00000000..501c99b2 --- /dev/null +++ b/frontend/src/components/procedural-editor/scheduleUtils.ts @@ -0,0 +1,24 @@ +import type { MaintenanceSchedule, TargetList } from '@/types' + +export function getScheduleSummary(schedule: MaintenanceSchedule | null, targetList?: TargetList | null): string { + if (!schedule) return 'No schedule configured' + + const parts = schedule.cron_expression.split(' ') + const min = parts[0] ?? '0' + const hour = parts[1] ?? '0' + const timeStr = `${hour.padStart(2, '0')}:${min.padStart(2, '0')}` + + const dayOfWeek = parts[4] + const dayOfMonth = parts[2] + let freqStr = 'Custom' + if (dayOfMonth === '1') { + freqStr = 'Monthly (1st)' + } else if (dayOfMonth === '*' && parts[3] === '*') { + if (dayOfWeek === '*') freqStr = 'Daily' + else if (dayOfWeek === '1') freqStr = 'Every Monday' + else if (dayOfWeek === '5') freqStr = 'Every Friday' + } + + const targetStr = targetList ? ` \u00b7 ${targetList.targets.length} target${targetList.targets.length !== 1 ? 's' : ''}` : '' + return `${freqStr} at ${timeStr} ${schedule.timezone}${targetStr}` +} diff --git a/frontend/src/pages/ProceduralEditorPage.tsx b/frontend/src/pages/ProceduralEditorPage.tsx index f17b4d8e..2bf6c9d2 100644 --- a/frontend/src/pages/ProceduralEditorPage.tsx +++ b/frontend/src/pages/ProceduralEditorPage.tsx @@ -5,7 +5,8 @@ import { treesApi } from '@/api/trees' import { useProceduralEditorStore } from '@/store/proceduralEditorStore' import { CollapsibleEditorSection } from '@/components/procedural-editor/CollapsibleEditorSection' import { IntakeFormBuilder } from '@/components/procedural-editor/IntakeFormBuilder' -import { MaintenanceScheduleSection, getScheduleSummary } from '@/components/procedural-editor/MaintenanceScheduleSection' +import { MaintenanceScheduleSection } from '@/components/procedural-editor/MaintenanceScheduleSection' +import { getScheduleSummary } from '@/components/procedural-editor/scheduleUtils' import { StepList } from '@/components/procedural-editor/StepList' import { TagInput } from '@/components/common/TagInput' import { toast } from '@/lib/toast'