Skip to content

Commit f2de012

Browse files
tcraptsclaude
andcommitted
fix(mobile): apply webhook filter and environment edits to the current draft
Webhook filter rows and the environment picker still built their update from rendered props, so a second edit before React committed dropped the first. Both now update the current editor state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ba3eff4 commit f2de012

2 files changed

Lines changed: 50 additions & 24 deletions

File tree

‎apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ vi.mock("../../lib/modelOptions", () => ({
9797
resolveDefaultableModelSelection: () => null,
9898
resolveNewTaskModelSelection: () => null,
9999
}));
100-
vi.mock("../../state/session", () => ({ readEnvironmentScope: () => true }));
100+
vi.mock("../../state/session", () => ({
101+
readEnvironmentScope: () => true,
102+
usePreparedConnection: () => ({ _tag: "None" }),
103+
}));
101104
vi.mock("../../state/server", () => ({
102105
serverEnvironment: {
103106
scheduledTasksLive: () => ({}),
@@ -213,4 +216,14 @@ describe("scheduled task batched edits", () => {
213216
}),
214217
});
215218
});
219+
it("keeps every webhook filter added before React commits", () => {
220+
act(() => button("On webhook").click());
221+
act(() => {
222+
button("Add filter").click();
223+
button("Add filter").click();
224+
});
225+
expect(
226+
appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current?.draft.schedule.filters,
227+
).toHaveLength(2);
228+
});
216229
});

‎apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx‎

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,13 @@ function SelectRow(props: {
243243
function WebhookFilterRows(props: {
244244
readonly filters: ReadonlyArray<WebhookFilterDraft>;
245245
readonly disabled: boolean;
246-
readonly onChange: (filters: ReadonlyArray<WebhookFilterDraft>) => void;
246+
readonly onChange: (
247+
update: (filters: ReadonlyArray<WebhookFilterDraft>) => ReadonlyArray<WebhookFilterDraft>,
248+
) => void;
247249
}) {
248-
const update = (index: number, patch: Partial<WebhookFilterDraft>) =>
249-
props.onChange(
250-
props.filters.map((filter, at) => (at === index ? { ...filter, ...patch } : filter)),
250+
const update = (id: WebhookFilterDraft["id"], patch: Partial<WebhookFilterDraft>) =>
251+
props.onChange((filters) =>
252+
filters.map((filter) => (filter.id === id ? { ...filter, ...patch } : filter)),
251253
);
252254
return (
253255
<>
@@ -260,7 +262,9 @@ function WebhookFilterRows(props: {
260262
accessibilityLabel={`Remove filter ${index + 1}`}
261263
disabled={props.disabled}
262264
hitSlop={8}
263-
onPress={() => props.onChange(removeWebhookFilterDraft(props.filters, filter.id))}
265+
onPress={() =>
266+
props.onChange((filters) => removeWebhookFilterDraft(filters, filter.id))
267+
}
264268
className="active:opacity-70"
265269
>
266270
<SymbolView name="trash" size={16} tintColorClassName="accent-danger-foreground" />
@@ -271,7 +275,7 @@ function WebhookFilterRows(props: {
271275
value={filter.path}
272276
placeholder="body.action"
273277
disabled={props.disabled}
274-
onChange={(path) => update(index, { path })}
278+
onChange={(path) => update(filter.id, { path })}
275279
/>
276280
<SelectRow
277281
label="Test"
@@ -283,7 +287,7 @@ function WebhookFilterRows(props: {
283287
}))}
284288
onSelect={(id) => {
285289
const known = WEBHOOK_FILTER_OPS.find((option) => option.op === id);
286-
if (known) update(index, { op: known.op });
290+
if (known) update(filter.id, { op: known.op });
287291
}}
288292
/>
289293
{filter.op === "exists" ? null : (
@@ -292,7 +296,7 @@ function WebhookFilterRows(props: {
292296
value={filter.value}
293297
placeholder={filter.op === "in" ? "opened, reopened" : "opened"}
294298
disabled={props.disabled}
295-
onChange={(value) => update(index, { value })}
299+
onChange={(value) => update(filter.id, { value })}
296300
/>
297301
)}
298302
</View>
@@ -301,7 +305,13 @@ function WebhookFilterRows(props: {
301305
<Pressable
302306
accessibilityRole="button"
303307
disabled={props.disabled}
304-
onPress={() => props.onChange([...props.filters, emptyWebhookFilterDraft()])}
308+
onPress={() =>
309+
props.onChange((filters) =>
310+
filters.length < MAX_WEBHOOK_FILTERS
311+
? [...filters, emptyWebhookFilterDraft()]
312+
: filters,
313+
)
314+
}
305315
className="min-h-14 flex-row items-center gap-3 border-t border-border-subtle px-4 py-3 active:opacity-70"
306316
>
307317
<Text textRole="body" className="min-w-0 flex-1 text-foreground">
@@ -613,18 +623,21 @@ function SettingsScheduledTaskEditorScreen({ title }: { readonly title: string }
613623
if (navigation.isFocused()) navigation.goBack();
614624
}}
615625
onChangeEnvironment={(target) => {
616-
if (target.environmentId === editor.environmentId) return;
617-
setEditor({
618-
environmentId: target.environmentId,
619-
environmentLabel: target.label,
620-
draft: {
621-
...draftForEnvironment(target.environmentId),
622-
title: editor.draft.title,
623-
prompt: editor.draft.prompt,
624-
schedule: editor.draft.schedule,
625-
enabled: editor.draft.enabled,
626-
},
627-
});
626+
setEditor((current) =>
627+
!current || target.environmentId === current.environmentId
628+
? current
629+
: {
630+
environmentId: target.environmentId,
631+
environmentLabel: target.label,
632+
draft: {
633+
...draftForEnvironment(target.environmentId),
634+
title: current.draft.title,
635+
prompt: current.draft.prompt,
636+
schedule: current.draft.schedule,
637+
enabled: current.draft.enabled,
638+
},
639+
},
640+
);
628641
}}
629642
/>
630643
) : (
@@ -1092,10 +1105,10 @@ function TaskForm({
10921105
<WebhookFilterRows
10931106
filters={draft.schedule.filters}
10941107
disabled={saving}
1095-
onChange={(filters) =>
1108+
onChange={(update) =>
10961109
setDraft((current) => ({
10971110
...current,
1098-
schedule: { ...current.schedule, filters },
1111+
schedule: { ...current.schedule, filters: update(current.schedule.filters) },
10991112
}))
11001113
}
11011114
/>

0 commit comments

Comments
 (0)