@bindu-dashing/dam-solution-v2 5.8.28 → 5.8.29

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
- prevCurrentRootIdRef.current = currentRootId;
178
- fetchFolders(currentRootId);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.28",
3
+ "version": "5.8.29",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",