@bindu-dashing/dam-solution-v2 5.8.58 → 5.8.60
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 +27 -0
- 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,6 +221,18 @@ 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
|
+
}
|
|
209
236
|
// Update ref to prevent re-triggering
|
|
210
237
|
prevCurrentRootIdRef.current = currentRootId;
|
|
211
238
|
}
|