mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-04 21:32:39 +02:00
fix: scope pending doc warning to folder subtree on folder export
This commit is contained in:
parent
b5f6e44fc3
commit
a81fff299a
1 changed files with 23 additions and 3 deletions
|
|
@ -503,13 +503,33 @@ export function DocumentsSidebar({
|
||||||
setExportWarningContext(null);
|
setExportWarningContext(null);
|
||||||
}, [exportWarningContext, searchSpaceId, doExport]);
|
}, [exportWarningContext, searchSpaceId, doExport]);
|
||||||
|
|
||||||
|
const getPendingCountInSubtree = useCallback(
|
||||||
|
(folderId: number): number => {
|
||||||
|
const subtreeIds = new Set<number>();
|
||||||
|
function collect(id: number) {
|
||||||
|
subtreeIds.add(id);
|
||||||
|
for (const child of foldersByParent[String(id)] ?? []) {
|
||||||
|
collect(child.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collect(folderId);
|
||||||
|
return treeDocuments.filter(
|
||||||
|
(d) =>
|
||||||
|
subtreeIds.has(d.folderId ?? -1) &&
|
||||||
|
(d.status?.state === "pending" || d.status?.state === "processing")
|
||||||
|
).length;
|
||||||
|
},
|
||||||
|
[foldersByParent, treeDocuments]
|
||||||
|
);
|
||||||
|
|
||||||
const handleExportFolder = useCallback(
|
const handleExportFolder = useCallback(
|
||||||
async (folder: FolderDisplay) => {
|
async (folder: FolderDisplay) => {
|
||||||
if (pendingDocuments.length > 0) {
|
const folderPendingCount = getPendingCountInSubtree(folder.id);
|
||||||
|
if (folderPendingCount > 0) {
|
||||||
setExportWarningContext({
|
setExportWarningContext({
|
||||||
type: "folder",
|
type: "folder",
|
||||||
folder,
|
folder,
|
||||||
pendingCount: pendingDocuments.length,
|
pendingCount: folderPendingCount,
|
||||||
});
|
});
|
||||||
setExportWarningOpen(true);
|
setExportWarningOpen(true);
|
||||||
return;
|
return;
|
||||||
|
|
@ -531,7 +551,7 @@ export function DocumentsSidebar({
|
||||||
toast.error(err instanceof Error ? err.message : "Export failed");
|
toast.error(err instanceof Error ? err.message : "Export failed");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[searchSpaceId, pendingDocuments.length, doExport]
|
[searchSpaceId, getPendingCountInSubtree, doExport]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleExportDocument = useCallback(
|
const handleExportDocument = useCallback(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue