fix: keep Send All response updates window-scoped (#405)

This commit is contained in:
Gregory Schier
2026-02-25 06:54:59 -08:00
committed by GitHub
parent b2a70d8938
commit 020589f2e6
3 changed files with 38 additions and 16 deletions

View File

@@ -362,7 +362,7 @@ async fn handle_host_plugin_request<R: Runtime>(
workspace_id: http_request.workspace_id.clone(), workspace_id: http_request.workspace_id.clone(),
..Default::default() ..Default::default()
}, },
&UpdateSource::Plugin, &UpdateSource::from_window_label(window.label()),
&blobs, &blobs,
)? )?
}; };

View File

@@ -1,7 +1,7 @@
{ {
"name": "@yaak/action-send-folder", "name": "@yaak/action-send-folder",
"displayName": "Send All", "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": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/mountain-loop/yaak.git", "url": "https://github.com/mountain-loop/yaak.git",

View File

@@ -14,22 +14,44 @@ export const plugin: PluginDefinition = {
ctx.httpRequest.list(), ctx.httpRequest.list(),
]); ]);
// Build a set of all folder IDs that are descendants of the target folder // Build the send order to match tree ordering:
const folderIds = new Set<string>([targetFolder.id]); // sort siblings by sortPriority then updatedAt, and traverse folders depth-first.
const addDescendants = (parentId: string) => { const compareByOrder = (
for (const folder of allFolders) { a: Pick<typeof allFolders[number], 'sortPriority' | 'updatedAt'>,
if (folder.folderId === parentId && !folderIds.has(folder.id)) { b: Pick<typeof allFolders[number], 'sortPriority' | 'updatedAt'>,
folderIds.add(folder.id); ) => {
addDescendants(folder.id); if (a.sortPriority === b.sortPriority) {
return a.updatedAt > b.updatedAt ? 1 : -1;
}
return a.sortPriority - b.sortPriority;
};
const childrenByFolderId = new Map<string, Array<typeof allFolders[number] | typeof allRequests[number]>>();
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); collectRequests(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),
);
if (requestsToSend.length === 0) { if (requestsToSend.length === 0) {
await ctx.toast.show({ await ctx.toast.show({
@@ -40,7 +62,7 @@ export const plugin: PluginDefinition = {
return; return;
} }
// Send each request sequentially // Send requests sequentially in the calculated folder order.
let successCount = 0; let successCount = 0;
let errorCount = 0; let errorCount = 0;