@bindu-dashing/dam-solution-v2 5.8.57 → 5.8.59
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 +45 -3
- package/package.json +1 -1
|
@@ -179,6 +179,21 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
179
179
|
}
|
|
180
180
|
return false;
|
|
181
181
|
};
|
|
182
|
+
// Helper to find the path (all parent IDs) to a folder in the tree
|
|
183
|
+
const findPathToFolder = (folderId, tree, path = []) => {
|
|
184
|
+
for (const folder of tree) {
|
|
185
|
+
const currentPath = [...path, folder._id];
|
|
186
|
+
if (folder._id === folderId) {
|
|
187
|
+
return currentPath;
|
|
188
|
+
}
|
|
189
|
+
if (isArray(folder.children)) {
|
|
190
|
+
const found = findPathToFolder(folderId, folder.children, currentPath);
|
|
191
|
+
if (found)
|
|
192
|
+
return found;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
};
|
|
182
197
|
// ✅ Load on mount & when currentRootId changes
|
|
183
198
|
// Use ref to track previous currentRootId to prevent unnecessary fetches
|
|
184
199
|
const prevCurrentRootIdRef = useRef(null);
|
|
@@ -206,11 +221,38 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
206
221
|
if (!existingFolder || !isArray(existingFolder.children) || existingFolder.children.length === 0) {
|
|
207
222
|
fetchFolderChildren(currentRootId);
|
|
208
223
|
}
|
|
224
|
+
// Expand the tree to show the path to the selected folder
|
|
225
|
+
const pathToFolder = findPathToFolder(currentRootId, folders);
|
|
226
|
+
if (pathToFolder && pathToFolder.length > 0) {
|
|
227
|
+
// Remove the folder itself from the path (we only need to expand parents)
|
|
228
|
+
const parentPath = pathToFolder.slice(0, -1);
|
|
229
|
+
if (parentPath.length > 0) {
|
|
230
|
+
const currentExpanded = isArray(expandedKeys) ? expandedKeys : [expandedKeys].filter(Boolean);
|
|
231
|
+
const newExpanded = [...new Set([...currentExpanded, ...parentPath])];
|
|
232
|
+
setExpandedKeys(newExpanded);
|
|
233
|
+
console.log('## Expanding path to folder:', parentPath);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// Update ref to prevent re-triggering
|
|
237
|
+
prevCurrentRootIdRef.current = currentRootId;
|
|
209
238
|
}
|
|
210
239
|
else {
|
|
211
|
-
// Folder not in tree
|
|
212
|
-
|
|
213
|
-
|
|
240
|
+
// Folder not in tree - only replace tree if it's the root folder or folders is empty
|
|
241
|
+
// For subfolders clicked from list view, keep existing tree structure to avoid replacing it
|
|
242
|
+
if (currentRootId === rootFolderId || folders.length === 0) {
|
|
243
|
+
// Root folder or empty tree - fetch as new root
|
|
244
|
+
prevCurrentRootIdRef.current = currentRootId;
|
|
245
|
+
fetchFolders(currentRootId);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
// Subfolder not in tree but tree has content - keep existing tree structure
|
|
249
|
+
// The DriveContainer will handle showing the folder contents based on parentFolderId
|
|
250
|
+
// This prevents replacing the entire tree when clicking folders from list view
|
|
251
|
+
console.log('## Folder not in tree but tree has content - keeping existing tree structure');
|
|
252
|
+
prevCurrentRootIdRef.current = currentRootId;
|
|
253
|
+
// Don't call fetchFolders here to avoid replacing the tree
|
|
254
|
+
// The folder contents will be shown by DriveContainer based on parentFolderId
|
|
255
|
+
}
|
|
214
256
|
}
|
|
215
257
|
}
|
|
216
258
|
else if (globalSearch !== globalSearchValue && currentRootId === rootFolderId) {
|