@bindu-dashing/dam-solution-v2 5.8.27 → 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.
|
@@ -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 || "" });
|
|
@@ -148,9 +168,57 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
148
168
|
});
|
|
149
169
|
}
|
|
150
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
|
+
};
|
|
151
185
|
// ✅ Load on mount & when currentRootId changes
|
|
186
|
+
// Use ref to track previous currentRootId to prevent unnecessary fetches
|
|
187
|
+
const prevCurrentRootIdRef = useRef(null);
|
|
152
188
|
useEffect(() => {
|
|
153
|
-
if (currentRootId) {
|
|
189
|
+
if (currentRootId && currentRootId !== prevCurrentRootIdRef.current) {
|
|
190
|
+
console.log('## FolderTree useEffect - currentRootId changed from', prevCurrentRootIdRef.current, 'to', currentRootId, 'rootFolderId:', rootFolderId);
|
|
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
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if (globalSearch !== globalSearchValue && currentRootId === rootFolderId) {
|
|
220
|
+
// Only refetch on global search change if we're on root folder
|
|
221
|
+
console.log('## FolderTree useEffect - globalSearch changed, refetching root folder');
|
|
154
222
|
fetchFolders(currentRootId);
|
|
155
223
|
}
|
|
156
224
|
}, [currentRootId, globalSearch]);
|
|
@@ -181,6 +249,7 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
181
249
|
const toggleEditModal = (folder = {}) => setState((prev) => (Object.assign(Object.assign({}, prev), { selectedFolder: folder, showEditModal: !prev.showEditModal })));
|
|
182
250
|
const toggleDeleteModal = (folder = {}) => setState((prev) => (Object.assign(Object.assign({}, prev), { selectedFolder: folder, showConfirmationModal: !prev.showConfirmationModal })));
|
|
183
251
|
const getFoldersTree = (folders = []) => {
|
|
252
|
+
console.log('## folders', folders);
|
|
184
253
|
const transform = (tree = []) => map(tree, (folder) => {
|
|
185
254
|
const key = get(folder, "_id", "");
|
|
186
255
|
const name = get(folder, "name", "");
|
|
@@ -228,6 +297,19 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
228
297
|
return get(item, "_id") !== rootFolderId;
|
|
229
298
|
});
|
|
230
299
|
}, [parentFolder]);
|
|
300
|
+
// Wrapper for handleExpand that also fetches children when a folder is expanded
|
|
301
|
+
const handleExpandWithFetch = (keys) => {
|
|
302
|
+
handleExpand(keys);
|
|
303
|
+
const newExpanded = map(keys, (k) => k.toString());
|
|
304
|
+
const currentExpanded = isArray(expandedKeys) ? expandedKeys : [expandedKeys].filter(Boolean);
|
|
305
|
+
const newlyExpanded = newExpanded.filter(id => !currentExpanded.includes(id));
|
|
306
|
+
// Fetch children for newly expanded folders using the same simple logic
|
|
307
|
+
newlyExpanded.forEach(expandedId => {
|
|
308
|
+
if (expandedId !== rootFolderId && expandedId !== currentRootId) {
|
|
309
|
+
fetchFolderChildren(expandedId);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
};
|
|
231
313
|
const handleSelect = (keys) => {
|
|
232
314
|
// console.log("keys", keys);
|
|
233
315
|
const selected = map(keys, (k) => k.toString());
|
|
@@ -236,6 +318,11 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
236
318
|
if (get(selected, "length") > 0) {
|
|
237
319
|
const selectedId = selected[get(selected, "length", 0) - 1];
|
|
238
320
|
// navigate(SUBFOLDERS_SCREEN.replace(":folderId", selectedId));
|
|
321
|
+
console.log('## selectedId', selectedId);
|
|
322
|
+
// If the selected folder is not the root folder, fetch its children
|
|
323
|
+
if (selectedId !== rootFolderId && selectedId !== currentRootId) {
|
|
324
|
+
fetchFolderChildren(selectedId);
|
|
325
|
+
}
|
|
239
326
|
}
|
|
240
327
|
};
|
|
241
328
|
useEffect(() => {
|
|
@@ -341,6 +428,7 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
341
428
|
return Object.assign(Object.assign({}, prevState), { tempFolders: cloneDeep(customSorted), sortMode: "custom", enableDrag: false });
|
|
342
429
|
});
|
|
343
430
|
};
|
|
431
|
+
console.log('## folders in FolderTree', tempFolders, folders);
|
|
344
432
|
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
433
|
"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
434
|
return Object.assign(Object.assign({}, prevState), { globalSearchValue: e.target.value });
|
|
@@ -359,6 +447,6 @@ function FolderTree({ currentRootId, expandedKeys, selectedKeys, handleExpand, s
|
|
|
359
447
|
}, 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
448
|
icon: true,
|
|
361
449
|
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:
|
|
450
|
+
}, 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
451
|
}
|
|
364
452
|
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);
|