From 61154e6bfe31227f3c78091ca37130b7a660d6bb Mon Sep 17 00:00:00 2001 From: JiMyung Lee Date: Thu, 12 Nov 2026 20:45:36 +0900 Subject: [PATCH] :sparkles: Keep the swap component search when changing library (#12873) Changing the library in the Swap component menu cleared the search field, so checking several connected libraries for the same component meant typing the name again for each one. Keep the term and reset only the library id and the group path, so the new library is shown already filtered. Closes #12335 AI-assisted-by: claude-opus-5-5 Signed-off-by: JiMyung Lee --- .../ui/specs/workspace-shared-library.spec.js | 59 +++++++++++++++++++ .../sidebar/options/menus/component.cljs | 4 +- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/frontend/playwright/ui/specs/workspace-shared-library.spec.js b/frontend/playwright/ui/specs/workspace-shared-library.spec.js index b9bab493f1..4f65635f30 100644 --- a/frontend/playwright/ui/specs/workspace-shared-library.spec.js +++ b/frontend/playwright/ui/specs/workspace-shared-library.spec.js @@ -162,3 +162,62 @@ test("BUG 14214 - Updates tab refreshes after syncing a freshly linked library", updatesPanel.getByText("There are no Shared Libraries that need update"), ).toBeVisible(); }); + +test("Swap component menu keeps the search when changing library", async ({ + page, +}) => { + const workspace = new WasmWorkspacePage(page); + await workspace.setupEmptyFile(page); + + await workspace.mockRPC( + /get\-file\?/, + "workspace/get-file-9066-swap-groups.json", + ); + await workspace.mockRPC( + new RegExp(`get\\-file\\?id=${sharedFileId}`), + "workspace/get-file-9056_shared.json", + ); + await workspace.mockRPC( + "get-file-libraries?file-id=*", + "workspace/get-file-libraries-9056.json", + ); + await workspace.mockRPC( + `get-file-fragment?file-id=${sharedFileId}&fragment-id=${sharedFileFragmentId1}`, + "workspace/get-file-fragment-9056_shared-1.json", + ); + await workspace.mockRPC( + `get-file-fragment?file-id=${sharedFileId}&fragment-id=${sharedFileFragmentId2}`, + "workspace/get-file-fragment-9056_shared-2.json", + ); + + await workspace.goToWorkspace({ + fileId: "e179d9df-de35-80bf-8005-283bbd5516b0", + pageId: "e179d9df-de35-80bf-8005-283bbd5516b1", + }); + + await workspace.clickToggableLayer("Board"); + await workspace.clickToggableLayer("Group"); + await workspace.layers.getByText("A", { exact: true }).click(); + await workspace.rightSidebar.getByRole("button", { name: /^A / }).click(); + + const search = workspace.rightSidebar.locator( + "#swap-component-search-filter", + ); + await search.fill("rect"); + await expect( + workspace.rightSidebar.getByText("There are no assets in this library yet"), + ).toBeVisible(); + + await workspace.rightSidebar + .getByRole("combobox") + .filter({ hasText: "New File 10" }) + .click(); + await workspace.rightSidebar + .getByRole("option", { name: "published component" }) + .click(); + + await expect(search).toHaveValue("rect"); + await expect( + workspace.rightSidebar.getByText("Rectangle", { exact: true }), + ).toBeVisible(); +}); diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index f3c9764e15..387e0c9ac2 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -757,7 +757,9 @@ on-library-change (mf/use-fn (fn [id] - (swap! filters* assoc :file-id id :term "" :path ""))) + ;; Keep the search term: it describes what the user is looking + ;; for, not where, so it applies to the newly selected library. + (swap! filters* assoc :file-id id :path ""))) on-search-term-change (mf/use-fn