From 020589f2e6cc58abf69f5d214c2d4baf770273e5 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 25 Feb 2026 06:54:59 -0800 Subject: [PATCH] fix: keep Send All response updates window-scoped (#405) --- crates-tauri/yaak-app/src/plugin_events.rs | 2 +- plugins/action-send-folder/package.json | 2 +- plugins/action-send-folder/src/index.ts | 50 ++++++++++++++++------ 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/crates-tauri/yaak-app/src/plugin_events.rs b/crates-tauri/yaak-app/src/plugin_events.rs index f0b0875d..35ffa9c5 100644 --- a/crates-tauri/yaak-app/src/plugin_events.rs +++ b/crates-tauri/yaak-app/src/plugin_events.rs @@ -362,7 +362,7 @@ async fn handle_host_plugin_request( workspace_id: http_request.workspace_id.clone(), ..Default::default() }, - &UpdateSource::Plugin, + &UpdateSource::from_window_label(window.label()), &blobs, )? }; diff --git a/plugins/action-send-folder/package.json b/plugins/action-send-folder/package.json index 3b0f7570..69bd09a4 100644 --- a/plugins/action-send-folder/package.json +++ b/plugins/action-send-folder/package.json @@ -1,7 +1,7 @@ { "name": "@yaak/action-send-folder", "displayName": "Send All", - "description": "Send all HTTP requests in a folder sequentially", + "description": "Send all HTTP requests in a folder sequentially in tree order", "repository": { "type": "git", "url": "https://github.com/mountain-loop/yaak.git", diff --git a/plugins/action-send-folder/src/index.ts b/plugins/action-send-folder/src/index.ts index d0395c00..f2741755 100644 --- a/plugins/action-send-folder/src/index.ts +++ b/plugins/action-send-folder/src/index.ts @@ -14,22 +14,44 @@ export const plugin: PluginDefinition = { ctx.httpRequest.list(), ]); - // Build a set of all folder IDs that are descendants of the target folder - const folderIds = new Set([targetFolder.id]); - const addDescendants = (parentId: string) => { - for (const folder of allFolders) { - if (folder.folderId === parentId && !folderIds.has(folder.id)) { - folderIds.add(folder.id); - addDescendants(folder.id); + // Build the send order to match tree ordering: + // sort siblings by sortPriority then updatedAt, and traverse folders depth-first. + const compareByOrder = ( + a: Pick, + b: Pick, + ) => { + if (a.sortPriority === b.sortPriority) { + return a.updatedAt > b.updatedAt ? 1 : -1; + } + return a.sortPriority - b.sortPriority; + }; + + const childrenByFolderId = new Map>(); + for (const folder of allFolders) { + if (folder.folderId == null) continue; + const children = childrenByFolderId.get(folder.folderId) ?? []; + children.push(folder); + childrenByFolderId.set(folder.folderId, children); + } + for (const request of allRequests) { + if (request.folderId == null) continue; + const children = childrenByFolderId.get(request.folderId) ?? []; + children.push(request); + childrenByFolderId.set(request.folderId, children); + } + + const requestsToSend: typeof allRequests = []; + const collectRequests = (folderId: string) => { + const children = (childrenByFolderId.get(folderId) ?? []).slice().sort(compareByOrder); + for (const child of children) { + if (child.model === 'folder') { + collectRequests(child.id); + } else if (child.model === 'http_request') { + requestsToSend.push(child); } } }; - addDescendants(targetFolder.id); - - // Filter HTTP requests to those in the target folder or its descendants - const requestsToSend = allRequests.filter( - (req) => req.folderId != null && folderIds.has(req.folderId), - ); + collectRequests(targetFolder.id); if (requestsToSend.length === 0) { await ctx.toast.show({ @@ -40,7 +62,7 @@ export const plugin: PluginDefinition = { return; } - // Send each request sequentially + // Send requests sequentially in the calculated folder order. let successCount = 0; let errorCount = 0;