mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-24 19:44:49 +03:00
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
This commit is contained in:
committed by
GitHub
parent
ca5d578416
commit
aadaca3d18
@@ -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 });
|
||||
}
|
||||
|
||||
@@ -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(<NotifyTimeField value={schedule} onChange={onChange} ariaLabel="Schedule" />);
|
||||
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user