@bindu-dashing/dam-solution-v2 5.8.28 → 5.8.30
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.
|
@@ -168,14 +168,53 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
|
+
// Helper to check if a folder exists in the current tree
|
|
172
|
+
const folderExistsInTree = (folderId, tree) => {
|
|
173
|
+
for (const folder of tree) {
|
|
174
|
+
if (folder._id === folderId) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
if (isArray(folder.children)) {
|
|
178
|
+
if (folderExistsInTree(folderId, folder.children)) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
};
|
|
171
185
|
// ✅ Load on mount & when currentRootId changes
|
|
172
186
|
// Use ref to track previous currentRootId to prevent unnecessary fetches
|
|
173
187
|
const prevCurrentRootIdRef = useRef(null);
|
|
174
188
|
useEffect(() => {
|
|
175
189
|
if (currentRootId && currentRootId !== prevCurrentRootIdRef.current) {
|
|
176
190
|
console.log('## FolderTree useEffect - currentRootId changed from', prevCurrentRootIdRef.current, 'to', currentRootId, 'rootFolderId:', rootFolderId);
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
// If the folder is already in the tree, don't replace the entire tree
|
|
192
|
+
// Just fetch its children if needed
|
|
193
|
+
if (folders.length > 0 && folderExistsInTree(currentRootId, folders)) {
|
|
194
|
+
console.log('## Folder already in tree, fetching children only');
|
|
195
|
+
// Check if folder already has children loaded
|
|
196
|
+
const findFolder = (tree, id) => {
|
|
197
|
+
for (const folder of tree) {
|
|
198
|
+
if (folder._id === id)
|
|
199
|
+
return folder;
|
|
200
|
+
if (isArray(folder.children)) {
|
|
201
|
+
const found = findFolder(folder.children, id);
|
|
202
|
+
if (found)
|
|
203
|
+
return found;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
};
|
|
208
|
+
const existingFolder = findFolder(folders, currentRootId);
|
|
209
|
+
if (!existingFolder || !isArray(existingFolder.children) || existingFolder.children.length === 0) {
|
|
210
|
+
fetchFolderChildren(currentRootId);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
// Folder not in tree, fetch it as the new root
|
|
215
|
+
prevCurrentRootIdRef.current = currentRootId;
|
|
216
|
+
fetchFolders(currentRootId);
|
|
217
|
+
}
|
|
179
218
|
}
|
|
180
219
|
else if (globalSearch !== globalSearchValue && currentRootId === rootFolderId) {
|
|
181
220
|
// Only refetch on global search change if we're on root folder
|
|
@@ -278,7 +317,6 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
278
317
|
setSelectedKeys(selected);
|
|
279
318
|
if (get(selected, "length") > 0) {
|
|
280
319
|
const selectedId = selected[get(selected, "length", 0) - 1];
|
|
281
|
-
// navigate(SUBFOLDERS_SCREEN.replace(":folderId", selectedId));
|
|
282
320
|
console.log('## selectedId', selectedId);
|
|
283
321
|
// If the selected folder is not the root folder, fetch its children
|
|
284
322
|
if (selectedId !== rootFolderId && selectedId !== currentRootId) {
|
|
@@ -38,9 +38,17 @@ export default function MyDriveMainContainer({ folders, setFolders }) {
|
|
|
38
38
|
: selectedKeys
|
|
39
39
|
? selectedKeys
|
|
40
40
|
: ((params === null || params === void 0 ? void 0 : params.folderId) || (params === null || params === void 0 ? void 0 : params.id) || (params === null || params === void 0 ? void 0 : params.parentId) || rootFolderId);
|
|
41
|
-
|
|
41
|
+
// Get the currently selected folder ID for DriveContainer
|
|
42
|
+
const selectedFolderId = isArray(selectedKeys)
|
|
43
|
+
? selectedKeys.length
|
|
44
|
+
? selectedKeys[selectedKeys.length - 1]
|
|
45
|
+
: ((params === null || params === void 0 ? void 0 : params.folderId) || (params === null || params === void 0 ? void 0 : params.id) || (params === null || params === void 0 ? void 0 : params.parentId) || rootFolderId)
|
|
46
|
+
: selectedKeys
|
|
47
|
+
? selectedKeys
|
|
48
|
+
: ((params === null || params === void 0 ? void 0 : params.folderId) || (params === null || params === void 0 ? void 0 : params.id) || (params === null || params === void 0 ? void 0 : params.parentId) || rootFolderId);
|
|
49
|
+
console.log('## MyDriveMainContainer - selectedKeys:', selectedKeys, 'currentRootId:', currentRootId, 'selectedFolderId:', selectedFolderId, 'rootFolderId:', rootFolderId);
|
|
42
50
|
const handleExpand = (keys) => {
|
|
43
51
|
setExpandedKeys(map(keys, (k) => k.toString()));
|
|
44
52
|
};
|
|
45
|
-
return (_jsxs(FoldersProvider, { value: { setFolders, folders, globalSearch }, children: [_jsx(FolderTree, { currentRootId: currentRootId, handleExpand: handleExpand, setSelectedKeys: setSelectedKeys, expandedKeys: expandedKeys, selectedKeys: selectedKeys, folders: folders, setExpandedKeys: setExpandedKeys, setFolders: setFolders, setGlobalSearch: setGlobalSearch, globalSearch: globalSearch }), _jsx("div", { className: "md-lib-h-[inherit] md-lib-overflow-x-auto", children: _jsx(DriveContainer, { globalSearch: globalSearch, setGlobalSearch: setGlobalSearch }) })] }));
|
|
53
|
+
return (_jsxs(FoldersProvider, { value: { setFolders, folders, globalSearch }, children: [_jsx(FolderTree, { currentRootId: currentRootId, handleExpand: handleExpand, setSelectedKeys: setSelectedKeys, expandedKeys: expandedKeys, selectedKeys: selectedKeys, folders: folders, setExpandedKeys: setExpandedKeys, setFolders: setFolders, setGlobalSearch: setGlobalSearch, globalSearch: globalSearch }), _jsx("div", { className: "md-lib-h-[inherit] md-lib-overflow-x-auto", children: _jsx(DriveContainer, { parentFolderId: selectedFolderId, globalSearch: globalSearch, setGlobalSearch: setGlobalSearch }) })] }));
|
|
46
54
|
}
|