@bindu-dashing/dam-solution-v2 5.8.17 → 5.8.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/MyDrive/FolderTree.js +33 -39
- package/package.json +1 -1
|
@@ -42,8 +42,23 @@ const AiOutlineSortDescendingbtn = AiOutlineSortDescending;
|
|
|
42
42
|
const AiOutlineSortAscendingbtn = AiOutlineSortAscending;
|
|
43
43
|
const GrSortIcon = FaShuffle;
|
|
44
44
|
const IoIosSearchIcon = IoIosSearch;
|
|
45
|
+
// ✅ Helper to find a folder by ID in the tree
|
|
46
|
+
const findFolderById = (tree, folderId) => {
|
|
47
|
+
for (const node of tree) {
|
|
48
|
+
if (node._id === folderId) {
|
|
49
|
+
return node;
|
|
50
|
+
}
|
|
51
|
+
if (isArray(node.children)) {
|
|
52
|
+
const found = findFolderById(node.children, folderId);
|
|
53
|
+
if (found)
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
};
|
|
45
59
|
// ✅ Helper to insert children into the correct folder recursively
|
|
46
60
|
const insertSubfolders = (tree, parentId, childrenToInsert) => {
|
|
61
|
+
console.log('## insertSubfolders', tree, parentId, childrenToInsert);
|
|
47
62
|
const newTree = map(tree, (node) => {
|
|
48
63
|
if (node._id === parentId) {
|
|
49
64
|
return Object.assign(Object.assign({}, node), { children: childrenToInsert });
|
|
@@ -53,6 +68,7 @@ const insertSubfolders = (tree, parentId, childrenToInsert) => {
|
|
|
53
68
|
}
|
|
54
69
|
return node;
|
|
55
70
|
});
|
|
71
|
+
console.log('## newTree', newTree);
|
|
56
72
|
return newTree;
|
|
57
73
|
};
|
|
58
74
|
const sortFoldersRecursively = (folders, sortByField, // ✅ which field to sort
|
|
@@ -105,49 +121,27 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
105
121
|
});
|
|
106
122
|
const response = yield api.get(`${FETCH_FOLDER_URL.replace(":folderId", fid)}?isPagination=false&includeFiles=false&includeSubFoldersCount=true&fetchMainFolders=true&globalSearch=${fid == rootFolderId ? globalSearch : ""}`);
|
|
107
123
|
const newFolders = get(response, "data.folders", []);
|
|
108
|
-
console.log('## newFolders',
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
console.log('## sorted folders (length):', sorted.length, 'folders before update:', folders === null || folders === void 0 ? void 0 : folders.length);
|
|
112
|
-
// If results are empty and we don't have a rootFolderId, or if fid matches rootFolderId,
|
|
113
|
-
// always replace all folders with fresh results (even if empty)
|
|
114
|
-
if (fid === rootFolderId || (!rootFolderId && sorted.length === 0)) {
|
|
115
|
-
// For root folder, always replace with fresh results (even if empty)
|
|
116
|
-
// This ensures when API returns empty, we clear all folders
|
|
117
|
-
console.log('## Setting root folders to (length):', sorted.length);
|
|
118
|
-
setFolders(sorted);
|
|
124
|
+
console.log('## newFolders', response, newFolders, fid, rootFolderId, globalSearch);
|
|
125
|
+
if (fid === rootFolderId) {
|
|
126
|
+
setFolders(sortFoldersRecursively(newFolders, "name", sortOrder));
|
|
119
127
|
}
|
|
120
128
|
else {
|
|
121
|
-
// For subfolders, always replace children with fresh data (even if empty array)
|
|
122
|
-
// This ensures we don't keep stale/previous data when API returns empty results
|
|
123
129
|
setFolders((prev) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
// Find the folder with fid in the tree
|
|
131
|
+
const foundFolder = findFolderById(prev, fid);
|
|
132
|
+
if (foundFolder) {
|
|
133
|
+
// Return only the folder with fid and its updated children
|
|
134
|
+
const sorted = sortFoldersRecursively(newFolders, "name", sortOrder);
|
|
135
|
+
console.log('## Found folder:', foundFolder._id, 'New children:', sorted);
|
|
136
|
+
return [Object.assign(Object.assign({}, foundFolder), { children: sorted })];
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// If folder not found, update the entire tree (fallback)
|
|
140
|
+
console.log('## Folder not found, updating entire tree');
|
|
141
|
+
const cloned = cloneDeep(prev);
|
|
142
|
+
const sorted = sortFoldersRecursively(newFolders, "name", sortOrder);
|
|
143
|
+
return insertSubfolders(cloned, fid, sorted);
|
|
130
144
|
}
|
|
131
|
-
// Clone previous state to ensure immutability
|
|
132
|
-
const cloned = cloneDeep(prev);
|
|
133
|
-
// insertSubfolders will replace children with fresh sorted data (even if empty array)
|
|
134
|
-
// This ensures previous children are cleared when API returns empty results
|
|
135
|
-
const result = insertSubfolders(cloned, fid, sorted);
|
|
136
|
-
console.log('## After insertSubfolders, result length:', result === null || result === void 0 ? void 0 : result.length);
|
|
137
|
-
// Verify the folder was found and updated
|
|
138
|
-
const folderFound = result.some((node) => {
|
|
139
|
-
const checkNode = (n) => {
|
|
140
|
-
if (n._id === fid)
|
|
141
|
-
return true;
|
|
142
|
-
if (isArray(n.children)) {
|
|
143
|
-
return n.children.some(checkNode);
|
|
144
|
-
}
|
|
145
|
-
return false;
|
|
146
|
-
};
|
|
147
|
-
return checkNode(node);
|
|
148
|
-
});
|
|
149
|
-
console.log('## Folder found in tree:', folderFound);
|
|
150
|
-
return result;
|
|
151
145
|
});
|
|
152
146
|
}
|
|
153
147
|
setState((prevState) => {
|