From aadaca3d1880bc7ded1f799b349480f09aab2400 Mon Sep 17 00:00:00 2001 From: Benjamin Mitchell <352241654+BenjaminMitchell-D0FB@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:08:58 -0800 Subject: [PATCH] fix(settings): preserve notification intervals in Custom mode (#7082) Switching a Telegram or Discord schedule to Custom seeded the editor with a crontab translation of the interval. A cron step repeats within its field, so @every 45m became 0 */45 * * * *, which fires at :00 and :45 of each hour: alternating 45- and 15-minute gaps. The Custom draft now starts from the original @every descriptor; the calendar presets still seed their six-field expression. Fixes #7081 --- .../src/pages/settings/NotifyTimeField.tsx | 15 ++++--------- frontend/src/test/notify-time-field.test.tsx | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 frontend/src/test/notify-time-field.test.tsx diff --git a/frontend/src/pages/settings/NotifyTimeField.tsx b/frontend/src/pages/settings/NotifyTimeField.tsx index b073a9181..268bf03cc 100644 --- a/frontend/src/pages/settings/NotifyTimeField.tsx +++ b/frontend/src/pages/settings/NotifyTimeField.tsx @@ -41,9 +41,8 @@ export function composeRunTime(s: RunTime): string { return s.mode; } -// Custom is seeded with the six-field ("second minute hour day month weekday") -// equivalent of the current selection, so the admin edits a real expression. -export function toCrontab(s: RunTime): string { +// Keep elapsed-time intervals as descriptors. Crontab steps reset within their field. +function initialCustomSchedule(s: RunTime): string { switch (s.mode) { case '@hourly': return '0 0 * * * *'; @@ -53,14 +52,8 @@ export function toCrontab(s: RunTime): string { return '0 0 0 * * 0'; case '@monthly': return '0 0 0 1 * *'; - case 'every': { - const n = Math.max(1, s.num || 1); - if (s.unit === 's') return `*/${n} * * * * *`; - if (s.unit === 'm') return `0 */${n} * * * *`; - return `0 0 */${n} * * *`; - } default: - return s.custom; + return composeRunTime(s); } } @@ -84,7 +77,7 @@ export function NotifyTimeField({ function onModeChange(mode: Mode) { if (mode === 'custom' && !state.custom.trim()) { - update({ mode, custom: toCrontab(state) }); + update({ mode, custom: initialCustomSchedule(state) }); } else { update({ mode }); } diff --git a/frontend/src/test/notify-time-field.test.tsx b/frontend/src/test/notify-time-field.test.tsx new file mode 100644 index 000000000..774a75d69 --- /dev/null +++ b/frontend/src/test/notify-time-field.test.tsx @@ -0,0 +1,21 @@ +import { fireEvent, render, screen } from '@testing-library/react'; +import { expect, it, vi } from 'vitest'; + +import { NotifyTimeField } from '@/pages/settings/NotifyTimeField'; + +it.each([ + ['@every 45m', '@every 45m'], + ['@hourly', '0 0 * * * *'], +])('preserves the cadence of %s when switching to Custom', (schedule, expected) => { + const onChange = vi.fn(); + render(); + + fireEvent.mouseDown(screen.getByRole('combobox', { name: 'Schedule' })); + fireEvent.click(screen.getByText('Custom (crontab)')); + + expect(screen.getByRole('textbox', { name: 'Custom (crontab)' })).toHaveProperty( + 'value', + expected, + ); + expect(onChange).toHaveBeenLastCalledWith(expected); +});