mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-02-25 20:15:01 +01:00
fix: keep Send All response updates window-scoped (#405)
This commit is contained in:
@@ -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,
|
||||
)?
|
||||
};
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user