Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates-tauri/yaak-app/src/plugin_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ async fn handle_host_plugin_request<R: Runtime>(
workspace_id: http_request.workspace_id.clone(),
..Default::default()
},
&UpdateSource::Plugin,
&UpdateSource::from_window_label(window.label()),
&blobs,
)?
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/action-send-folder/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
50 changes: 36 additions & 14 deletions plugins/action-send-folder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>([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<typeof allFolders[number], 'sortPriority' | 'updatedAt'>,
b: Pick<typeof allFolders[number], 'sortPriority' | 'updatedAt'>,
) => {
if (a.sortPriority === b.sortPriority) {
return a.updatedAt > b.updatedAt ? 1 : -1;
}
return a.sortPriority - b.sortPriority;
};
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),
);
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);
}
}
};
collectRequests(targetFolder.id);

if (requestsToSend.length === 0) {
await ctx.toast.show({
Expand All @@ -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;

Expand Down