Skip to content

Commit c2655e8

Browse files
committed
fix(app-shell): clearing the flow designer's cron drops a typed schedule block left with no cadence
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 03533d2 commit c2655e8

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): clearing a start node's Cron schedule in the flow designer no longer leaves a typed schedule block with no cadence
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Clearing the Cron schedule box on a typed `config.schedule` such as `{ type: 'cron', expression, timezone }` used to store `{ type: 'cron', timezone }`. The engine binds nothing from that block, so a schedule flow silently never ran and a time-relative sweep did not fall back to its daily default the way the field's help says. The published `ScheduleSchema` refuses the same block. The designer now removes `config.schedule` entirely in that case, as it already did for an untyped `{ expression }`. Typing a cron over a typed block still keeps its `type` and `timezone`.

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.scheduleCadence-12779.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ describe('a typed cron stores a descriptor the engine resolves to it (objectui#1
238238
});
239239
});
240240

241+
describe('clearing the Cron schedule box drops a typed block it would leave with no cadence (objectstack#31383)', () => {
242+
const typed: Array<[string, Record<string, unknown>]> = [
243+
['a typed cron', { type: 'cron', expression: '0 7 * * *' }],
244+
['a typed cron with a timezone', { type: 'cron', expression: '0 7 * * *', timezone: 'Asia/Shanghai' }],
245+
];
246+
for (const [name, schedule] of typed) {
247+
it(`clearing ${name} stores no schedule`, () => {
248+
const { latest, patches } = mount(scheduleFlow({ schedule, objectName: 'todo_task' }));
249+
fireEvent.change(controlOf('Cron schedule'), { target: { value: '' } });
250+
expect(patches.length).toBeGreaterThan(0);
251+
const config = startConfig(latest());
252+
expect('schedule' in config).toBe(false);
253+
expect(config.objectName).toBe('todo_task');
254+
expect(controlOf('Cron schedule').value).toBe('');
255+
});
256+
}
257+
258+
it('CONTROL: clearing an untyped { expression } stores no schedule, as before', () => {
259+
const { latest } = mount(scheduleFlow({ schedule: { expression: '0 6 * * *' }, objectName: 'todo_task' }));
260+
fireEvent.change(controlOf('Cron schedule'), { target: { value: '' } });
261+
expect('schedule' in startConfig(latest())).toBe(false);
262+
});
263+
});
264+
241265
describe('CONTROLS: the forms the field already read behave as before (objectui#12779)', () => {
242266
it('a typed cron with a timezone reads and writes with its type and timezone kept', () => {
243267
const { latest } = mount(scheduleFlow({ schedule: { type: 'cron', expression: '0 7 * * *', timezone: 'Asia/Shanghai' } }));

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/flow-node-config.scheduleCadence-12779.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,41 @@ describe('a typed cron stores a descriptor that resolves to it (objectui#12779)'
171171
expect(scheduleWithExpression({ cron: '0 4 * * *' }, '')).toBeUndefined();
172172
expect(scheduleWithExpression({ expression: '0 4 * * *' }, undefined)).toBeUndefined();
173173
expect(scheduleWithExpression({ type: 'interval', intervalMs: 60000 }, undefined)).toBeUndefined();
174-
expect(scheduleWithExpression({ type: 'cron', expression: '0 7 * * *', timezone: 'UTC' }, '')).toEqual({
174+
});
175+
});
176+
177+
describe('clearing never leaves a typed schedule block with no cadence (objectstack#31383)', () => {
178+
// A typed block is judged by the published `ScheduleSchema`, which refuses a
179+
// `type: 'cron'` with no `expression`; the engine binds nothing from it.
180+
const typedCleared: Array<[string, Record<string, unknown>, unknown]> = [
181+
["a typed cron's expression", { type: 'cron', expression: '0 7 * * *' }, ''],
182+
["a typed cron's expression beside a timezone", { type: 'cron', expression: '0 7 * * *', timezone: 'UTC' }, ''],
183+
['a typed cron cleared to undefined', { type: 'cron', expression: '0 7 * * *', timezone: 'Asia/Shanghai' }, undefined],
184+
["a typed { cron }'s value", { type: 'cron', cron: '0 5 * * *', timezone: 'UTC' }, ''],
185+
['a typed cron that already carried no cadence', { type: 'cron', timezone: 'UTC' }, ''],
186+
['an interval type that carried only an expression', { type: 'interval', expression: '0 7 * * *' }, ''],
187+
['an unknown type beside an expression', { type: 'weekly', expression: '0 8 * * *', timezone: 'UTC' }, ''],
188+
];
189+
for (const [name, schedule, value] of typedCleared) {
190+
it(`clearing ${name} removes the whole schedule`, () => {
191+
expect(normalizeScheduleCadence(scheduleWithExpression(schedule, value))).toBeNull();
192+
expect(scheduleWithExpression(schedule, value)).toBeUndefined();
193+
});
194+
}
195+
196+
it('CONTROL: clearing an untyped { expression } still removes the whole schedule', () => {
197+
expect(scheduleWithExpression({ expression: '0 4 * * *' }, '')).toBeUndefined();
198+
});
199+
200+
it('CONTROL: a cron typed over a typed block keeps its type and the other keys', () => {
201+
expect(scheduleWithExpression({ type: 'cron', expression: '0 7 * * *', timezone: 'UTC' }, '0 9 * * *')).toEqual({
202+
type: 'cron',
203+
expression: '0 9 * * *',
204+
timezone: 'UTC',
205+
});
206+
expect(scheduleWithExpression({ type: 'cron', timezone: 'UTC' }, '0 9 * * *')).toEqual({
175207
type: 'cron',
208+
expression: '0 9 * * *',
176209
timezone: 'UTC',
177210
});
178211
});

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/flow-node-config.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ const FLOW_NODE_CONFIG: Record<string, FlowConfigField[]> = {
526526
// it is (`readOnlyScheduleCadence`): the designer edits cron cadences only.
527527
// A commit rewrites the whole block through `scheduleWithExpression`, which
528528
// keeps a bare string a string and an object's `type` / `timezone`, so the
529-
// stored cadence resolves to the cron the field shows.
529+
// stored cadence resolves to the cron the field shows; clearing it never
530+
// leaves a typed block with no cadence (objectstack#31383).
530531
//
531532
// objectui#12672 — gated on the flow's RESOLVED kind as well as on the
532533
// select: a `type: 'schedule'` flow, or a start node carrying
@@ -1705,7 +1706,13 @@ const NON_CRON_CADENCE_KEYS = ['intervalMs', 'every', 'at'] as const;
17051706
* only met on a descriptor the engine binds nothing from, since a live
17061707
* interval or once cadence offers no cron edit at all.
17071708
* - Clearing removes `expression` and `cron`, or the whole schedule when it is
1708-
* a string, an interval or once cadence, or an object left empty.
1709+
* a string, an interval or once cadence, an object left empty, or a typed
1710+
* block left with no cadence (objectstack#31383). A typed block is judged
1711+
* by the published `ScheduleSchema`, which refuses `{ type: 'cron' }` with no
1712+
* `expression` (a `timezone` beside it does not make it a cadence); the
1713+
* engine binds nothing from it either. So a cleared `{ type: 'cron',
1714+
* expression, timezone }` leaves no schedule, as an untyped `{ expression }`
1715+
* always did.
17091716
*/
17101717
export function scheduleWithExpression(schedule: unknown, value: unknown): unknown {
17111718
const expression = typeof value === 'string' ? value : '';
@@ -1717,6 +1724,7 @@ export function scheduleWithExpression(schedule: unknown, value: unknown): unkno
17171724
const cadence = normalizeScheduleCadence(schedule);
17181725
if (cadence && cadence.type !== 'cron') return undefined;
17191726
delete next.expression;
1727+
if (next.type !== undefined && normalizeScheduleCadence(next) === null) return undefined;
17201728
} else {
17211729
if (typeof next.type === 'string' && next.type !== 'cron') delete next.type;
17221730
for (const key of NON_CRON_CADENCE_KEYS) delete next[key];

0 commit comments

Comments
 (0)