@bindu-dashing/dam-solution-v2 5.8.27 → 5.8.28
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";
|
|
@@ -111,6 +111,33 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
111
111
|
globalSearchValue: "",
|
|
112
112
|
});
|
|
113
113
|
const { showConfirmationModal, showEditModal, selectedFolder, loading, isSorting, enableDrag, sortMode, sortOrder, tempFolders, parentFolder, globalSearchValue, } = state;
|
|
114
|
+
// Fetch children for a specific folder and insert them into the tree (same logic as fetchFolders)
|
|
115
|
+
const fetchFolderChildren = (folderId) => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
try {
|
|
117
|
+
setState((prevState) => {
|
|
118
|
+
return Object.assign(Object.assign({}, prevState), { loading: true });
|
|
119
|
+
});
|
|
120
|
+
const response = yield api.get(`${FETCH_FOLDER_URL.replace(":folderId", folderId)}?isPagination=false&includeFiles=false&includeSubFoldersCount=true&fetchMainFolders=true&globalSearch=`);
|
|
121
|
+
const newFolders = get(response, "data.folders", []);
|
|
122
|
+
// Simply use the same logic as fetchFolders - sort and insert recursively
|
|
123
|
+
const sorted = sortFoldersRecursively(newFolders, "name", sortOrder);
|
|
124
|
+
const newChildren = insertSubfoldersRecursively(sorted);
|
|
125
|
+
console.log('## Fetching children for folder:', folderId, 'New children:', newChildren);
|
|
126
|
+
// Insert the fetched children into the clicked folder in the tree
|
|
127
|
+
setFolders((prevFolders) => {
|
|
128
|
+
return insertSubfolders(prevFolders, folderId, newChildren);
|
|
129
|
+
});
|
|
130
|
+
setState((prevState) => {
|
|
131
|
+
return Object.assign(Object.assign({}, prevState), { loading: false });
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
|
|
136
|
+
setState((prevState) => {
|
|
137
|
+
return Object.assign(Object.assign({}, prevState), { loading: false });
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
114
141
|
const fetchFolders = (fid) => __awaiter(this, void 0, void 0, function* () {
|
|
115
142
|
try {
|
|
116
143
|
setState((prevState) => {
|
|
@@ -124,18 +151,11 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
124
151
|
setFolders(sortFoldersRecursively(newFolders, "name", sortOrder));
|
|
125
152
|
}
|
|
126
153
|
else {
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// children: insertSubfoldersRecursively(sorted),
|
|
133
|
-
// }]);
|
|
134
|
-
setFolders((prev) => {
|
|
135
|
-
const cloned = cloneDeep(prev);
|
|
136
|
-
const sorted = sortFoldersRecursively(newFolders, "name", sortOrder);
|
|
137
|
-
return insertSubfolders(cloned, fid, sorted);
|
|
138
|
-
});
|
|
154
|
+
// Simply use folder info from API response and newFolders as children
|
|
155
|
+
const sorted = sortFoldersRecursively(newFolders, "name", sortOrder);
|
|
156
|
+
console.log('## Folder info:', folderInfo, 'New children:', insertSubfoldersRecursively(sorted));
|
|
157
|
+
const newChildren = insertSubfoldersRecursively(sorted);
|
|
158
|
+
setFolders([Object.assign(Object.assign({}, folderInfo), { children: newChildren })]);
|
|
139
159
|
}
|
|
140
160
|
setState((prevState) => {
|
|
141
161
|
return Object.assign(Object.assign({}, prevState), { parentFolder: get(response, "data.folder", {}), loading: false, globalSearchValue: globalSearch || "" });
|
|
@@ -149,8 +169,17 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
149
169
|
}
|
|
150
170
|
});
|
|
151
171
|
// ✅ Load on mount & when currentRootId changes
|
|
172
|
+
// Use ref to track previous currentRootId to prevent unnecessary fetches
|
|
173
|
+
const prevCurrentRootIdRef = useRef(null);
|
|
152
174
|
useEffect(() => {
|
|
153
|
-
if (currentRootId) {
|
|
175
|
+
if (currentRootId && currentRootId !== prevCurrentRootIdRef.current) {
|
|
176
|
+
console.log('## FolderTree useEffect - currentRootId changed from', prevCurrentRootIdRef.current, 'to', currentRootId, 'rootFolderId:', rootFolderId);
|
|
177
|
+
prevCurrentRootIdRef.current = currentRootId;
|
|
178
|
+
fetchFolders(currentRootId);
|
|
179
|
+
}
|
|
180
|
+
else if (globalSearch !== globalSearchValue && currentRootId === rootFolderId) {
|
|
181
|
+
// Only refetch on global search change if we're on root folder
|
|
182
|
+
console.log('## FolderTree useEffect - globalSearch changed, refetching root folder');
|
|
154
183
|
fetchFolders(currentRootId);
|
|
155
184
|
}
|
|
156
185
|
}, [currentRootId, globalSearch]);
|
|
@@ -181,6 +210,7 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
181
210
|
const toggleEditModal = (folder = {}) => setState((prev) => (Object.assign(Object.assign({}, prev), { selectedFolder: folder, showEditModal: !prev.showEditModal })));
|
|
182
211
|
const toggleDeleteModal = (folder = {}) => setState((prev) => (Object.assign(Object.assign({}, prev), { selectedFolder: folder, showConfirmationModal: !prev.showConfirmationModal })));
|
|
183
212
|
const getFoldersTree = (folders = []) => {
|
|
213
|
+
console.log('## folders', folders);
|
|
184
214
|
const transform = (tree = []) => map(tree, (folder) => {
|
|
185
215
|
const key = get(folder, "_id", "");
|
|
186
216
|
const name = get(folder, "name", "");
|
|
@@ -228,6 +258,19 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
228
258
|
return get(item, "_id") !== rootFolderId;
|
|
229
259
|
});
|
|
230
260
|
}, [parentFolder]);
|
|
261
|
+
// Wrapper for handleExpand that also fetches children when a folder is expanded
|
|
262
|
+
const handleExpandWithFetch = (keys) => {
|
|
263
|
+
handleExpand(keys);
|
|
264
|
+
const newExpanded = map(keys, (k) => k.toString());
|
|
265
|
+
const currentExpanded = isArray(expandedKeys) ? expandedKeys : [expandedKeys].filter(Boolean);
|
|
266
|
+
const newlyExpanded = newExpanded.filter(id => !currentExpanded.includes(id));
|
|
267
|
+
// Fetch children for newly expanded folders using the same simple logic
|
|
268
|
+
newlyExpanded.forEach(expandedId => {
|
|
269
|
+
if (expandedId !== rootFolderId && expandedId !== currentRootId) {
|
|
270
|
+
fetchFolderChildren(expandedId);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
};
|
|
231
274
|
const handleSelect = (keys) => {
|
|
232
275
|
// console.log("keys", keys);
|
|
233
276
|
const selected = map(keys, (k) => k.toString());
|
|
@@ -236,6 +279,11 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
236
279
|
if (get(selected, "length") > 0) {
|
|
237
280
|
const selectedId = selected[get(selected, "length", 0) - 1];
|
|
238
281
|
// navigate(SUBFOLDERS_SCREEN.replace(":folderId", selectedId));
|
|
282
|
+
console.log('## selectedId', selectedId);
|
|
283
|
+
// If the selected folder is not the root folder, fetch its children
|
|
284
|
+
if (selectedId !== rootFolderId && selectedId !== currentRootId) {
|
|
285
|
+
fetchFolderChildren(selectedId);
|
|
286
|
+
}
|
|
239
287
|
}
|
|
240
288
|
};
|
|
241
289
|
useEffect(() => {
|
|
@@ -341,6 +389,7 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
341
389
|
return Object.assign(Object.assign({}, prevState), { tempFolders: cloneDeep(customSorted), sortMode: "custom", enableDrag: false });
|
|
342
390
|
});
|
|
343
391
|
};
|
|
392
|
+
console.log('## folders in FolderTree', tempFolders, folders);
|
|
344
393
|
return (_jsxs(_Fragment, { children: [!screens.md && collapse && (_jsxs("div", { className: `md-lib-bg-textColorActive dark:md-lib-bg-darkSecondaryColor md-lib-p-1 md-lib-rounded md-lib-absolute md-lib-top-16 md-lib-left-1`, children: [" ", _jsx(FaAngleRightbtn, { size: 24, className: "md-lib-text-textColor dark:md-lib-text-darkTextColor", onClick: toggleMenu })] })), _jsxs("div", { className: `md-lib-border-r md-lib-inline-table md-lib-border-borderColor dark:md-lib-border-darkBorderColor md-lib-bg-white dark:md-lib-bg-darkPrimaryHoverColor md-lib-px-2 md-lib-pt-1 md-lib-max-h-[calc(100%-76px)] md-lib-overflow-x-auto ${!screens.md &&
|
|
345
394
|
"md-lib-absolute md-lib-left-0 md-lib-z-30 md-lib-h-full"} ${!screens.md && collapse && "!-md-lib-left-full"}`, children: [!screens.md && !collapse && (_jsxs("div", { className: `md-lib-bg-textColorActive dark:md-lib-bg-darkSecondaryColor md-lib-p-1 md-lib-rounded md-lib-absolute md-lib-top-1 md-lib-right-1 md-lib-z-50`, children: [" ", _jsx(FaAngleLeftbtn, { size: 24, className: "md-lib-text-textColor dark:md-lib-text-darkTextColor", onClick: toggleMenu })] })), _jsx("div", { className: "md-lib-mb-2", children: _jsx(Input, { placeholder: "Search files (min. 2 characters required)", onChange: (e) => setState((prevState) => {
|
|
346
395
|
return Object.assign(Object.assign({}, prevState), { globalSearchValue: e.target.value });
|
|
@@ -359,6 +408,6 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
359
408
|
}, icon: sortOrder == "desc" ? (_jsx(AiOutlineSortAscendingbtn, { className: "md-lib-cursor-pointer" })) : (_jsx(AiOutlineSortDescendingbtn, { className: "md-lib-cursor-pointer" })) }) })), sortMode === "custom" && !enableDrag && !globalSearch && (_jsx(Tooltip, { title: "Enable Drag", children: _jsx(Button, { icon: _jsx(GrSortIcon, {}), onClick: toggleEnableDrag }) })), enableDrag && (_jsxs("div", { className: "md-lib-flex md-lib-gap-2 md-lib-ml-2", children: [_jsx(Button, { type: "primary", onClick: handleSave, loading: isSorting, children: "Save" }), _jsx(Button, { onClick: handleCancel, children: "Cancel" })] })), loading && _jsx(CustomLoader, {})] }), _jsx(DirectoryTree, { treeData: getFoldersTree(sortMode === "custom" ? tempFolders : folders), draggable: {
|
|
360
409
|
icon: true,
|
|
361
410
|
nodeDraggable: (node) => sortMode === "custom" && enableDrag ? !(node === null || node === void 0 ? void 0 : node.parentId) : false,
|
|
362
|
-
}, onDrop: sortMode === "custom" && enableDrag ? onDrop : undefined, blockNode: true, showIcon: false, selectable: !enableDrag, selectedKeys: isArray(selectedKeys) ? selectedKeys : [selectedKeys], expandedKeys: expandedKeys, onSelect: handleSelect, onExpand:
|
|
411
|
+
}, onDrop: sortMode === "custom" && enableDrag ? onDrop : undefined, blockNode: true, showIcon: false, selectable: !enableDrag, selectedKeys: isArray(selectedKeys) ? selectedKeys : [selectedKeys], expandedKeys: expandedKeys, onSelect: handleSelect, onExpand: handleExpandWithFetch })] }), showConfirmationModal && (_jsx(DeleteConfirmationModal, { showDeleteModal: showConfirmationModal, toggleDeleteModal: toggleDeleteModal, okText: DELETE_OK_TEXT, description: DELETE_CONFIRMATION_MESSAGE.replace(":action", "delete").replace(":entity", get(selectedFolder, "name", "this folder")), onOk: onDeleteFolder, loading: loading })), showEditModal && (_jsx(AddFolder, { open: showEditModal, handleCancel: toggleEditModal, folder: selectedFolder }))] }));
|
|
363
412
|
}
|
|
364
413
|
export default FolderTree;
|
|
@@ -19,7 +19,7 @@ import { SUBSCRIPTION_EXPIRED_ERROR_MESSAGE } from "./appConstants";
|
|
|
19
19
|
const DamConfigContext = createContext(null);
|
|
20
20
|
export const DamConfigProvider = ({ children, config }) => {
|
|
21
21
|
// console.log(config);
|
|
22
|
-
const { damAccessKey, secretKey, subdomain, teamIds, appType, initialRootFolderId
|
|
22
|
+
const { damAccessKey, secretKey, subdomain, teamIds, appType, initialRootFolderId } = config;
|
|
23
23
|
const [accessToken, setAccessToken] = useState(null);
|
|
24
24
|
const [user, setDamUser] = useState(null);
|
|
25
25
|
const [brand, setBrand] = useState(null);
|