Skip to content

Commit 020589f

Browse files
authored
fix: keep Send All response updates window-scoped (#405)
1 parent b2a70d8 commit 020589f

3 files changed

Lines changed: 38 additions & 16 deletions

File tree

crates-tauri/yaak-app/src/plugin_events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ async fn handle_host_plugin_request<R: Runtime>(
362362
workspace_id: http_request.workspace_id.clone(),
363363
..Default::default()
364364
},
365-
&UpdateSource::Plugin,
365+
&UpdateSource::from_window_label(window.label()),
366366
&blobs,
367367
)?
368368
};

plugins/action-send-folder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@yaak/action-send-folder",
33
"displayName": "Send All",
4-
"description": "Send all HTTP requests in a folder sequentially",
4+
"description": "Send all HTTP requests in a folder sequentially in tree order",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/mountain-loop/yaak.git",

plugins/action-send-folder/src/index.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,44 @@ export const plugin: PluginDefinition = {
1414
ctx.httpRequest.list(),
1515
]);
1616

17-
// Build a set of all folder IDs that are descendants of the target folder
18-
const folderIds = new Set<string>([targetFolder.id]);
19-
const addDescendants = (parentId: string) => {
20-
for (const folder of allFolders) {
21-
if (folder.folderId === parentId && !folderIds.has(folder.id)) {
22-
folderIds.add(folder.id);
23-
addDescendants(folder.id);
24-
}
17+
// Build the send order to match tree ordering:
18+
// sort siblings by sortPriority then updatedAt, and traverse folders depth-first.
19+
const compareByOrder = (
20+
a: Pick<typeof allFolders[number], 'sortPriority' | 'updatedAt'>,
21+
b: Pick<typeof allFolders[number], 'sortPriority' | 'updatedAt'>,
22+
) => {
23+
if (a.sortPriority === b.sortPriority) {
24+
return a.updatedAt > b.updatedAt ? 1 : -1;
2525
}
26+
return a.sortPriority - b.sortPriority;
2627
};
27-
addDescendants(targetFolder.id);
2828

29-
// Filter HTTP requests to those in the target folder or its descendants
30-
const requestsToSend = allRequests.filter(
31-
(req) => req.folderId != null && folderIds.has(req.folderId),
32-
);
29+
const childrenByFolderId = new Map<string, Array<typeof allFolders[number] | typeof allRequests[number]>>();
30+
for (const folder of allFolders) {
31+
if (folder.folderId == null) continue;
32+
const children = childrenByFolderId.get(folder.folderId) ?? [];
33+
children.push(folder);
34+
childrenByFolderId.set(folder.folderId, children);
35+
}
36+
for (const request of allRequests) {
37+
if (request.folderId == null) continue;
38+
const children = childrenByFolderId.get(request.folderId) ?? [];
39+
children.push(request);
40+
childrenByFolderId.set(request.folderId, children);
41+
}
42+
43+
const requestsToSend: typeof allRequests = [];
44+
const collectRequests = (folderId: string) => {
45+
const children = (childrenByFolderId.get(folderId) ?? []).slice().sort(compareByOrder);
46+
for (const child of children) {
47+
if (child.model === 'folder') {
48+
collectRequests(child.id);
49+
} else if (child.model === 'http_request') {
50+
requestsToSend.push(child);
51+
}
52+
}
53+
};
54+
collectRequests(targetFolder.id);
3355

3456
if (requestsToSend.length === 0) {
3557
await ctx.toast.show({
@@ -40,7 +62,7 @@ export const plugin: PluginDefinition = {
4062
return;
4163
}
4264

43-
// Send each request sequentially
65+
// Send requests sequentially in the calculated folder order.
4466
let successCount = 0;
4567
let errorCount = 0;
4668

0 commit comments

Comments
 (0)