@bindu-dashing/dam-solution-v2 5.8.19 → 5.8.21

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.
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { Button, Dropdown, Grid, Input, Select, Tooltip, Tree } from "antd";
12
- import { useEffect, useMemo, useState } from "react";
12
+ import { useEffect, useMemo, useState, useRef } from "react";
13
13
  import { get, map, isArray, isObject, cloneDeep, first, sortBy, } from "lodash";
14
14
  import { FaAngleLeft, FaAngleRight } from "react-icons/fa";
15
15
  import { deleteFolders, } from "../react-query/services/folder-services";
@@ -42,20 +42,6 @@ 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
- };
59
45
  // ✅ Helper to insert children into the correct folder recursively
60
46
  const insertSubfolders = (tree, parentId, childrenToInsert) => {
61
47
  console.log('## insertSubfolders', tree, parentId, childrenToInsert);
@@ -121,28 +107,16 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
121
107
  });
122
108
  const response = yield api.get(`${FETCH_FOLDER_URL.replace(":folderId", fid)}?isPagination=false&includeFiles=false&includeSubFoldersCount=true&fetchMainFolders=true&globalSearch=${fid == rootFolderId ? globalSearch : ""}`);
123
109
  const newFolders = get(response, "data.folders", []);
110
+ const folderInfo = get(response, "data.folder", {});
124
111
  console.log('## newFolders', response, newFolders, fid, rootFolderId, globalSearch);
125
112
  if (fid === rootFolderId) {
126
113
  setFolders(sortFoldersRecursively(newFolders, "name", sortOrder));
127
114
  }
128
115
  else {
129
- setFolders((prev) => {
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);
144
- }
145
- });
116
+ // Simply use folder info from API response and newFolders as children
117
+ const sorted = sortFoldersRecursively(newFolders, "name", sortOrder);
118
+ console.log('## Folder info:', folderInfo, 'New children:', sorted);
119
+ setFolders([Object.assign(Object.assign({}, folderInfo), { children: sorted })]);
146
120
  }
147
121
  setState((prevState) => {
148
122
  return Object.assign(Object.assign({}, prevState), { parentFolder: get(response, "data.folder", {}), loading: false, globalSearchValue: globalSearch || "" });
@@ -156,8 +130,17 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
156
130
  }
157
131
  });
158
132
  // ✅ Load on mount & when currentRootId changes
133
+ // Use ref to track previous currentRootId to prevent unnecessary fetches
134
+ const prevCurrentRootIdRef = useRef(null);
159
135
  useEffect(() => {
160
- if (currentRootId) {
136
+ if (currentRootId && currentRootId !== prevCurrentRootIdRef.current) {
137
+ console.log('## FolderTree useEffect - currentRootId changed from', prevCurrentRootIdRef.current, 'to', currentRootId, 'rootFolderId:', rootFolderId);
138
+ prevCurrentRootIdRef.current = currentRootId;
139
+ fetchFolders(currentRootId);
140
+ }
141
+ else if (globalSearch !== globalSearchValue && currentRootId === rootFolderId) {
142
+ // Only refetch on global search change if we're on root folder
143
+ console.log('## FolderTree useEffect - globalSearch changed, refetching root folder');
161
144
  fetchFolders(currentRootId);
162
145
  }
163
146
  }, [currentRootId, globalSearch]);
@@ -17,8 +17,14 @@ export default function MyDriveMainContainer({ folders, setFolders }) {
17
17
  useEffect(() => {
18
18
  // Priority: URL params > Props from ParamsProvider > rootFolderId from config
19
19
  if (params === null || params === void 0 ? void 0 : params.folderId) {
20
+ console.log('## Setting selectedKeys from params.folderId:', params.folderId);
20
21
  setSelectedKeys(params.folderId);
21
22
  }
23
+ else if (!(params === null || params === void 0 ? void 0 : params.folderId) && rootFolderId) {
24
+ // If no params but we have rootFolderId, use it
25
+ console.log('## No params.folderId, using rootFolderId:', rootFolderId);
26
+ setSelectedKeys(rootFolderId);
27
+ }
22
28
  }, [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]);
23
29
  const currentRootId = isArray(selectedKeys)
24
30
  ? selectedKeys.length
@@ -27,6 +33,7 @@ export default function MyDriveMainContainer({ folders, setFolders }) {
27
33
  : selectedKeys
28
34
  ? selectedKeys
29
35
  : rootFolderId;
36
+ console.log('## MyDriveMainContainer - selectedKeys:', selectedKeys, 'currentRootId:', currentRootId, 'rootFolderId:', rootFolderId);
30
37
  const handleExpand = (keys) => {
31
38
  setExpandedKeys(map(keys, (k) => k.toString()));
32
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.19",
3
+ "version": "5.8.21",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",