mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 09:08:32 +02: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(),
|
workspace_id: http_request.workspace_id.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
&UpdateSource::Plugin,
|
&UpdateSource::from_window_label(window.label()),
|
||||||
&blobs,
|
&blobs,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user