@payloadcms/ui 3.42.0 → 3.43.0-internal.c5bbc84
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.
- package/dist/elements/CopyLocaleData/index.d.ts.map +1 -1
- package/dist/elements/CopyLocaleData/index.js +6 -1
- package/dist/elements/CopyLocaleData/index.js.map +1 -1
- package/dist/elements/FolderView/CollectionTypePill/index.d.ts.map +1 -1
- package/dist/elements/FolderView/CollectionTypePill/index.js +13 -10
- package/dist/elements/FolderView/CollectionTypePill/index.js.map +1 -1
- package/dist/elements/FolderView/CurrentFolderActions/index.d.ts.map +1 -1
- package/dist/elements/FolderView/CurrentFolderActions/index.js +17 -11
- package/dist/elements/FolderView/CurrentFolderActions/index.js.map +1 -1
- package/dist/elements/FolderView/Drawers/EditFolderAction/index.d.ts +1 -3
- package/dist/elements/FolderView/Drawers/EditFolderAction/index.d.ts.map +1 -1
- package/dist/elements/FolderView/Drawers/EditFolderAction/index.js +7 -4
- package/dist/elements/FolderView/Drawers/EditFolderAction/index.js.map +1 -1
- package/dist/elements/FolderView/Drawers/MoveToFolder/index.d.ts +1 -0
- package/dist/elements/FolderView/Drawers/MoveToFolder/index.d.ts.map +1 -1
- package/dist/elements/FolderView/Drawers/MoveToFolder/index.js +230 -201
- package/dist/elements/FolderView/Drawers/MoveToFolder/index.js.map +1 -1
- package/dist/elements/FolderView/FolderFileCard/index.d.ts +8 -0
- package/dist/elements/FolderView/FolderFileCard/index.d.ts.map +1 -1
- package/dist/elements/FolderView/FolderFileCard/index.js +82 -0
- package/dist/elements/FolderView/FolderFileCard/index.js.map +1 -1
- package/dist/elements/FolderView/FolderFileTable/index.d.ts +1 -22
- package/dist/elements/FolderView/FolderFileTable/index.d.ts.map +1 -1
- package/dist/elements/FolderView/FolderFileTable/index.js +245 -163
- package/dist/elements/FolderView/FolderFileTable/index.js.map +1 -1
- package/dist/elements/FolderView/ItemCardGrid/index.d.ts +2 -8
- package/dist/elements/FolderView/ItemCardGrid/index.d.ts.map +1 -1
- package/dist/elements/FolderView/ItemCardGrid/index.js +24 -90
- package/dist/elements/FolderView/ItemCardGrid/index.js.map +1 -1
- package/dist/elements/FolderView/SortByPill/index.d.ts.map +1 -1
- package/dist/elements/FolderView/SortByPill/index.js +17 -15
- package/dist/elements/FolderView/SortByPill/index.js.map +1 -1
- package/dist/elements/ListHeader/TitleActions/ListCreateNewDocInFolderButton.d.ts.map +1 -1
- package/dist/elements/ListHeader/TitleActions/ListCreateNewDocInFolderButton.js +8 -10
- package/dist/elements/ListHeader/TitleActions/ListCreateNewDocInFolderButton.js.map +1 -1
- package/dist/exports/client/index.js +22 -22
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/rsc/index.d.ts +1 -0
- package/dist/exports/rsc/index.d.ts.map +1 -1
- package/dist/exports/rsc/index.js +1 -0
- package/dist/exports/rsc/index.js.map +1 -1
- package/dist/fields/Relationship/Input.d.ts.map +1 -1
- package/dist/fields/Relationship/Input.js +1 -0
- package/dist/fields/Relationship/Input.js.map +1 -1
- package/dist/providers/Folders/index.d.ts +59 -46
- package/dist/providers/Folders/index.d.ts.map +1 -1
- package/dist/providers/Folders/index.js +163 -572
- package/dist/providers/Folders/index.js.map +1 -1
- package/dist/providers/ServerFunctions/index.d.ts +6 -1
- package/dist/providers/ServerFunctions/index.d.ts.map +1 -1
- package/dist/providers/ServerFunctions/index.js +19 -0
- package/dist/providers/ServerFunctions/index.js.map +1 -1
- package/dist/providers/TableColumns/index.js +1 -0
- package/dist/providers/TableColumns/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/getFolderResultsComponentAndData.d.ts +29 -0
- package/dist/utilities/getFolderResultsComponentAndData.d.ts.map +1 -0
- package/dist/utilities/getFolderResultsComponentAndData.js +128 -0
- package/dist/utilities/getFolderResultsComponentAndData.js.map +1 -0
- package/dist/views/BrowseByFolder/index.d.ts +1 -4
- package/dist/views/BrowseByFolder/index.d.ts.map +1 -1
- package/dist/views/BrowseByFolder/index.js +219 -158
- package/dist/views/BrowseByFolder/index.js.map +1 -1
- package/dist/views/CollectionFolder/ListSelection/index.d.ts.map +1 -1
- package/dist/views/CollectionFolder/ListSelection/index.js +25 -50
- package/dist/views/CollectionFolder/ListSelection/index.js.map +1 -1
- package/dist/views/CollectionFolder/index.d.ts +1 -1
- package/dist/views/CollectionFolder/index.d.ts.map +1 -1
- package/dist/views/CollectionFolder/index.js +186 -153
- package/dist/views/CollectionFolder/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,82 +1,68 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
-
import { useRouter } from 'next/navigation.js';
|
|
4
|
+
import { useRouter, useSearchParams } from 'next/navigation.js';
|
|
5
5
|
import { extractID, formatAdminURL, formatFolderOrDocumentItem } from 'payload/shared';
|
|
6
6
|
import * as qs from 'qs-esm';
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { toast } from 'sonner';
|
|
9
9
|
import { useDrawerDepth } from '../../elements/Drawer/index.js';
|
|
10
|
+
import { parseSearchParams } from '../../utilities/parseSearchParams.js';
|
|
10
11
|
import { useConfig } from '../Config/index.js';
|
|
11
12
|
import { useRouteTransition } from '../RouteTransition/index.js';
|
|
12
13
|
import { useTranslation } from '../Translation/index.js';
|
|
13
14
|
import { getMetaSelection, getShiftSelection, groupItemIDsByRelation } from './selection.js';
|
|
14
15
|
const Context = /*#__PURE__*/React.createContext({
|
|
15
|
-
|
|
16
|
+
activeCollectionFolderSlugs: [],
|
|
17
|
+
allCollectionFolderSlugs: [],
|
|
18
|
+
allowCreateCollectionSlugs: [],
|
|
16
19
|
breadcrumbs: [],
|
|
17
20
|
clearSelections: () => {},
|
|
18
21
|
currentFolder: null,
|
|
19
22
|
documents: [],
|
|
20
|
-
filterItems: () => undefined,
|
|
21
23
|
focusedRowIndex: -1,
|
|
22
24
|
folderCollectionConfig: null,
|
|
23
25
|
folderCollectionSlug: '',
|
|
24
|
-
folderCollectionSlugs: [],
|
|
25
26
|
folderFieldName: 'folder',
|
|
26
27
|
folderID: undefined,
|
|
28
|
+
FolderResultsComponent: null,
|
|
29
|
+
getFolderRoute: () => '',
|
|
27
30
|
getSelectedItems: () => [],
|
|
28
31
|
isDragging: false,
|
|
32
|
+
itemKeysToMove: undefined,
|
|
29
33
|
lastSelectedIndex: null,
|
|
30
34
|
moveToFolder: () => Promise.resolve(undefined),
|
|
31
35
|
onItemClick: () => undefined,
|
|
32
36
|
onItemKeyPress: () => undefined,
|
|
33
|
-
|
|
34
|
-
renameFolder: () => undefined,
|
|
37
|
+
refineFolderData: () => undefined,
|
|
35
38
|
search: '',
|
|
36
|
-
|
|
39
|
+
selectedItemKeys: new Set(),
|
|
37
40
|
setBreadcrumbs: () => {},
|
|
38
41
|
setFocusedRowIndex: () => -1,
|
|
39
|
-
setFolderID: () => null,
|
|
40
42
|
setIsDragging: () => false,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
sortOn: '_folderOrDocumentTitle',
|
|
44
|
-
subfolders: [],
|
|
45
|
-
visibleCollectionSlugs: []
|
|
43
|
+
sort: '_folderOrDocumentTitle',
|
|
44
|
+
subfolders: []
|
|
46
45
|
});
|
|
47
|
-
function filterOutItems({
|
|
48
|
-
items,
|
|
49
|
-
relationTo,
|
|
50
|
-
search
|
|
51
|
-
}) {
|
|
52
|
-
if (typeof search !== 'string' && relationTo === undefined) {
|
|
53
|
-
return items;
|
|
54
|
-
}
|
|
55
|
-
const searchLower = (search || '').toLowerCase();
|
|
56
|
-
return items.filter(item => {
|
|
57
|
-
const itemTitle = item.value._folderOrDocumentTitle.toLowerCase();
|
|
58
|
-
const itemRelationTo = item.relationTo;
|
|
59
|
-
return (relationTo ? relationTo.includes(itemRelationTo) : true) && (!searchLower || itemTitle.includes(searchLower));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
46
|
export function FolderProvider({
|
|
47
|
+
activeCollectionFolderSlugs: activeCollectionSlugs,
|
|
48
|
+
allCollectionFolderSlugs = [],
|
|
49
|
+
allowCreateCollectionSlugs,
|
|
63
50
|
allowMultiSelection = true,
|
|
51
|
+
baseFolderPath,
|
|
64
52
|
breadcrumbs: _breadcrumbsFromProps = [],
|
|
65
53
|
children,
|
|
66
|
-
|
|
67
|
-
documents: allDocumentsFromProps = [],
|
|
68
|
-
filteredCollectionSlugs,
|
|
69
|
-
folderCollectionSlugs = [],
|
|
54
|
+
documents,
|
|
70
55
|
folderFieldName,
|
|
71
|
-
folderID
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
56
|
+
folderID,
|
|
57
|
+
FolderResultsComponent: InitialFolderResultsComponent,
|
|
58
|
+
onItemClick: onItemClickFromProps,
|
|
59
|
+
search,
|
|
60
|
+
sort = '_folderOrDocumentTitle',
|
|
61
|
+
subfolders
|
|
75
62
|
}) {
|
|
76
63
|
const parentFolderContext = useFolder();
|
|
77
64
|
const {
|
|
78
|
-
config
|
|
79
|
-
getEntityConfig
|
|
65
|
+
config
|
|
80
66
|
} = useConfig();
|
|
81
67
|
const {
|
|
82
68
|
routes,
|
|
@@ -90,154 +76,102 @@ export function FolderProvider({
|
|
|
90
76
|
const {
|
|
91
77
|
startRouteTransition
|
|
92
78
|
} = useRouteTransition();
|
|
79
|
+
const [FolderResultsComponent, setFolderResultsComponent] = React.useState(InitialFolderResultsComponent || (() => null));
|
|
93
80
|
const [folderCollectionConfig] = React.useState(() => config.collections.find(collection => config.folders && collection.slug === config.folders.slug));
|
|
94
81
|
const folderCollectionSlug = folderCollectionConfig.slug;
|
|
82
|
+
const rawSearchParams = useSearchParams();
|
|
83
|
+
const searchParams = React.useMemo(() => parseSearchParams(rawSearchParams), [rawSearchParams]);
|
|
84
|
+
const [currentQuery, setCurrentQuery] = React.useState(searchParams);
|
|
95
85
|
const [isDragging, setIsDragging] = React.useState(false);
|
|
96
|
-
const [
|
|
86
|
+
const [selectedItemKeys, setSelectedItemKeys] = React.useState(() => new Set());
|
|
97
87
|
const [focusedRowIndex, setFocusedRowIndex] = React.useState(-1);
|
|
98
88
|
const [lastSelectedIndex, setLastSelectedIndex] = React.useState(null);
|
|
99
|
-
const [visibleCollectionSlugs, setVisibleCollectionSlugs] = React.useState(filteredCollectionSlugs || [...folderCollectionSlugs, folderCollectionSlug]);
|
|
100
|
-
const [activeFolderID, setActiveFolderID] = React.useState(_folderIDFromProps);
|
|
101
89
|
const [breadcrumbs, setBreadcrumbs] = React.useState(_breadcrumbsFromProps);
|
|
102
|
-
const [allSubfolders, setAllSubfolders] = React.useState(subfoldersFromProps);
|
|
103
|
-
const [subfolders, setSubfolders] = React.useState(() => {
|
|
104
|
-
return filterOutItems({
|
|
105
|
-
items: allSubfolders,
|
|
106
|
-
relationTo: visibleCollectionSlugs.includes(folderCollectionSlug) ? [folderCollectionSlug] : [],
|
|
107
|
-
search: _searchFromProps
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
const [allDocuments, setAllDocuments] = React.useState(allDocumentsFromProps);
|
|
111
|
-
const [documents, setDocuments] = React.useState(() => filterOutItems({
|
|
112
|
-
items: allDocuments,
|
|
113
|
-
relationTo: visibleCollectionSlugs,
|
|
114
|
-
search: _searchFromProps
|
|
115
|
-
}));
|
|
116
|
-
const [search, setSearch] = React.useState(_searchFromProps);
|
|
117
|
-
const [baseFolderPath] = React.useState(() => {
|
|
118
|
-
if (collectionSlug) {
|
|
119
|
-
return `/collections/${collectionSlug}/${folderCollectionSlug}`;
|
|
120
|
-
} else {
|
|
121
|
-
return config.admin.routes.browseByFolder;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
const [sortDirection, setSortDirection] = React.useState(() => {
|
|
125
|
-
if (sort) {
|
|
126
|
-
return sort.startsWith('-') ? 'desc' : 'asc';
|
|
127
|
-
}
|
|
128
|
-
return 'asc';
|
|
129
|
-
});
|
|
130
|
-
const [sortOn, setSortOn] = React.useState(() => {
|
|
131
|
-
if (sort) {
|
|
132
|
-
return sort.replace(/^-/, '');
|
|
133
|
-
}
|
|
134
|
-
return '_folderOrDocumentTitle';
|
|
135
|
-
});
|
|
136
90
|
const lastClickTime = React.useRef(null);
|
|
137
91
|
const totalCount = subfolders.length + documents.length;
|
|
138
|
-
const formatFolderURL = React.useCallback(args => {
|
|
139
|
-
const newFolderID = 'folderID' in args ? args.folderID : activeFolderID;
|
|
140
|
-
const params = {
|
|
141
|
-
relationTo: 'relationTo' in args ? args.relationTo : collectionSlug ? undefined : visibleCollectionSlugs,
|
|
142
|
-
search: 'search' in args ? args.search : search,
|
|
143
|
-
sortBy: 'sortBy' in args ? args.sortBy : sortOn,
|
|
144
|
-
sortDirection: 'sortDirection' in args ? args.sortDirection : sortDirection
|
|
145
|
-
};
|
|
146
|
-
return formatAdminURL({
|
|
147
|
-
adminRoute: config.routes.admin,
|
|
148
|
-
path: `${baseFolderPath}${newFolderID ? `/${newFolderID}` : ''}${qs.stringify(params, {
|
|
149
|
-
addQueryPrefix: true
|
|
150
|
-
})}`
|
|
151
|
-
});
|
|
152
|
-
}, [activeFolderID, baseFolderPath, collectionSlug, config.routes.admin, search, sortDirection, sortOn, visibleCollectionSlugs]);
|
|
153
92
|
const clearSelections = React.useCallback(() => {
|
|
154
93
|
setFocusedRowIndex(-1);
|
|
155
|
-
|
|
94
|
+
setSelectedItemKeys(new Set());
|
|
156
95
|
setLastSelectedIndex(undefined);
|
|
157
96
|
}, []);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
97
|
+
const mergeQuery = React.useCallback((newQuery = {}) => {
|
|
98
|
+
let page = 'page' in newQuery ? newQuery.page : currentQuery?.page;
|
|
99
|
+
if ('search' in newQuery) {
|
|
100
|
+
page = '1';
|
|
101
|
+
}
|
|
102
|
+
const mergedQuery = {
|
|
103
|
+
...currentQuery,
|
|
104
|
+
...newQuery,
|
|
105
|
+
page,
|
|
106
|
+
search: 'search' in newQuery ? newQuery.search : currentQuery?.search,
|
|
107
|
+
sort: 'sort' in newQuery ? newQuery.sort : currentQuery?.sort ?? undefined
|
|
108
|
+
};
|
|
109
|
+
return mergedQuery;
|
|
110
|
+
}, [currentQuery]);
|
|
111
|
+
const refineFolderData = React.useCallback(({
|
|
112
|
+
query,
|
|
113
|
+
updateURL
|
|
166
114
|
}) => {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
115
|
+
if (updateURL) {
|
|
116
|
+
const newQuery_0 = mergeQuery(query);
|
|
117
|
+
startRouteTransition(() => router.replace(`${qs.stringify(newQuery_0, {
|
|
118
|
+
addQueryPrefix: true
|
|
119
|
+
})}`));
|
|
120
|
+
setCurrentQuery(newQuery_0);
|
|
121
|
+
}
|
|
122
|
+
}, [mergeQuery, router, startRouteTransition]);
|
|
123
|
+
const getFolderRoute = React.useCallback(toFolderID => {
|
|
124
|
+
const newQuery_1 = mergeQuery({
|
|
125
|
+
page: '1',
|
|
126
|
+
search: ''
|
|
175
127
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
128
|
+
return formatAdminURL({
|
|
129
|
+
adminRoute: config.routes.admin,
|
|
130
|
+
path: `${baseFolderPath}${toFolderID ? `/${toFolderID}` : ''}${qs.stringify(newQuery_1, {
|
|
131
|
+
addQueryPrefix: true
|
|
132
|
+
})}`,
|
|
133
|
+
serverURL: config.serverURL
|
|
181
134
|
});
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return folderDataRes;
|
|
187
|
-
} else {
|
|
188
|
-
return {
|
|
189
|
-
breadcrumbs: [],
|
|
190
|
-
documents: [],
|
|
191
|
-
subfolders: []
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
}, [folderCollectionSlug, search, routes.api, serverURL, collectionSlug]);
|
|
195
|
-
const setNewActiveFolderID = React.useCallback(async ({
|
|
196
|
-
folderID: toFolderID
|
|
197
|
-
}) => {
|
|
198
|
-
clearSelections();
|
|
199
|
-
if (drawerDepth === 1) {
|
|
200
|
-
// not in a drawer (default is 1)
|
|
201
|
-
startRouteTransition(() => router.push(formatFolderURL({
|
|
202
|
-
folderID: toFolderID
|
|
203
|
-
})));
|
|
204
|
-
} else {
|
|
205
|
-
const folderDataRes_0 = await getFolderData({
|
|
206
|
-
folderID: toFolderID
|
|
207
|
-
});
|
|
208
|
-
setBreadcrumbs(folderDataRes_0?.breadcrumbs || []);
|
|
209
|
-
setSubfolders(folderDataRes_0?.subfolders || []);
|
|
210
|
-
setDocuments(folderDataRes_0?.documents || []);
|
|
211
|
-
setActiveFolderID(toFolderID);
|
|
212
|
-
}
|
|
213
|
-
}, [clearSelections, drawerDepth, startRouteTransition, router, formatFolderURL, getFolderData]);
|
|
135
|
+
}, [baseFolderPath, config.routes.admin, config.serverURL, mergeQuery]);
|
|
136
|
+
const getItem = React.useCallback(itemKey => {
|
|
137
|
+
return [...subfolders, ...documents].find(doc => doc.itemKey === itemKey);
|
|
138
|
+
}, [documents, subfolders]);
|
|
214
139
|
const getSelectedItems = React.useCallback(() => {
|
|
215
|
-
return Array.from(
|
|
216
|
-
const item =
|
|
140
|
+
return Array.from(selectedItemKeys).reduce((acc, itemKey_0) => {
|
|
141
|
+
const item = getItem(itemKey_0);
|
|
217
142
|
if (item) {
|
|
218
143
|
acc.push(item);
|
|
219
144
|
}
|
|
220
145
|
return acc;
|
|
221
146
|
}, []);
|
|
222
|
-
}, [
|
|
223
|
-
const navigateAfterSelection = React.useCallback(
|
|
224
|
-
collectionSlug
|
|
147
|
+
}, [selectedItemKeys, getItem]);
|
|
148
|
+
const navigateAfterSelection = React.useCallback(({
|
|
149
|
+
collectionSlug,
|
|
225
150
|
docID
|
|
226
151
|
}) => {
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
152
|
+
if (drawerDepth === 1) {
|
|
153
|
+
// not in a drawer (default is 1)
|
|
154
|
+
clearSelections();
|
|
155
|
+
if (collectionSlug === folderCollectionSlug) {
|
|
156
|
+
// clicked on folder, take the user to the folder view
|
|
157
|
+
startRouteTransition(() => router.push(getFolderRoute(docID)));
|
|
158
|
+
} else if (collectionSlug) {
|
|
159
|
+
// clicked on document, take the user to the documet view
|
|
160
|
+
startRouteTransition(() => {
|
|
161
|
+
router.push(formatAdminURL({
|
|
162
|
+
adminRoute: config.routes.admin,
|
|
163
|
+
path: `/collections/${collectionSlug}/${docID}`
|
|
164
|
+
}));
|
|
165
|
+
});
|
|
166
|
+
}
|
|
236
167
|
}
|
|
237
|
-
|
|
238
|
-
|
|
168
|
+
if (typeof onItemClickFromProps === 'function') {
|
|
169
|
+
onItemClickFromProps(getItem(`${collectionSlug}-${docID}`));
|
|
170
|
+
}
|
|
171
|
+
}, [clearSelections, config.routes.admin, drawerDepth, folderCollectionSlug, getFolderRoute, getItem, onItemClickFromProps, router, startRouteTransition]);
|
|
172
|
+
const onItemKeyPress = React.useCallback(({
|
|
239
173
|
event,
|
|
240
|
-
index
|
|
174
|
+
index,
|
|
241
175
|
item: item_0
|
|
242
176
|
}) => {
|
|
243
177
|
const {
|
|
@@ -248,12 +182,12 @@ export function FolderProvider({
|
|
|
248
182
|
} = event;
|
|
249
183
|
const isShiftPressed = shiftKey;
|
|
250
184
|
const isCtrlPressed = ctrlKey || metaKey;
|
|
251
|
-
let newSelectedIndexes =
|
|
185
|
+
let newSelectedIndexes = undefined;
|
|
252
186
|
switch (code) {
|
|
253
187
|
case 'ArrowDown':
|
|
254
188
|
{
|
|
255
189
|
event.preventDefault();
|
|
256
|
-
const nextIndex_0 = Math.min(
|
|
190
|
+
const nextIndex_0 = Math.min(index + 1, totalCount - 1);
|
|
257
191
|
setFocusedRowIndex(nextIndex_0);
|
|
258
192
|
if (isCtrlPressed) {
|
|
259
193
|
break;
|
|
@@ -272,7 +206,7 @@ export function FolderProvider({
|
|
|
272
206
|
case 'ArrowUp':
|
|
273
207
|
{
|
|
274
208
|
event.preventDefault();
|
|
275
|
-
const prevIndex_0 = Math.max(
|
|
209
|
+
const prevIndex_0 = Math.max(index - 1, 0);
|
|
276
210
|
setFocusedRowIndex(prevIndex_0);
|
|
277
211
|
if (isCtrlPressed) {
|
|
278
212
|
break;
|
|
@@ -290,7 +224,7 @@ export function FolderProvider({
|
|
|
290
224
|
}
|
|
291
225
|
case 'Enter':
|
|
292
226
|
{
|
|
293
|
-
if (
|
|
227
|
+
if (selectedItemKeys.size === 1) {
|
|
294
228
|
newSelectedIndexes = new Set([]);
|
|
295
229
|
setFocusedRowIndex(undefined);
|
|
296
230
|
}
|
|
@@ -299,7 +233,6 @@ export function FolderProvider({
|
|
|
299
233
|
case 'Escape':
|
|
300
234
|
{
|
|
301
235
|
setFocusedRowIndex(undefined);
|
|
302
|
-
setSelectedIndexes(new Set([]));
|
|
303
236
|
newSelectedIndexes = new Set([]);
|
|
304
237
|
break;
|
|
305
238
|
}
|
|
@@ -320,49 +253,57 @@ export function FolderProvider({
|
|
|
320
253
|
event.preventDefault();
|
|
321
254
|
newSelectedIndexes = getMetaSelection({
|
|
322
255
|
currentSelection: newSelectedIndexes,
|
|
323
|
-
toggleIndex:
|
|
256
|
+
toggleIndex: index
|
|
324
257
|
});
|
|
325
|
-
setLastSelectedIndex(
|
|
258
|
+
setLastSelectedIndex(index);
|
|
326
259
|
} else {
|
|
327
260
|
event.preventDefault();
|
|
328
|
-
newSelectedIndexes = new Set([
|
|
329
|
-
setLastSelectedIndex(
|
|
261
|
+
newSelectedIndexes = new Set([index]);
|
|
262
|
+
setLastSelectedIndex(index);
|
|
330
263
|
}
|
|
331
264
|
break;
|
|
332
265
|
}
|
|
333
266
|
case 'Tab':
|
|
334
267
|
{
|
|
335
268
|
if (allowMultiSelection && isShiftPressed) {
|
|
336
|
-
const prevIndex =
|
|
337
|
-
if (prevIndex < 0 && newSelectedIndexes
|
|
269
|
+
const prevIndex = index - 1;
|
|
270
|
+
if (prevIndex < 0 && newSelectedIndexes?.size > 0) {
|
|
338
271
|
setFocusedRowIndex(prevIndex);
|
|
339
272
|
}
|
|
340
273
|
} else {
|
|
341
|
-
const nextIndex =
|
|
342
|
-
if (nextIndex === totalCount &&
|
|
274
|
+
const nextIndex = index + 1;
|
|
275
|
+
if (nextIndex === totalCount && selectedItemKeys.size > 0) {
|
|
343
276
|
setFocusedRowIndex(totalCount - 1);
|
|
344
277
|
}
|
|
345
278
|
}
|
|
346
279
|
break;
|
|
347
280
|
}
|
|
348
281
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
282
|
+
if (!newSelectedIndexes) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
setSelectedItemKeys([...subfolders, ...documents].reduce((acc_0, item_1, index_0) => {
|
|
286
|
+
if (newSelectedIndexes?.size && newSelectedIndexes.has(index_0)) {
|
|
287
|
+
acc_0.add(item_1.itemKey);
|
|
288
|
+
}
|
|
289
|
+
return acc_0;
|
|
290
|
+
}, new Set()));
|
|
291
|
+
if (selectedItemKeys.size === 1 && code === 'Enter') {
|
|
292
|
+
navigateAfterSelection({
|
|
352
293
|
collectionSlug: item_0.relationTo,
|
|
353
294
|
docID: extractID(item_0.value)
|
|
354
295
|
});
|
|
355
296
|
}
|
|
356
|
-
}, [allowMultiSelection, lastSelectedIndex, navigateAfterSelection,
|
|
357
|
-
const onItemClick = React.useCallback(
|
|
297
|
+
}, [allowMultiSelection, documents, lastSelectedIndex, navigateAfterSelection, subfolders, totalCount, selectedItemKeys]);
|
|
298
|
+
const onItemClick = React.useCallback(({
|
|
358
299
|
event: event_0,
|
|
359
300
|
index: index_1,
|
|
360
|
-
item:
|
|
301
|
+
item: item_2
|
|
361
302
|
}) => {
|
|
362
303
|
let doubleClicked = false;
|
|
363
304
|
const isCtrlPressed_0 = event_0.ctrlKey || event_0.metaKey;
|
|
364
305
|
const isShiftPressed_0 = event_0.shiftKey;
|
|
365
|
-
let newSelectedIndexes_0 =
|
|
306
|
+
let newSelectedIndexes_0 = undefined;
|
|
366
307
|
if (allowMultiSelection && isCtrlPressed_0) {
|
|
367
308
|
newSelectedIndexes_0 = getMetaSelection({
|
|
368
309
|
currentSelection: newSelectedIndexes_0,
|
|
@@ -375,7 +316,7 @@ export function FolderProvider({
|
|
|
375
316
|
});
|
|
376
317
|
} else if (allowMultiSelection && event_0.type === 'pointermove') {
|
|
377
318
|
// on drag start of an unselected item
|
|
378
|
-
if (!
|
|
319
|
+
if (!selectedItemKeys.has(item_2.itemKey)) {
|
|
379
320
|
newSelectedIndexes_0 = new Set([index_1]);
|
|
380
321
|
}
|
|
381
322
|
setLastSelectedIndex(index_1);
|
|
@@ -387,277 +328,42 @@ export function FolderProvider({
|
|
|
387
328
|
lastClickTime.current = now;
|
|
388
329
|
setLastSelectedIndex(index_1);
|
|
389
330
|
}
|
|
390
|
-
if (newSelectedIndexes_0
|
|
331
|
+
if (!newSelectedIndexes_0) {
|
|
391
332
|
setFocusedRowIndex(undefined);
|
|
392
333
|
} else {
|
|
393
334
|
setFocusedRowIndex(index_1);
|
|
394
335
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
docID: extractID(item_1.value)
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
}, [selectedIndexes, lastSelectedIndex, allowMultiSelection, navigateAfterSelection]);
|
|
403
|
-
const filterItems = React.useCallback(async ({
|
|
404
|
-
relationTo: _relationTo,
|
|
405
|
-
search: _search_0
|
|
406
|
-
}) => {
|
|
407
|
-
const relationTo = Array.isArray(_relationTo) ? _relationTo : visibleCollectionSlugs;
|
|
408
|
-
const searchFilter_0 = ((typeof _search_0 === 'string' ? _search_0 : search) || '').trim();
|
|
409
|
-
let filteredDocuments = allDocuments;
|
|
410
|
-
let filteredSubfolders = allSubfolders;
|
|
411
|
-
if (collectionSlug && !activeFolderID && _search_0 !== search) {
|
|
412
|
-
// this allows us to search all documents in the collection when we are not in a folder and in the folder-collection view
|
|
413
|
-
const res = await getFolderData({
|
|
414
|
-
folderID: activeFolderID,
|
|
415
|
-
search: searchFilter_0
|
|
416
|
-
});
|
|
417
|
-
filteredDocuments = filterOutItems({
|
|
418
|
-
items: res.documents,
|
|
419
|
-
relationTo,
|
|
420
|
-
search: searchFilter_0
|
|
421
|
-
});
|
|
422
|
-
filteredSubfolders = filterOutItems({
|
|
423
|
-
items: res.subfolders,
|
|
424
|
-
relationTo: [folderCollectionSlug],
|
|
425
|
-
search: searchFilter_0
|
|
426
|
-
});
|
|
427
|
-
} else {
|
|
428
|
-
filteredDocuments = filterOutItems({
|
|
429
|
-
items: allDocuments,
|
|
430
|
-
relationTo,
|
|
431
|
-
search: searchFilter_0
|
|
432
|
-
});
|
|
433
|
-
filteredSubfolders = filterOutItems({
|
|
434
|
-
items: allSubfolders,
|
|
435
|
-
relationTo: relationTo.includes(folderCollectionSlug) ? [folderCollectionSlug] : [],
|
|
436
|
-
search: searchFilter_0
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
setDocuments(filteredDocuments);
|
|
440
|
-
setSubfolders(filteredSubfolders);
|
|
441
|
-
setSearch(searchFilter_0);
|
|
442
|
-
setVisibleCollectionSlugs(relationTo);
|
|
443
|
-
if (drawerDepth === 1) {
|
|
444
|
-
router.replace(formatFolderURL({
|
|
445
|
-
relationTo,
|
|
446
|
-
search: searchFilter_0 || undefined
|
|
447
|
-
}));
|
|
448
|
-
}
|
|
449
|
-
}, [collectionSlug, visibleCollectionSlugs, search, activeFolderID, allDocuments, allSubfolders, folderCollectionSlug, drawerDepth, getFolderData, router, formatFolderURL]);
|
|
450
|
-
const sortItems = React.useCallback(({
|
|
451
|
-
documentsToSort,
|
|
452
|
-
sortDirection: sortDirectionArg,
|
|
453
|
-
sortOn: sortOnArg,
|
|
454
|
-
subfoldersToSort
|
|
455
|
-
}) => {
|
|
456
|
-
let sortedDocuments;
|
|
457
|
-
let sortedSubfolders;
|
|
458
|
-
const sortDirectionToUse = sortDirectionArg || sortDirection;
|
|
459
|
-
const sortOnToUse = sortOnArg || sortOn;
|
|
460
|
-
if (sortOnArg) {
|
|
461
|
-
setSortOn(sortOnArg);
|
|
462
|
-
}
|
|
463
|
-
if (sortDirectionArg) {
|
|
464
|
-
setSortDirection(sortDirectionArg);
|
|
465
|
-
}
|
|
466
|
-
const newURL = formatFolderURL({
|
|
467
|
-
sortBy: sortOnArg || sortOn,
|
|
468
|
-
sortDirection: sortDirectionArg || sortDirection
|
|
469
|
-
});
|
|
470
|
-
if (documentsToSort) {
|
|
471
|
-
sortedDocuments = [...documentsToSort].sort((a, b) => {
|
|
472
|
-
const aValue = a.value[sortOnToUse];
|
|
473
|
-
const bValue = b.value[sortOnToUse];
|
|
474
|
-
if (aValue == null && bValue == null) {
|
|
475
|
-
return 0;
|
|
476
|
-
}
|
|
477
|
-
if (aValue == null) {
|
|
478
|
-
return sortDirectionToUse === 'asc' ? 1 : -1;
|
|
479
|
-
}
|
|
480
|
-
if (bValue == null) {
|
|
481
|
-
return sortDirectionToUse === 'asc' ? -1 : 1;
|
|
482
|
-
}
|
|
483
|
-
if (typeof aValue === 'string' && typeof bValue === 'string') {
|
|
484
|
-
return sortDirectionToUse === 'asc' ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
|
485
|
-
}
|
|
486
|
-
return 0;
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
if (subfoldersToSort) {
|
|
490
|
-
sortedSubfolders = [...subfoldersToSort].sort((a_0, b_0) => {
|
|
491
|
-
const aValue_0 = a_0.value[sortOnToUse];
|
|
492
|
-
const bValue_0 = b_0.value[sortOnToUse];
|
|
493
|
-
if (aValue_0 == null && bValue_0 == null) {
|
|
494
|
-
return 0;
|
|
336
|
+
if (newSelectedIndexes_0) {
|
|
337
|
+
setSelectedItemKeys([...subfolders, ...documents].reduce((acc_1, item_3, index_2) => {
|
|
338
|
+
if (newSelectedIndexes_0.size && newSelectedIndexes_0.has(index_2)) {
|
|
339
|
+
acc_1.add(item_3.itemKey);
|
|
495
340
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
if (bValue_0 == null) {
|
|
500
|
-
return sortDirectionToUse === 'asc' ? -1 : 1;
|
|
501
|
-
}
|
|
502
|
-
if (typeof aValue_0 === 'string' && typeof bValue_0 === 'string') {
|
|
503
|
-
return sortDirectionToUse === 'asc' ? aValue_0.localeCompare(bValue_0) : bValue_0.localeCompare(aValue_0);
|
|
504
|
-
}
|
|
505
|
-
return 0;
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
return {
|
|
509
|
-
newURL,
|
|
510
|
-
sortedDocuments,
|
|
511
|
-
sortedSubfolders
|
|
512
|
-
};
|
|
513
|
-
}, [formatFolderURL, sortDirection, sortOn]);
|
|
514
|
-
const sortAndUpdateState = React.useCallback(({
|
|
515
|
-
documentsToSort: documentsToSort_0,
|
|
516
|
-
sortDirection: sortDirectionArg_0,
|
|
517
|
-
sortOn: sortOnArg_0,
|
|
518
|
-
subfoldersToSort: subfoldersToSort_0
|
|
519
|
-
}) => {
|
|
520
|
-
const {
|
|
521
|
-
newURL: newURL_0,
|
|
522
|
-
sortedDocuments: sortedDocuments_0,
|
|
523
|
-
sortedSubfolders: sortedSubfolders_0
|
|
524
|
-
} = sortItems({
|
|
525
|
-
documentsToSort: documentsToSort_0,
|
|
526
|
-
sortDirection: sortDirectionArg_0,
|
|
527
|
-
sortOn: sortOnArg_0,
|
|
528
|
-
subfoldersToSort: subfoldersToSort_0
|
|
529
|
-
});
|
|
530
|
-
if (sortedDocuments_0) {
|
|
531
|
-
setDocuments(sortedDocuments_0);
|
|
341
|
+
return acc_1;
|
|
342
|
+
}, new Set()));
|
|
532
343
|
}
|
|
533
|
-
if (
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
// not in a drawer (default is 1)
|
|
538
|
-
startRouteTransition(() => {
|
|
539
|
-
router.replace(newURL_0);
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
}, [drawerDepth, router, sortItems, startRouteTransition]);
|
|
543
|
-
const separateItems = React.useCallback(items => {
|
|
544
|
-
return items.reduce((acc_0, item_2) => {
|
|
545
|
-
if (item_2.relationTo === folderCollectionSlug) {
|
|
546
|
-
acc_0.folders.push(item_2);
|
|
547
|
-
} else {
|
|
548
|
-
acc_0.documents.push(item_2);
|
|
549
|
-
}
|
|
550
|
-
return acc_0;
|
|
551
|
-
}, {
|
|
552
|
-
documents: [],
|
|
553
|
-
folders: []
|
|
554
|
-
});
|
|
555
|
-
}, [folderCollectionSlug]);
|
|
556
|
-
/**
|
|
557
|
-
* Used to remove items from the current state.
|
|
558
|
-
*
|
|
559
|
-
* Does NOT handle the request to the server.
|
|
560
|
-
* Useful when a document is deleted and it needs to be removed
|
|
561
|
-
* from the current state.
|
|
562
|
-
*/
|
|
563
|
-
const removeItems = React.useCallback(items_0 => {
|
|
564
|
-
if (!items_0.length) {
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
const separatedItems = separateItems(items_0);
|
|
568
|
-
if (separatedItems.documents.length) {
|
|
569
|
-
setDocuments(prevDocs => {
|
|
570
|
-
return prevDocs.filter(({
|
|
571
|
-
itemKey
|
|
572
|
-
}) => !separatedItems.documents.some(item_3 => item_3.itemKey === itemKey));
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
if (separatedItems.folders.length) {
|
|
576
|
-
setSubfolders(prevFolders => {
|
|
577
|
-
return prevFolders.filter(({
|
|
578
|
-
itemKey: itemKey_0
|
|
579
|
-
}) => !separatedItems.folders.some(item_4 => item_4.itemKey === itemKey_0));
|
|
344
|
+
if (doubleClicked) {
|
|
345
|
+
navigateAfterSelection({
|
|
346
|
+
collectionSlug: item_2.relationTo,
|
|
347
|
+
docID: extractID(item_2.value)
|
|
580
348
|
});
|
|
581
349
|
}
|
|
582
|
-
|
|
583
|
-
}, [clearSelections, separateItems, setDocuments, setSubfolders]);
|
|
584
|
-
/**
|
|
585
|
-
* Used to add items to the current state.
|
|
586
|
-
*
|
|
587
|
-
* Does NOT handle the request to the server.
|
|
588
|
-
* Used when a document needs to be added to the current state.
|
|
589
|
-
*/
|
|
590
|
-
const addItems = React.useCallback(itemsToAdd => {
|
|
591
|
-
const {
|
|
592
|
-
items: items_1,
|
|
593
|
-
parentItems
|
|
594
|
-
} = itemsToAdd.reduce((acc_1, item_5) => {
|
|
595
|
-
const destinationFolderID = item_5.value.folderID || null;
|
|
596
|
-
if (item_5.value.folderID && item_5.value.folderID === activeFolderID || !activeFolderID && !item_5.value.folderID) {
|
|
597
|
-
acc_1.items.push(item_5);
|
|
598
|
-
}
|
|
599
|
-
if (parentFolderContext && (parentFolderContext.folderID && destinationFolderID === parentFolderContext.folderID || !parentFolderContext.folderID && !item_5.value.folderID)) {
|
|
600
|
-
acc_1.parentItems.push(item_5);
|
|
601
|
-
}
|
|
602
|
-
return acc_1;
|
|
603
|
-
}, {
|
|
604
|
-
items: [],
|
|
605
|
-
parentItems: []
|
|
606
|
-
});
|
|
607
|
-
if (parentItems.length) {
|
|
608
|
-
parentFolderContext.addItems(parentItems);
|
|
609
|
-
}
|
|
610
|
-
if (!items_1.length) {
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
const separatedItems_0 = separateItems(items_1);
|
|
614
|
-
let documentsToSort_1 = undefined;
|
|
615
|
-
let subfoldersToSort_1 = undefined;
|
|
616
|
-
if (separatedItems_0.documents.length) {
|
|
617
|
-
documentsToSort_1 = [...documents, ...separatedItems_0.documents];
|
|
618
|
-
}
|
|
619
|
-
if (separatedItems_0.folders.length) {
|
|
620
|
-
subfoldersToSort_1 = [...subfolders, ...separatedItems_0.folders];
|
|
621
|
-
}
|
|
622
|
-
const {
|
|
623
|
-
sortedDocuments: sortedDocuments_1,
|
|
624
|
-
sortedSubfolders: sortedSubfolders_1
|
|
625
|
-
} = sortItems({
|
|
626
|
-
documentsToSort: documentsToSort_1,
|
|
627
|
-
subfoldersToSort: subfoldersToSort_1
|
|
628
|
-
});
|
|
629
|
-
const {
|
|
630
|
-
sortedDocuments: sortedAllDocuments,
|
|
631
|
-
sortedSubfolders: sortedAllSubfolders
|
|
632
|
-
} = sortItems({
|
|
633
|
-
documentsToSort: documentsToSort_1,
|
|
634
|
-
subfoldersToSort: subfoldersToSort_1
|
|
635
|
-
});
|
|
636
|
-
if (sortedDocuments_1) {
|
|
637
|
-
setDocuments(sortedDocuments_1);
|
|
638
|
-
setAllDocuments(sortedAllDocuments);
|
|
639
|
-
}
|
|
640
|
-
if (sortedSubfolders_1) {
|
|
641
|
-
setSubfolders(sortedSubfolders_1);
|
|
642
|
-
setAllSubfolders(sortedAllSubfolders);
|
|
643
|
-
}
|
|
644
|
-
}, [activeFolderID, documents, separateItems, sortItems, subfolders, parentFolderContext]);
|
|
350
|
+
}, [selectedItemKeys, allowMultiSelection, lastSelectedIndex, subfolders, documents, navigateAfterSelection]);
|
|
645
351
|
/**
|
|
646
|
-
*
|
|
352
|
+
* Makes requests to the server to update the folder field on passed in documents
|
|
647
353
|
*
|
|
648
|
-
*
|
|
354
|
+
* Might rewrite this in the future to return the promises so errors can be handled contextually
|
|
649
355
|
*/
|
|
650
|
-
const moveToFolder = React.useCallback(async
|
|
356
|
+
const moveToFolder = React.useCallback(async args => {
|
|
651
357
|
const {
|
|
652
|
-
itemsToMove:
|
|
358
|
+
itemsToMove: items,
|
|
653
359
|
toFolderID: toFolderID_0
|
|
654
|
-
} =
|
|
655
|
-
if (!
|
|
360
|
+
} = args;
|
|
361
|
+
if (!items.length) {
|
|
656
362
|
return;
|
|
657
363
|
}
|
|
658
|
-
const movingCurrentFolder =
|
|
364
|
+
const movingCurrentFolder = items.length === 1 && items[0].relationTo === folderCollectionSlug && items[0].value.id === folderID;
|
|
659
365
|
if (movingCurrentFolder) {
|
|
660
|
-
const req = await fetch(`${serverURL}${routes.api}/${folderCollectionSlug}/${
|
|
366
|
+
const req = await fetch(`${serverURL}${routes.api}/${folderCollectionSlug}/${folderID}?depth=0`, {
|
|
661
367
|
body: JSON.stringify({
|
|
662
368
|
[folderFieldName]: toFolderID_0 || null
|
|
663
369
|
}),
|
|
@@ -669,36 +375,11 @@ export function FolderProvider({
|
|
|
669
375
|
});
|
|
670
376
|
if (req.status !== 200) {
|
|
671
377
|
toast.error(t('general:error'));
|
|
672
|
-
} else {
|
|
673
|
-
const updatedDoc = await req.json();
|
|
674
|
-
const folderRes = await getFolderData({
|
|
675
|
-
folderID: updatedDoc.id
|
|
676
|
-
});
|
|
677
|
-
setBreadcrumbs(folderRes?.breadcrumbs || []);
|
|
678
|
-
setSubfolders(folderRes?.subfolders || []);
|
|
679
|
-
setDocuments(folderRes?.documents || []);
|
|
680
|
-
setActiveFolderID(updatedDoc.id);
|
|
681
378
|
}
|
|
682
|
-
setBreadcrumbs(prevBreadcrumbs => {
|
|
683
|
-
return prevBreadcrumbs.map(breadcrumb => {
|
|
684
|
-
if (breadcrumb.id === activeFolderID) {
|
|
685
|
-
return {
|
|
686
|
-
...breadcrumb,
|
|
687
|
-
id: toFolderID_0
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
return breadcrumb;
|
|
691
|
-
});
|
|
692
|
-
});
|
|
693
379
|
} else {
|
|
694
|
-
const
|
|
695
|
-
const successfullyMovedFolderItems = [];
|
|
696
|
-
const successfullyMovedDocumentItems = [];
|
|
697
|
-
for (const [collectionSlug_1, ids] of Object.entries(groupItemIDsByRelation(items_2))) {
|
|
698
|
-
const collectionConfig = getEntityConfig({
|
|
699
|
-
collectionSlug: collectionSlug_1
|
|
700
|
-
});
|
|
380
|
+
for (const [collectionSlug_0, ids] of Object.entries(groupItemIDsByRelation(items))) {
|
|
701
381
|
const query_0 = qs.stringify({
|
|
382
|
+
depth: 0,
|
|
702
383
|
limit: 0,
|
|
703
384
|
where: {
|
|
704
385
|
id: {
|
|
@@ -709,7 +390,7 @@ export function FolderProvider({
|
|
|
709
390
|
addQueryPrefix: true
|
|
710
391
|
});
|
|
711
392
|
try {
|
|
712
|
-
|
|
393
|
+
await fetch(`${serverURL}${routes.api}/${collectionSlug_0}${query_0}`, {
|
|
713
394
|
body: JSON.stringify({
|
|
714
395
|
[folderFieldName]: toFolderID_0 || null
|
|
715
396
|
}),
|
|
@@ -719,24 +400,6 @@ export function FolderProvider({
|
|
|
719
400
|
},
|
|
720
401
|
method: 'PATCH'
|
|
721
402
|
});
|
|
722
|
-
if (res_0.status === 200) {
|
|
723
|
-
const json = await res_0.json();
|
|
724
|
-
const {
|
|
725
|
-
docs
|
|
726
|
-
} = json;
|
|
727
|
-
const formattedItems = docs.map(doc => formatFolderOrDocumentItem({
|
|
728
|
-
folderFieldName,
|
|
729
|
-
isUpload: Boolean(collectionConfig.upload),
|
|
730
|
-
relationTo: collectionSlug_1,
|
|
731
|
-
useAsTitle: collectionConfig.admin.useAsTitle,
|
|
732
|
-
value: doc
|
|
733
|
-
}));
|
|
734
|
-
if (collectionSlug_1 === folderCollectionSlug) {
|
|
735
|
-
successfullyMovedFolderItems.push(...formattedItems);
|
|
736
|
-
} else {
|
|
737
|
-
successfullyMovedDocumentItems.push(...formattedItems);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
403
|
} catch (error) {
|
|
741
404
|
toast.error(t('general:error'));
|
|
742
405
|
// eslint-disable-next-line no-console
|
|
@@ -744,88 +407,20 @@ export function FolderProvider({
|
|
|
744
407
|
continue;
|
|
745
408
|
}
|
|
746
409
|
}
|
|
747
|
-
if (movingToCurrentFolder) {
|
|
748
|
-
// need to sort if we are moving (adding) items to the current folder
|
|
749
|
-
const {
|
|
750
|
-
newURL: newURL_1,
|
|
751
|
-
sortedDocuments: sortedDocuments_2,
|
|
752
|
-
sortedSubfolders: sortedSubfolders_2
|
|
753
|
-
} = sortItems({
|
|
754
|
-
documentsToSort: successfullyMovedDocumentItems.length ? [...documents, ...successfullyMovedDocumentItems] : undefined,
|
|
755
|
-
subfoldersToSort: successfullyMovedFolderItems.length ? [...subfolders, ...successfullyMovedFolderItems] : undefined
|
|
756
|
-
});
|
|
757
|
-
if (sortedDocuments_2) {
|
|
758
|
-
setDocuments(sortedDocuments_2);
|
|
759
|
-
}
|
|
760
|
-
if (sortedSubfolders_2) {
|
|
761
|
-
setSubfolders(sortedSubfolders_2);
|
|
762
|
-
}
|
|
763
|
-
if (drawerDepth === 1 && newURL_1) {
|
|
764
|
-
// not in a drawer (default is 1)
|
|
765
|
-
router.replace(newURL_1);
|
|
766
|
-
}
|
|
767
|
-
} else {
|
|
768
|
-
// no need to sort, just remove the items from the current state
|
|
769
|
-
const filteredDocuments_0 = successfullyMovedDocumentItems.length ? documents.filter(({
|
|
770
|
-
itemKey: itemKey_1
|
|
771
|
-
}) => !successfullyMovedDocumentItems.some(item_6 => item_6.itemKey === itemKey_1)) : undefined;
|
|
772
|
-
const filteredSubfolders_0 = successfullyMovedFolderItems.length ? subfolders.filter(({
|
|
773
|
-
itemKey: itemKey_2
|
|
774
|
-
}) => !successfullyMovedFolderItems.some(item_7 => item_7.itemKey === itemKey_2)) : undefined;
|
|
775
|
-
if (filteredDocuments_0) {
|
|
776
|
-
setDocuments(filteredDocuments_0);
|
|
777
|
-
}
|
|
778
|
-
if (filteredSubfolders_0) {
|
|
779
|
-
setSubfolders(filteredSubfolders_0);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
410
|
}
|
|
783
411
|
clearSelections();
|
|
784
|
-
}, [
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
* Used when the user renames a folder using the drawer
|
|
790
|
-
* and it needs to be updated in the current state.
|
|
791
|
-
*/
|
|
792
|
-
const renameFolder = React.useCallback(({
|
|
793
|
-
folderID: updatedFolderID,
|
|
794
|
-
newName
|
|
795
|
-
}) => {
|
|
796
|
-
if (activeFolderID === updatedFolderID) {
|
|
797
|
-
// updating the curent folder
|
|
798
|
-
setBreadcrumbs(prevBreadcrumbs_0 => {
|
|
799
|
-
return prevBreadcrumbs_0.map(breadcrumb_0 => {
|
|
800
|
-
if (breadcrumb_0.id === updatedFolderID) {
|
|
801
|
-
return {
|
|
802
|
-
...breadcrumb_0,
|
|
803
|
-
name: newName
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
return breadcrumb_0;
|
|
807
|
-
});
|
|
808
|
-
});
|
|
809
|
-
} else {
|
|
810
|
-
setSubfolders(prevFolders_0 => {
|
|
811
|
-
return prevFolders_0.map(folder => {
|
|
812
|
-
if (folder.value.id === updatedFolderID && folder.relationTo === folderCollectionSlug) {
|
|
813
|
-
return {
|
|
814
|
-
...folder,
|
|
815
|
-
value: {
|
|
816
|
-
...folder.value,
|
|
817
|
-
_folderOrDocumentTitle: newName
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
return folder;
|
|
822
|
-
});
|
|
823
|
-
});
|
|
412
|
+
}, [folderID, clearSelections, folderCollectionSlug, folderFieldName, routes.api, serverURL, t]);
|
|
413
|
+
// If a new component is provided, update the state so children can re-render with the new component
|
|
414
|
+
React.useEffect(() => {
|
|
415
|
+
if (InitialFolderResultsComponent) {
|
|
416
|
+
setFolderResultsComponent(InitialFolderResultsComponent);
|
|
824
417
|
}
|
|
825
|
-
}, [
|
|
418
|
+
}, [InitialFolderResultsComponent]);
|
|
826
419
|
return /*#__PURE__*/_jsx(Context, {
|
|
827
420
|
value: {
|
|
828
|
-
|
|
421
|
+
activeCollectionFolderSlugs: activeCollectionSlugs || allCollectionFolderSlugs,
|
|
422
|
+
allCollectionFolderSlugs,
|
|
423
|
+
allowCreateCollectionSlugs,
|
|
829
424
|
breadcrumbs,
|
|
830
425
|
clearSelections,
|
|
831
426
|
currentFolder: breadcrumbs?.[0]?.id ? formatFolderOrDocumentItem({
|
|
@@ -836,32 +431,28 @@ export function FolderProvider({
|
|
|
836
431
|
value: breadcrumbs[breadcrumbs.length - 1]
|
|
837
432
|
}) : null,
|
|
838
433
|
documents,
|
|
839
|
-
filterItems,
|
|
840
434
|
focusedRowIndex,
|
|
841
435
|
folderCollectionConfig,
|
|
842
436
|
folderCollectionSlug,
|
|
843
|
-
folderCollectionSlugs,
|
|
844
437
|
folderFieldName,
|
|
845
|
-
folderID
|
|
438
|
+
folderID,
|
|
439
|
+
FolderResultsComponent,
|
|
440
|
+
getFolderRoute,
|
|
846
441
|
getSelectedItems,
|
|
847
442
|
isDragging,
|
|
443
|
+
itemKeysToMove: parentFolderContext.selectedItemKeys,
|
|
848
444
|
lastSelectedIndex,
|
|
849
445
|
moveToFolder,
|
|
850
446
|
onItemClick,
|
|
851
447
|
onItemKeyPress,
|
|
852
|
-
|
|
853
|
-
renameFolder,
|
|
448
|
+
refineFolderData,
|
|
854
449
|
search,
|
|
855
|
-
|
|
450
|
+
selectedItemKeys,
|
|
856
451
|
setBreadcrumbs,
|
|
857
452
|
setFocusedRowIndex,
|
|
858
|
-
setFolderID: setNewActiveFolderID,
|
|
859
453
|
setIsDragging,
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
sortOn,
|
|
863
|
-
subfolders,
|
|
864
|
-
visibleCollectionSlugs
|
|
454
|
+
sort,
|
|
455
|
+
subfolders
|
|
865
456
|
},
|
|
866
457
|
children: children
|
|
867
458
|
});
|