diff --git a/packages/tui/src/context/data.tsx b/packages/tui/src/context/data.tsx index a8b91548c56..a54b4af3104 100644 --- a/packages/tui/src/context/data.tsx +++ b/packages/tui/src/context/data.tsx @@ -69,12 +69,6 @@ function locationKey(location: LocationRef) { return JSON.stringify([location.directory, location.workspaceID]) } -function matchesGlobalForm(form: FormInfo, id: string, location?: LocationRef) { - if (form.id !== id) return false - if (!form.location || !location) return true - return locationKey(form.location) === locationKey(location) -} - function locationQuery(ref?: LocationRef) { return ref ? { directory: ref.directory, workspace: ref.workspaceID } : undefined } @@ -595,14 +589,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({ ) break case "form.created": - if ( - store.session.form[event.data.form.sessionID]?.some((form) => - event.data.form.sessionID === "global" - ? matchesGlobalForm(form, event.data.form.id, event.location) - : form.id === event.data.form.id, - ) - ) - break + if (store.session.form[event.data.form.sessionID]?.some((form) => form.id === event.data.form.id)) break setStore("session", "form", event.data.form.sessionID, [ ...(store.session.form[event.data.form.sessionID] ?? []), mutable({ ...event.data.form, location: event.location }), @@ -614,11 +601,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({ "session", "form", event.data.sessionID, - (store.session.form[event.data.sessionID] ?? []).filter((form) => - event.data.sessionID === "global" - ? !matchesGlobalForm(form, event.data.id, event.location) - : form.id !== event.data.id, - ), + (store.session.form[event.data.sessionID] ?? []).filter((form) => form.id !== event.data.id), ) break case "shell.created": @@ -754,7 +737,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({ const key = locationKey(location) setStore("session", "form", sessionID, [ ...(store.session.form[sessionID] ?? []).filter( - (form) => !form.location || locationKey(form.location) !== key, + (form) => form.location && locationKey(form.location) !== key, ), ...mutable( result.data.filter((form) => form.sessionID === "global").map((form) => ({ ...form, location })), diff --git a/packages/tui/src/feature-plugins/system/notifications.ts b/packages/tui/src/feature-plugins/system/notifications.ts index ce39c916eed..36f08b1c84b 100644 --- a/packages/tui/src/feature-plugins/system/notifications.ts +++ b/packages/tui/src/feature-plugins/system/notifications.ts @@ -26,13 +26,6 @@ function sessionErrorMessage(error: SessionError) { return "Session error" } -function formKey( - event: Extract, - id: string, -) { - return JSON.stringify([event.location?.directory, event.location?.workspaceID, id]) -} - const tui: TuiPlugin = async (api) => { const active = new Set() const errored = new Set() @@ -41,18 +34,17 @@ const tui: TuiPlugin = async (api) => { const permissions = new Set() api.event.on("form.created", (event) => { - const key = formKey(event, event.data.form.id) - if (forms.has(key)) return - forms.add(key) + if (forms.has(event.data.form.id)) return + forms.add(event.data.form.id) notify(api, event.data.form.sessionID, "Input needs response", "question") }) api.event.on("form.replied", (event) => { - forms.delete(formKey(event, event.data.id)) + forms.delete(event.data.id) }) api.event.on("form.cancelled", (event) => { - forms.delete(formKey(event, event.data.id)) + forms.delete(event.data.id) }) api.event.on("question.asked", (event) => { diff --git a/packages/tui/src/routes/session/index.tsx b/packages/tui/src/routes/session/index.tsx index 6a5919f5e1d..1bce7377149 100644 --- a/packages/tui/src/routes/session/index.tsx +++ b/packages/tui/src/routes/session/index.tsx @@ -187,11 +187,6 @@ export function Session() { ...(data.session.form.list("global", location()) ?? []), ] }) - const formKey = createMemo(() => { - const form = forms()[0] - if (!form) return - return JSON.stringify([form.location?.directory, form.location?.workspaceID, form.id]) - }) const [composer, setComposer] = createStore({ open: false, tab: undefined as string | undefined, @@ -269,7 +264,7 @@ export function Session() { if (route.sessionID !== sessionID) return project.workspace.set(info.location.workspaceID) editor.reconnect(info.location.directory) - if (route.sessionID === sessionID && scroll) scroll.scrollBy(100_000) + if (scroll) scroll.scrollBy(100_000) })().catch((error) => { if (route.sessionID !== sessionID) return toast.show({ @@ -948,7 +943,7 @@ export function Session() { 0}> - + {(_) => { const form = forms()[0] return form ? : null diff --git a/packages/tui/test/cli/tui/data.test.tsx b/packages/tui/test/cli/tui/data.test.tsx index f79fcf9f9e4..25143099d1b 100644 --- a/packages/tui/test/cli/tui/data.test.tsx +++ b/packages/tui/test/cli/tui/data.test.tsx @@ -907,7 +907,7 @@ test("tracks global forms by location", async () => { created: 0, location: other, type: "form.created", - data: { form: { id: "frm_global", sessionID: "global", mode: "form", fields: [] } }, + data: { form: { id: "frm_other", sessionID: "global", mode: "form", fields: [] } }, }) await wait(() => data.session.form.list("global", other)?.length === 1) @@ -918,7 +918,7 @@ test("tracks global forms by location", async () => { created: 1, location: { directory }, type: "form.created", - data: { form: { id: "frm_global", sessionID: "global", mode: "form", fields: [] } }, + data: { form: { id: "frm_default", sessionID: "global", mode: "form", fields: [] } }, }) await wait(() => data.session.form.list("global", { directory })?.length === 1) @@ -927,10 +927,10 @@ test("tracks global forms by location", async () => { created: 2, location: other, type: "form.replied", - data: { id: "frm_global", sessionID: "global", answer: {} }, + data: { id: "frm_other", sessionID: "global", answer: {} }, }) await wait(() => data.session.form.list("global", other)?.length === 0) - expect(data.session.form.list("global", { directory })?.map((form) => form.id)).toEqual(["frm_global"]) + expect(data.session.form.list("global", { directory })?.map((form) => form.id)).toEqual(["frm_default"]) } finally { app.renderer.destroy() }