@payloadcms/ui 3.48.0 → 3.49.0-canary.1
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/ListControls/useQueryPresets.d.ts.map +1 -1
- package/dist/elements/ListControls/useQueryPresets.js +3 -3
- package/dist/elements/ListControls/useQueryPresets.js.map +1 -1
- package/dist/elements/RelationshipTable/index.d.ts.map +1 -1
- package/dist/elements/RelationshipTable/index.js +9 -4
- package/dist/elements/RelationshipTable/index.js.map +1 -1
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +4 -4
- package/dist/providers/ListQuery/index.d.ts.map +1 -1
- package/dist/providers/ListQuery/index.js +38 -69
- package/dist/providers/ListQuery/index.js.map +1 -1
- package/dist/providers/ListQuery/mergeQuery.d.ts +5 -0
- package/dist/providers/ListQuery/mergeQuery.d.ts.map +1 -0
- package/dist/providers/ListQuery/mergeQuery.js +20 -0
- package/dist/providers/ListQuery/mergeQuery.js.map +1 -0
- package/dist/providers/ListQuery/sanitizeQuery.d.ts +8 -0
- package/dist/providers/ListQuery/sanitizeQuery.d.ts.map +1 -0
- package/dist/providers/ListQuery/sanitizeQuery.js +29 -0
- package/dist/providers/ListQuery/sanitizeQuery.js.map +1 -0
- package/dist/providers/ListQuery/types.d.ts +2 -5
- package/dist/providers/ListQuery/types.d.ts.map +1 -1
- package/dist/providers/ListQuery/types.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.d.ts +0 -1
- package/dist/providers/TableColumns/buildColumnState/index.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.js +5 -6
- package/dist/providers/TableColumns/buildColumnState/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/isColumnActive.d.ts +2 -2
- package/dist/providers/TableColumns/buildColumnState/isColumnActive.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/isColumnActive.js +4 -4
- package/dist/providers/TableColumns/buildColumnState/isColumnActive.js.map +1 -1
- package/dist/utilities/buildTableState.js +2 -3
- package/dist/utilities/buildTableState.js.map +1 -1
- package/dist/utilities/renderTable.d.ts +1 -2
- package/dist/utilities/renderTable.d.ts.map +1 -1
- package/dist/utilities/renderTable.js +0 -2
- package/dist/utilities/renderTable.js.map +1 -1
- package/dist/utilities/upsertPreferences.d.ts +9 -10
- package/dist/utilities/upsertPreferences.d.ts.map +1 -1
- package/dist/utilities/upsertPreferences.js +6 -5
- package/dist/utilities/upsertPreferences.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/ListQuery/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/ListQuery/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,YAAY,CAAA;AAUnE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAuKtD,CAAA"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
import { useRouter, useSearchParams } from 'next/navigation.js';
|
|
5
|
-
import { isNumber, transformColumnsToSearchParams } from 'payload/shared';
|
|
6
5
|
import * as qs from 'qs-esm';
|
|
7
6
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
7
|
import { useListDrawerContext } from '../../elements/ListDrawer/Provider.js';
|
|
@@ -10,21 +9,19 @@ import { useEffectEvent } from '../../hooks/useEffectEvent.js';
|
|
|
10
9
|
import { useRouteTransition } from '../../providers/RouteTransition/index.js';
|
|
11
10
|
import { parseSearchParams } from '../../utilities/parseSearchParams.js';
|
|
12
11
|
import { ListQueryContext, ListQueryModifiedContext } from './context.js';
|
|
12
|
+
import { mergeQuery } from './mergeQuery.js';
|
|
13
|
+
import { sanitizeQuery } from './sanitizeQuery.js';
|
|
13
14
|
export { useListQuery } from './context.js';
|
|
14
15
|
export const ListQueryProvider = ({
|
|
15
16
|
children,
|
|
16
17
|
collectionSlug,
|
|
17
|
-
columns,
|
|
18
18
|
data,
|
|
19
|
-
defaultLimit,
|
|
20
|
-
defaultSort,
|
|
21
|
-
listPreferences,
|
|
22
19
|
modifySearchParams,
|
|
23
20
|
onQueryChange: onQueryChangeFromProps,
|
|
24
|
-
orderableFieldName
|
|
21
|
+
orderableFieldName,
|
|
22
|
+
query: queryFromProps
|
|
25
23
|
}) => {
|
|
26
24
|
// TODO: Investigate if this is still needed
|
|
27
|
-
// eslint-disable-next-line react-compiler/react-compiler
|
|
28
25
|
'use no memo';
|
|
29
26
|
|
|
30
27
|
const router = useRouter();
|
|
@@ -33,7 +30,7 @@ export const ListQueryProvider = ({
|
|
|
33
30
|
startRouteTransition
|
|
34
31
|
} = useRouteTransition();
|
|
35
32
|
const [modified, setModified] = useState(false);
|
|
36
|
-
const searchParams = useMemo(() => parseSearchParams(rawSearchParams), [rawSearchParams]);
|
|
33
|
+
const searchParams = useMemo(() => sanitizeQuery(parseSearchParams(rawSearchParams)), [rawSearchParams]);
|
|
37
34
|
const contextRef = useRef({});
|
|
38
35
|
contextRef.current.modified = modified;
|
|
39
36
|
const {
|
|
@@ -44,29 +41,11 @@ export const ListQueryProvider = ({
|
|
|
44
41
|
return searchParams;
|
|
45
42
|
} else {
|
|
46
43
|
return {
|
|
47
|
-
limit:
|
|
48
|
-
sort:
|
|
44
|
+
limit: queryFromProps.limit,
|
|
45
|
+
sort: queryFromProps.sort
|
|
49
46
|
};
|
|
50
47
|
}
|
|
51
48
|
});
|
|
52
|
-
const mergeQuery = useCallback((newQuery = {}) => {
|
|
53
|
-
let page = 'page' in newQuery ? newQuery.page : currentQuery?.page;
|
|
54
|
-
if ('where' in newQuery || 'search' in newQuery) {
|
|
55
|
-
page = '1';
|
|
56
|
-
}
|
|
57
|
-
const mergedQuery = {
|
|
58
|
-
...currentQuery,
|
|
59
|
-
...newQuery,
|
|
60
|
-
columns: 'columns' in newQuery ? newQuery.columns : currentQuery.columns,
|
|
61
|
-
limit: 'limit' in newQuery ? newQuery.limit : currentQuery?.limit ?? String(defaultLimit),
|
|
62
|
-
page,
|
|
63
|
-
preset: 'preset' in newQuery ? newQuery.preset : currentQuery?.preset,
|
|
64
|
-
search: 'search' in newQuery ? newQuery.search : currentQuery?.search,
|
|
65
|
-
sort: 'sort' in newQuery ? newQuery.sort : currentQuery?.sort ?? defaultSort,
|
|
66
|
-
where: 'where' in newQuery ? newQuery.where : currentQuery?.where
|
|
67
|
-
};
|
|
68
|
-
return mergedQuery;
|
|
69
|
-
}, [currentQuery, defaultLimit, defaultSort]);
|
|
70
49
|
const refineListData = useCallback(
|
|
71
50
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
72
51
|
async (incomingQuery, modified_0) => {
|
|
@@ -75,29 +54,34 @@ export const ListQueryProvider = ({
|
|
|
75
54
|
} else {
|
|
76
55
|
setModified(true);
|
|
77
56
|
}
|
|
78
|
-
const
|
|
57
|
+
const newQuery = mergeQuery(currentQuery, incomingQuery, {
|
|
58
|
+
defaults: {
|
|
59
|
+
limit: queryFromProps.limit,
|
|
60
|
+
sort: queryFromProps.sort
|
|
61
|
+
}
|
|
62
|
+
});
|
|
79
63
|
if (modifySearchParams) {
|
|
80
64
|
startRouteTransition(() => router.replace(`${qs.stringify({
|
|
81
|
-
...
|
|
82
|
-
columns: JSON.stringify(
|
|
65
|
+
...newQuery,
|
|
66
|
+
columns: JSON.stringify(newQuery.columns)
|
|
83
67
|
}, {
|
|
84
68
|
addQueryPrefix: true
|
|
85
69
|
})}`));
|
|
86
70
|
} else if (typeof onQueryChange === 'function' || typeof onQueryChangeFromProps === 'function') {
|
|
87
71
|
const onChangeFn = onQueryChange || onQueryChangeFromProps;
|
|
88
|
-
onChangeFn(
|
|
72
|
+
onChangeFn(newQuery);
|
|
89
73
|
}
|
|
90
|
-
setCurrentQuery(
|
|
91
|
-
}, [
|
|
74
|
+
setCurrentQuery(newQuery);
|
|
75
|
+
}, [currentQuery, queryFromProps.limit, queryFromProps.sort, modifySearchParams, onQueryChange, onQueryChangeFromProps, startRouteTransition, router]);
|
|
92
76
|
const handlePageChange = useCallback(async arg => {
|
|
93
77
|
await refineListData({
|
|
94
|
-
page:
|
|
78
|
+
page: arg
|
|
95
79
|
});
|
|
96
80
|
}, [refineListData]);
|
|
97
81
|
const handlePerPageChange = React.useCallback(async arg_0 => {
|
|
98
82
|
await refineListData({
|
|
99
|
-
limit:
|
|
100
|
-
page:
|
|
83
|
+
limit: arg_0,
|
|
84
|
+
page: 1
|
|
101
85
|
});
|
|
102
86
|
}, [refineListData]);
|
|
103
87
|
const handleSearchChange = useCallback(async arg_1 => {
|
|
@@ -116,43 +100,28 @@ export const ListQueryProvider = ({
|
|
|
116
100
|
where: arg_3
|
|
117
101
|
});
|
|
118
102
|
}, [refineListData]);
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
...(
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
shouldUpdateQueryString = true;
|
|
133
|
-
}
|
|
134
|
-
// Only modify columns if they originated from preferences
|
|
135
|
-
// We can assume they did if `listPreferences.columns` is defined
|
|
136
|
-
if (columns && listPreferences?.columns && !('columns' in currentQuery)) {
|
|
137
|
-
newQuery_1.columns = transformColumnsToSearchParams(columns);
|
|
138
|
-
shouldUpdateQueryString = true;
|
|
139
|
-
}
|
|
140
|
-
if (shouldUpdateQueryString) {
|
|
141
|
-
setCurrentQuery(newQuery_1);
|
|
142
|
-
// Do not use router.replace here to avoid re-rendering on initial load
|
|
143
|
-
window.history.replaceState(null, '', `?${qs.stringify({
|
|
144
|
-
...newQuery_1,
|
|
145
|
-
columns: JSON.stringify(newQuery_1.columns)
|
|
146
|
-
})}`);
|
|
103
|
+
const mergeQueryFromPropsAndSyncToURL = useEffectEvent(() => {
|
|
104
|
+
const newQuery_0 = sanitizeQuery({
|
|
105
|
+
...(currentQuery || {}),
|
|
106
|
+
...(queryFromProps || {})
|
|
107
|
+
});
|
|
108
|
+
const search_0 = `?${qs.stringify({
|
|
109
|
+
...newQuery_0,
|
|
110
|
+
columns: JSON.stringify(newQuery_0.columns)
|
|
111
|
+
})}`;
|
|
112
|
+
if (window.location.search !== search_0) {
|
|
113
|
+
setCurrentQuery(newQuery_0);
|
|
114
|
+
// Important: do not use router.replace here to avoid re-rendering on initial load
|
|
115
|
+
window.history.replaceState(null, '', search_0);
|
|
147
116
|
}
|
|
148
117
|
});
|
|
149
|
-
// If `
|
|
150
|
-
//
|
|
118
|
+
// If `query` is updated externally, update the local state
|
|
119
|
+
// E.g. when HMR runs, these properties may be different
|
|
151
120
|
useEffect(() => {
|
|
152
121
|
if (modifySearchParams) {
|
|
153
|
-
|
|
122
|
+
mergeQueryFromPropsAndSyncToURL();
|
|
154
123
|
}
|
|
155
|
-
}, [
|
|
124
|
+
}, [modifySearchParams, queryFromProps]);
|
|
156
125
|
return /*#__PURE__*/_jsx(ListQueryContext, {
|
|
157
126
|
value: {
|
|
158
127
|
collectionSlug,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useRouter","useSearchParams","isNumber","transformColumnsToSearchParams","qs","React","useCallback","useEffect","useMemo","useRef","useState","useListDrawerContext","useEffectEvent","useRouteTransition","parseSearchParams","ListQueryContext","ListQueryModifiedContext","useListQuery","ListQueryProvider","children","collectionSlug","columns","data","defaultLimit","defaultSort","listPreferences","modifySearchParams","onQueryChange","onQueryChangeFromProps","orderableFieldName","router","rawSearchParams","startRouteTransition","modified","setModified","searchParams","contextRef","current","currentQuery","setCurrentQuery","limit","String","sort","mergeQuery","newQuery","page","mergedQuery","preset","search","where","refineListData","incomingQuery","undefined","replace","stringify","JSON","addQueryPrefix","onChangeFn","handlePageChange","arg","handlePerPageChange","handleSearchChange","handleSortChange","handleWhereChange","syncQuery","shouldUpdateQueryString","window","history","replaceState","_jsx","value","query"],"sources":["../../../src/providers/ListQuery/index.tsx"],"sourcesContent":["'use client'\nimport { useRouter, useSearchParams } from 'next/navigation.js'\nimport { type ListQuery, type Where } from 'payload'\nimport { isNumber, transformColumnsToSearchParams } from 'payload/shared'\nimport * as qs from 'qs-esm'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { IListQueryContext, ListQueryProps } from './types.js'\n\nimport { useListDrawerContext } from '../../elements/ListDrawer/Provider.js'\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport { useRouteTransition } from '../../providers/RouteTransition/index.js'\nimport { parseSearchParams } from '../../utilities/parseSearchParams.js'\nimport { ListQueryContext, ListQueryModifiedContext } from './context.js'\n\nexport { useListQuery } from './context.js'\n\nexport const ListQueryProvider: React.FC<ListQueryProps> = ({\n children,\n collectionSlug,\n columns,\n data,\n defaultLimit,\n defaultSort,\n listPreferences,\n modifySearchParams,\n onQueryChange: onQueryChangeFromProps,\n orderableFieldName,\n}) => {\n // TODO: Investigate if this is still needed\n // eslint-disable-next-line react-compiler/react-compiler\n 'use no memo'\n const router = useRouter()\n const rawSearchParams = useSearchParams()\n const { startRouteTransition } = useRouteTransition()\n const [modified, setModified] = useState(false)\n\n const searchParams = useMemo<ListQuery>(\n () => parseSearchParams(rawSearchParams),\n [rawSearchParams],\n )\n\n const contextRef = useRef({} as IListQueryContext)\n\n contextRef.current.modified = modified\n\n const { onQueryChange } = useListDrawerContext()\n\n const [currentQuery, setCurrentQuery] = useState<ListQuery>(() => {\n if (modifySearchParams) {\n return searchParams\n } else {\n return {\n limit: String(defaultLimit),\n sort: defaultSort,\n }\n }\n })\n\n const mergeQuery = useCallback(\n (newQuery: ListQuery = {}): ListQuery => {\n let page = 'page' in newQuery ? newQuery.page : currentQuery?.page\n\n if ('where' in newQuery || 'search' in newQuery) {\n page = '1'\n }\n\n const mergedQuery: ListQuery = {\n ...currentQuery,\n ...newQuery,\n columns: 'columns' in newQuery ? newQuery.columns : currentQuery.columns,\n limit: 'limit' in newQuery ? newQuery.limit : (currentQuery?.limit ?? String(defaultLimit)),\n page,\n preset: 'preset' in newQuery ? newQuery.preset : currentQuery?.preset,\n search: 'search' in newQuery ? newQuery.search : currentQuery?.search,\n sort: 'sort' in newQuery ? newQuery.sort : ((currentQuery?.sort as string) ?? defaultSort),\n where: 'where' in newQuery ? newQuery.where : currentQuery?.where,\n }\n\n return mergedQuery\n },\n [currentQuery, defaultLimit, defaultSort],\n )\n\n const refineListData = useCallback(\n // eslint-disable-next-line @typescript-eslint/require-await\n async (incomingQuery: ListQuery, modified?: boolean) => {\n if (modified !== undefined) {\n setModified(modified)\n } else {\n setModified(true)\n }\n\n const newQuery = mergeQuery(incomingQuery)\n\n if (modifySearchParams) {\n startRouteTransition(() =>\n router.replace(\n `${qs.stringify({ ...newQuery, columns: JSON.stringify(newQuery.columns) }, { addQueryPrefix: true })}`,\n ),\n )\n } else if (\n typeof onQueryChange === 'function' ||\n typeof onQueryChangeFromProps === 'function'\n ) {\n const onChangeFn = onQueryChange || onQueryChangeFromProps\n onChangeFn(newQuery)\n }\n\n setCurrentQuery(newQuery)\n },\n [\n mergeQuery,\n modifySearchParams,\n onQueryChange,\n onQueryChangeFromProps,\n startRouteTransition,\n router,\n ],\n )\n\n const handlePageChange = useCallback(\n async (arg: number) => {\n await refineListData({ page: String(arg) })\n },\n [refineListData],\n )\n\n const handlePerPageChange = React.useCallback(\n async (arg: number) => {\n await refineListData({ limit: String(arg), page: '1' })\n },\n [refineListData],\n )\n\n const handleSearchChange = useCallback(\n async (arg: string) => {\n const search = arg === '' ? undefined : arg\n await refineListData({ search })\n },\n [refineListData],\n )\n\n const handleSortChange = useCallback(\n async (arg: string) => {\n await refineListData({ sort: arg })\n },\n [refineListData],\n )\n\n const handleWhereChange = useCallback(\n async (arg: Where) => {\n await refineListData({ where: arg })\n },\n [refineListData],\n )\n\n const syncQuery = useEffectEvent(() => {\n let shouldUpdateQueryString = false\n const newQuery = { ...(currentQuery || {}) }\n\n // Allow the URL to override the default limit\n if (isNumber(defaultLimit) && !('limit' in currentQuery)) {\n newQuery.limit = String(defaultLimit)\n shouldUpdateQueryString = true\n }\n\n // Allow the URL to override the default sort\n if (defaultSort && !('sort' in currentQuery)) {\n newQuery.sort = defaultSort\n shouldUpdateQueryString = true\n }\n\n // Only modify columns if they originated from preferences\n // We can assume they did if `listPreferences.columns` is defined\n if (columns && listPreferences?.columns && !('columns' in currentQuery)) {\n newQuery.columns = transformColumnsToSearchParams(columns)\n shouldUpdateQueryString = true\n }\n\n if (shouldUpdateQueryString) {\n setCurrentQuery(newQuery)\n // Do not use router.replace here to avoid re-rendering on initial load\n window.history.replaceState(\n null,\n '',\n `?${qs.stringify({ ...newQuery, columns: JSON.stringify(newQuery.columns) })}`,\n )\n }\n })\n\n // If `defaultLimit` or `defaultSort` are updated externally, update the query\n // I.e. when HMR runs, these properties may be different\n useEffect(() => {\n if (modifySearchParams) {\n syncQuery()\n }\n }, [defaultSort, defaultLimit, modifySearchParams, columns])\n\n return (\n <ListQueryContext\n value={{\n collectionSlug,\n data,\n handlePageChange,\n handlePerPageChange,\n handleSearchChange,\n handleSortChange,\n handleWhereChange,\n orderableFieldName,\n query: currentQuery,\n refineListData,\n setModified,\n\n ...contextRef.current,\n }}\n >\n <ListQueryModifiedContext value={modified}>{children}</ListQueryModifiedContext>\n </ListQueryContext>\n )\n}\n"],"mappings":"AAAA;;;AACA,SAASA,SAAS,EAAEC,eAAe,QAAQ;AAE3C,SAASC,QAAQ,EAAEC,8BAA8B,QAAQ;AACzD,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AA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
{"version":3,"file":"index.js","names":["useRouter","useSearchParams","qs","React","useCallback","useEffect","useMemo","useRef","useState","useListDrawerContext","useEffectEvent","useRouteTransition","parseSearchParams","ListQueryContext","ListQueryModifiedContext","mergeQuery","sanitizeQuery","useListQuery","ListQueryProvider","children","collectionSlug","data","modifySearchParams","onQueryChange","onQueryChangeFromProps","orderableFieldName","query","queryFromProps","router","rawSearchParams","startRouteTransition","modified","setModified","searchParams","contextRef","current","currentQuery","setCurrentQuery","limit","sort","refineListData","incomingQuery","undefined","newQuery","defaults","replace","stringify","columns","JSON","addQueryPrefix","onChangeFn","handlePageChange","arg","page","handlePerPageChange","handleSearchChange","search","handleSortChange","handleWhereChange","where","mergeQueryFromPropsAndSyncToURL","window","location","history","replaceState","_jsx","value"],"sources":["../../../src/providers/ListQuery/index.tsx"],"sourcesContent":["'use client'\nimport { useRouter, useSearchParams } from 'next/navigation.js'\nimport { type ListQuery, type Where } from 'payload'\nimport * as qs from 'qs-esm'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { IListQueryContext, ListQueryProps } from './types.js'\n\nimport { useListDrawerContext } from '../../elements/ListDrawer/Provider.js'\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport { useRouteTransition } from '../../providers/RouteTransition/index.js'\nimport { parseSearchParams } from '../../utilities/parseSearchParams.js'\nimport { ListQueryContext, ListQueryModifiedContext } from './context.js'\nimport { mergeQuery } from './mergeQuery.js'\nimport { sanitizeQuery } from './sanitizeQuery.js'\n\nexport { useListQuery } from './context.js'\n\nexport const ListQueryProvider: React.FC<ListQueryProps> = ({\n children,\n collectionSlug,\n data,\n modifySearchParams,\n onQueryChange: onQueryChangeFromProps,\n orderableFieldName,\n query: queryFromProps,\n}) => {\n // TODO: Investigate if this is still needed\n\n 'use no memo'\n const router = useRouter()\n const rawSearchParams = useSearchParams()\n const { startRouteTransition } = useRouteTransition()\n const [modified, setModified] = useState(false)\n\n const searchParams = useMemo<ListQuery>(\n () => sanitizeQuery(parseSearchParams(rawSearchParams)),\n [rawSearchParams],\n )\n\n const contextRef = useRef({} as IListQueryContext)\n\n contextRef.current.modified = modified\n\n const { onQueryChange } = useListDrawerContext()\n\n const [currentQuery, setCurrentQuery] = useState<ListQuery>(() => {\n if (modifySearchParams) {\n return searchParams\n } else {\n return {\n limit: queryFromProps.limit,\n sort: queryFromProps.sort,\n }\n }\n })\n\n const refineListData = useCallback(\n // eslint-disable-next-line @typescript-eslint/require-await\n async (incomingQuery: ListQuery, modified?: boolean) => {\n if (modified !== undefined) {\n setModified(modified)\n } else {\n setModified(true)\n }\n\n const newQuery = mergeQuery(currentQuery, incomingQuery, {\n defaults: {\n limit: queryFromProps.limit,\n sort: queryFromProps.sort,\n },\n })\n\n if (modifySearchParams) {\n startRouteTransition(() =>\n router.replace(\n `${qs.stringify(\n {\n ...newQuery,\n columns: JSON.stringify(newQuery.columns),\n },\n { addQueryPrefix: true },\n )}`,\n ),\n )\n } else if (\n typeof onQueryChange === 'function' ||\n typeof onQueryChangeFromProps === 'function'\n ) {\n const onChangeFn = onQueryChange || onQueryChangeFromProps\n onChangeFn(newQuery)\n }\n\n setCurrentQuery(newQuery)\n },\n [\n currentQuery,\n queryFromProps.limit,\n queryFromProps.sort,\n modifySearchParams,\n onQueryChange,\n onQueryChangeFromProps,\n startRouteTransition,\n router,\n ],\n )\n\n const handlePageChange = useCallback(\n async (arg: number) => {\n await refineListData({ page: arg })\n },\n [refineListData],\n )\n\n const handlePerPageChange = React.useCallback(\n async (arg: number) => {\n await refineListData({ limit: arg, page: 1 })\n },\n [refineListData],\n )\n\n const handleSearchChange = useCallback(\n async (arg: string) => {\n const search = arg === '' ? undefined : arg\n await refineListData({ search })\n },\n [refineListData],\n )\n\n const handleSortChange = useCallback(\n async (arg: string) => {\n await refineListData({ sort: arg })\n },\n [refineListData],\n )\n\n const handleWhereChange = useCallback(\n async (arg: Where) => {\n await refineListData({ where: arg })\n },\n [refineListData],\n )\n\n const mergeQueryFromPropsAndSyncToURL = useEffectEvent(() => {\n const newQuery = sanitizeQuery({ ...(currentQuery || {}), ...(queryFromProps || {}) })\n\n const search = `?${qs.stringify({ ...newQuery, columns: JSON.stringify(newQuery.columns) })}`\n\n if (window.location.search !== search) {\n setCurrentQuery(newQuery)\n\n // Important: do not use router.replace here to avoid re-rendering on initial load\n window.history.replaceState(null, '', search)\n }\n })\n\n // If `query` is updated externally, update the local state\n // E.g. when HMR runs, these properties may be different\n useEffect(() => {\n if (modifySearchParams) {\n mergeQueryFromPropsAndSyncToURL()\n }\n }, [modifySearchParams, queryFromProps])\n\n return (\n <ListQueryContext\n value={{\n collectionSlug,\n data,\n handlePageChange,\n handlePerPageChange,\n handleSearchChange,\n handleSortChange,\n handleWhereChange,\n orderableFieldName,\n query: currentQuery,\n refineListData,\n setModified,\n\n ...contextRef.current,\n }}\n >\n <ListQueryModifiedContext value={modified}>{children}</ListQueryModifiedContext>\n </ListQueryContext>\n )\n}\n"],"mappings":"AAAA;;;AACA,SAASA,SAAS,EAAEC,eAAe,QAAQ;AAE3C,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAIzE,SAASC,oBAAoB,QAAQ;AACrC,SAASC,cAAc,QAAQ;AAC/B,SAASC,kBAAkB,QAAQ;AACnC,SAASC,iBAAiB,QAAQ;AAClC,SAASC,gBAAgB,EAAEC,wBAAwB,QAAQ;AAC3D,SAASC,UAAU,QAAQ;AAC3B,SAASC,aAAa,QAAQ;AAE9B,SAASC,YAAY,QAAQ;AAE7B,OAAO,MAAMC,iBAAA,GAA8CA,CAAC;EAC1DC,QAAQ;EACRC,cAAc;EACdC,IAAI;EACJC,kBAAkB;EAClBC,aAAA,EAAeC,sBAAsB;EACrCC,kBAAkB;EAClBC,KAAA,EAAOC;AAAc,CACtB;EACC;EAEA;;EACA,MAAMC,MAAA,GAAS5B,SAAA;EACf,MAAM6B,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MAAG,IAAIT,cAAA,IAAkB,CAAC,CAAC;IAAE;IAEpF,MAAM6B,QAAA,GAAS,IAAItD,EAAA,CAAG4C,SAAS,CAAC;MAAE,GAAGH,UAAQ;MAAEI,OAAA,EAASC,IAAA,CAAKF,SAAS,CAACH,UAAA,CAASI,OAAO;IAAE,IAAI;IAE7F,IAAIc,MAAA,CAAOC,QAAQ,CAACN,MAAM,KAAKA,QAAA,EAAQ;MACrCnB,eAAA,CAAgBM,UAAA;MAEhB;MACAkB,MAAA,CAAOE,OAAO,CAACC,YAAY,CAAC,MAAM,IAAIR,QAAA;IACxC;EACF;EAEA;EACA;EACAnD,SAAA,CAAU;IACR,IAAIiB,kBAAA,EAAoB;MACtBsC,+BAAA;IACF;EACF,GAAG,CAACtC,kBAAA,EAAoBK,cAAA,CAAe;EAEvC,oBACEsC,IAAA,CAACpD,gBAAA;IACCqD,KAAA,EAAO;MACL9C,cAAA;MACAC,IAAA;MACA8B,gBAAA;MACAG,mBAAA;MACAC,kBAAA;MACAE,gBAAA;MACAC,iBAAA;MACAjC,kBAAA;MACAC,KAAA,EAAOU,YAAA;MACPI,cAAA;MACAR,WAAA;MAEA,GAAGE,UAAA,CAAWC;IAChB;cAEA,aAAA8B,IAAA,CAACnD,wBAAA;MAAyBoD,KAAA,EAAOnC,QAAA;gBAAWZ;;;AAGlD","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeQuery.d.ts","sourceRoot":"","sources":["../../../src/providers/ListQuery/mergeQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,eAAO,MAAM,UAAU,iBACP,SAAS,YACb,SAAS,YACT;IACR,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,KACA,SA2BF,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const mergeQuery = (currentQuery, newQuery, options) => {
|
|
2
|
+
let page = 'page' in newQuery ? newQuery.page : currentQuery?.page;
|
|
3
|
+
if ('where' in newQuery || 'search' in newQuery) {
|
|
4
|
+
page = 1;
|
|
5
|
+
}
|
|
6
|
+
const mergedQuery = {
|
|
7
|
+
...currentQuery,
|
|
8
|
+
...newQuery,
|
|
9
|
+
columns: 'columns' in newQuery ? newQuery.columns : currentQuery.columns,
|
|
10
|
+
groupBy: 'groupBy' in newQuery ? newQuery.groupBy : currentQuery?.groupBy ?? options?.defaults?.groupBy,
|
|
11
|
+
limit: 'limit' in newQuery ? newQuery.limit : currentQuery?.limit ?? options?.defaults?.limit,
|
|
12
|
+
page,
|
|
13
|
+
preset: 'preset' in newQuery ? newQuery.preset : currentQuery?.preset,
|
|
14
|
+
search: 'search' in newQuery ? newQuery.search : currentQuery?.search,
|
|
15
|
+
sort: 'sort' in newQuery ? newQuery.sort : currentQuery?.sort ?? options?.defaults?.sort,
|
|
16
|
+
where: 'where' in newQuery ? newQuery.where : currentQuery?.where
|
|
17
|
+
};
|
|
18
|
+
return mergedQuery;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=mergeQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeQuery.js","names":["mergeQuery","currentQuery","newQuery","options","page","mergedQuery","columns","groupBy","defaults","limit","preset","search","sort","where"],"sources":["../../../src/providers/ListQuery/mergeQuery.ts"],"sourcesContent":["import type { ListQuery } from 'payload'\n\nexport const mergeQuery = (\n currentQuery: ListQuery,\n newQuery: ListQuery,\n options?: {\n defaults?: ListQuery\n },\n): ListQuery => {\n let page = 'page' in newQuery ? newQuery.page : currentQuery?.page\n\n if ('where' in newQuery || 'search' in newQuery) {\n page = 1\n }\n\n const mergedQuery: ListQuery = {\n ...currentQuery,\n ...newQuery,\n columns: 'columns' in newQuery ? newQuery.columns : currentQuery.columns,\n groupBy:\n 'groupBy' in newQuery\n ? newQuery.groupBy\n : (currentQuery?.groupBy ?? options?.defaults?.groupBy),\n limit: 'limit' in newQuery ? newQuery.limit : (currentQuery?.limit ?? options?.defaults?.limit),\n page,\n preset: 'preset' in newQuery ? newQuery.preset : currentQuery?.preset,\n search: 'search' in newQuery ? newQuery.search : currentQuery?.search,\n sort:\n 'sort' in newQuery\n ? newQuery.sort\n : ((currentQuery?.sort as string) ?? options?.defaults?.sort),\n where: 'where' in newQuery ? newQuery.where : currentQuery?.where,\n }\n\n return mergedQuery\n}\n"],"mappings":"AAEA,OAAO,MAAMA,UAAA,GAAaA,CACxBC,YAAA,EACAC,QAAA,EACAC,OAAA;EAIA,IAAIC,IAAA,GAAO,UAAUF,QAAA,GAAWA,QAAA,CAASE,IAAI,GAAGH,YAAA,EAAcG,IAAA;EAE9D,IAAI,WAAWF,QAAA,IAAY,YAAYA,QAAA,EAAU;IAC/CE,IAAA,GAAO;EACT;EAEA,MAAMC,WAAA,GAAyB;IAC7B,GAAGJ,YAAY;IACf,GAAGC,QAAQ;IACXI,OAAA,EAAS,aAAaJ,QAAA,GAAWA,QAAA,CAASI,OAAO,GAAGL,YAAA,CAAaK,OAAO;IACxEC,OAAA,EACE,aAAaL,QAAA,GACTA,QAAA,CAASK,OAAO,GACfN,YAAA,EAAcM,OAAA,IAAWJ,OAAA,EAASK,QAAA,EAAUD,OAAA;IACnDE,KAAA,EAAO,WAAWP,QAAA,GAAWA,QAAA,CAASO,KAAK,GAAIR,YAAA,EAAcQ,KAAA,IAASN,OAAA,EAASK,QAAA,EAAUC,KAAA;IACzFL,IAAA;IACAM,MAAA,EAAQ,YAAYR,QAAA,GAAWA,QAAA,CAASQ,MAAM,GAAGT,YAAA,EAAcS,MAAA;IAC/DC,MAAA,EAAQ,YAAYT,QAAA,GAAWA,QAAA,CAASS,MAAM,GAAGV,YAAA,EAAcU,MAAA;IAC/DC,IAAA,EACE,UAAUV,QAAA,GACNA,QAAA,CAASU,IAAI,GACZX,YAAC,EAAcW,IAAA,IAAmBT,OAAA,EAASK,QAAA,EAAUI,IAAA;IAC5DC,KAAA,EAAO,WAAWX,QAAA,GAAWA,QAAA,CAASW,KAAK,GAAGZ,YAAA,EAAcY;EAC9D;EAEA,OAAOR,WAAA;AACT","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ListQuery } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Sanitize empty strings from the query, e.g. `?preset=`
|
|
4
|
+
* This is how we determine whether to clear user preferences for certain params
|
|
5
|
+
* Once cleared, they are no longer needed in the URL
|
|
6
|
+
*/
|
|
7
|
+
export declare const sanitizeQuery: (toSanitize: ListQuery) => ListQuery;
|
|
8
|
+
//# sourceMappingURL=sanitizeQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeQuery.d.ts","sourceRoot":"","sources":["../../../src/providers/ListQuery/sanitizeQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAS,MAAM,SAAS,CAAA;AAE/C;;;;GAIG;AACH,eAAO,MAAM,aAAa,eAAgB,SAAS,KAAG,SA8BrD,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitize empty strings from the query, e.g. `?preset=`
|
|
3
|
+
* This is how we determine whether to clear user preferences for certain params
|
|
4
|
+
* Once cleared, they are no longer needed in the URL
|
|
5
|
+
*/export const sanitizeQuery = toSanitize => {
|
|
6
|
+
const sanitized = {
|
|
7
|
+
...toSanitize
|
|
8
|
+
};
|
|
9
|
+
Object.entries(sanitized).forEach(([key, value]) => {
|
|
10
|
+
if (key === 'columns' && (value === '[]' || Array.isArray(sanitized[key]) && sanitized[key].length === 0)) {
|
|
11
|
+
delete sanitized[key];
|
|
12
|
+
}
|
|
13
|
+
if (key === 'where' && typeof value === 'object' && !Object.keys(value).length) {
|
|
14
|
+
delete sanitized[key];
|
|
15
|
+
}
|
|
16
|
+
if ((key === 'limit' || key === 'page') && typeof value === 'string') {
|
|
17
|
+
const parsed = parseInt(value, 10);
|
|
18
|
+
sanitized[key] = Number.isNaN(parsed) ? undefined : parsed;
|
|
19
|
+
}
|
|
20
|
+
if (key === 'page' && value === 0) {
|
|
21
|
+
delete sanitized[key];
|
|
22
|
+
}
|
|
23
|
+
if (value === '') {
|
|
24
|
+
delete sanitized[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return sanitized;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=sanitizeQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeQuery.js","names":["sanitizeQuery","toSanitize","sanitized","Object","entries","forEach","key","value","Array","isArray","length","keys","parsed","parseInt","Number","isNaN","undefined"],"sources":["../../../src/providers/ListQuery/sanitizeQuery.ts"],"sourcesContent":["import type { ListQuery, Where } from 'payload'\n\n/**\n * Sanitize empty strings from the query, e.g. `?preset=`\n * This is how we determine whether to clear user preferences for certain params\n * Once cleared, they are no longer needed in the URL\n */\nexport const sanitizeQuery = (toSanitize: ListQuery): ListQuery => {\n const sanitized = { ...toSanitize }\n\n Object.entries(sanitized).forEach(([key, value]) => {\n if (\n key === 'columns' &&\n (value === '[]' || (Array.isArray(sanitized[key]) && sanitized[key].length === 0))\n ) {\n delete sanitized[key]\n }\n\n if (key === 'where' && typeof value === 'object' && !Object.keys(value as Where).length) {\n delete sanitized[key]\n }\n\n if ((key === 'limit' || key === 'page') && typeof value === 'string') {\n const parsed = parseInt(value, 10)\n sanitized[key] = Number.isNaN(parsed) ? undefined : parsed\n }\n\n if (key === 'page' && value === 0) {\n delete sanitized[key]\n }\n\n if (value === '') {\n delete sanitized[key]\n }\n })\n\n return sanitized\n}\n"],"mappings":"AAEA;;;;GAKA,OAAO,MAAMA,aAAA,GAAiBC,UAAA;EAC5B,MAAMC,SAAA,GAAY;IAAE,GAAGD;EAAW;EAElCE,MAAA,CAAOC,OAAO,CAACF,SAAA,EAAWG,OAAO,CAAC,CAAC,CAACC,GAAA,EAAKC,KAAA,CAAM;IAC7C,IACED,GAAA,KAAQ,cACPC,KAAA,KAAU,QAASC,KAAA,CAAMC,OAAO,CAACP,SAAS,CAACI,GAAA,CAAI,KAAKJ,SAAS,CAACI,GAAA,CAAI,CAACI,MAAM,KAAK,CAAC,GAChF;MACA,OAAOR,SAAS,CAACI,GAAA,CAAI;IACvB;IAEA,IAAIA,GAAA,KAAQ,WAAW,OAAOC,KAAA,KAAU,YAAY,CAACJ,MAAA,CAAOQ,IAAI,CAACJ,KAAA,EAAgBG,MAAM,EAAE;MACvF,OAAOR,SAAS,CAACI,GAAA,CAAI;IACvB;IAEA,IAAI,CAACA,GAAA,KAAQ,WAAWA,GAAA,KAAQ,MAAK,KAAM,OAAOC,KAAA,KAAU,UAAU;MACpE,MAAMK,MAAA,GAASC,QAAA,CAASN,KAAA,EAAO;MAC/BL,SAAS,CAACI,GAAA,CAAI,GAAGQ,MAAA,CAAOC,KAAK,CAACH,MAAA,IAAUI,SAAA,GAAYJ,MAAA;IACtD;IAEA,IAAIN,GAAA,KAAQ,UAAUC,KAAA,KAAU,GAAG;MACjC,OAAOL,SAAS,CAACI,GAAA,CAAI;IACvB;IAEA,IAAIC,KAAA,KAAU,IAAI;MAChB,OAAOL,SAAS,CAACI,GAAA,CAAI;IACvB;EACF;EAEA,OAAOJ,SAAA;AACT","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClientCollectionConfig,
|
|
1
|
+
import type { ClientCollectionConfig, ListQuery, PaginatedDocs, Sort, Where } from 'payload';
|
|
2
2
|
type ContextHandlers = {
|
|
3
3
|
handlePageChange?: (page: number) => Promise<void>;
|
|
4
4
|
handlePerPageChange?: (limit: number) => Promise<void>;
|
|
@@ -10,11 +10,7 @@ export type OnListQueryChange = (query: ListQuery) => void;
|
|
|
10
10
|
export type ListQueryProps = {
|
|
11
11
|
readonly children: React.ReactNode;
|
|
12
12
|
readonly collectionSlug?: ClientCollectionConfig['slug'];
|
|
13
|
-
readonly columns?: ColumnPreference[];
|
|
14
13
|
readonly data: PaginatedDocs;
|
|
15
|
-
readonly defaultLimit?: number;
|
|
16
|
-
readonly defaultSort?: Sort;
|
|
17
|
-
readonly listPreferences?: CollectionPreferences;
|
|
18
14
|
readonly modifySearchParams?: boolean;
|
|
19
15
|
readonly onQueryChange?: OnListQueryChange;
|
|
20
16
|
readonly orderableFieldName?: string;
|
|
@@ -22,6 +18,7 @@ export type ListQueryProps = {
|
|
|
22
18
|
* @deprecated
|
|
23
19
|
*/
|
|
24
20
|
readonly preferenceKey?: string;
|
|
21
|
+
query?: ListQuery;
|
|
25
22
|
};
|
|
26
23
|
export type IListQueryContext = {
|
|
27
24
|
collectionSlug: ClientCollectionConfig['slug'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/ListQuery/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/ListQuery/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EAEtB,SAAS,EACT,aAAa,EACb,IAAI,EACJ,KAAK,EACN,MAAM,SAAS,CAAA;AAEhB,KAAK,eAAe,GAAG;IACrB,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAClD,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACtD,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACtD,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAClD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACpD,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;AAE1D,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IAClC,QAAQ,CAAC,cAAc,CAAC,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAA;IACxD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;IAC5B,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAA;IACrC,QAAQ,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAA;IAC1C,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IACpC;;OAEG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAA;IAC9C,IAAI,EAAE,aAAa,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,KAAK,EAAE,SAAS,CAAA;IAChB,cAAc,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACzE,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;CACzC,GAAG,eAAe,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/providers/ListQuery/types.ts"],"sourcesContent":["import type {\n ClientCollectionConfig,\n
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/providers/ListQuery/types.ts"],"sourcesContent":["import type {\n ClientCollectionConfig,\n ColumnPreference,\n ListQuery,\n PaginatedDocs,\n Sort,\n Where,\n} from 'payload'\n\ntype ContextHandlers = {\n handlePageChange?: (page: number) => Promise<void>\n handlePerPageChange?: (limit: number) => Promise<void>\n handleSearchChange?: (search: string) => Promise<void>\n handleSortChange?: (sort: string) => Promise<void>\n handleWhereChange?: (where: Where) => Promise<void>\n}\n\nexport type OnListQueryChange = (query: ListQuery) => void\n\nexport type ListQueryProps = {\n readonly children: React.ReactNode\n readonly collectionSlug?: ClientCollectionConfig['slug']\n readonly data: PaginatedDocs\n readonly modifySearchParams?: boolean\n readonly onQueryChange?: OnListQueryChange\n readonly orderableFieldName?: string\n /**\n * @deprecated\n */\n readonly preferenceKey?: string\n query?: ListQuery\n}\n\nexport type IListQueryContext = {\n collectionSlug: ClientCollectionConfig['slug']\n data: PaginatedDocs\n defaultLimit?: number\n defaultSort?: Sort\n modified: boolean\n orderableFieldName?: string\n query: ListQuery\n refineListData: (args: ListQuery, setModified?: boolean) => Promise<void>\n setModified: (modified: boolean) => void\n} & ContextHandlers\n"],"mappings":"AAiCA","ignoreList":[]}
|
|
@@ -4,7 +4,6 @@ import type { SortColumnProps } from '../../../elements/SortColumn/index.js';
|
|
|
4
4
|
export type BuildColumnStateArgs = {
|
|
5
5
|
beforeRows?: Column[];
|
|
6
6
|
clientFields: ClientField[];
|
|
7
|
-
columnPreferences: CollectionPreferences['columns'];
|
|
8
7
|
columns?: CollectionPreferences['columns'];
|
|
9
8
|
customCellProps: DefaultCellComponentProps['customCellProps'];
|
|
10
9
|
enableLinkedCell?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/providers/TableColumns/buildColumnState/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAEV,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,MAAM,EACN,yBAAyB,EACzB,QAAQ,EACR,KAAK,EACL,aAAa,EACb,OAAO,EACP,yBAAyB,EAG1B,MAAM,SAAS,CAAA;AAUhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AAY5E,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,YAAY,EAAE,WAAW,EAAE,CAAA;IAC3B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/providers/TableColumns/buildColumnState/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAEV,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,MAAM,EACN,yBAAyB,EACzB,QAAQ,EACR,KAAK,EACL,aAAa,EACb,OAAO,EACP,yBAAyB,EAG1B,MAAM,SAAS,CAAA;AAUhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AAY5E,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,YAAY,EAAE,WAAW,EAAE,CAAA;IAC3B,OAAO,CAAC,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAA;IAC1C,eAAe,EAAE,yBAAyB,CAAC,iBAAiB,CAAC,CAAA;IAC7D,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,EAAE,KAAK,EAAE,CAAA;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IAC1C,UAAU,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAA;CAC7D,GAAG,CACA;IACE,cAAc,EAAE,cAAc,CAAA;IAC9B,QAAQ,EAAE,aAAa,CAAA;IACvB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAC5B,GACD;IACE,cAAc,CAAC,EAAE,SAAS,CAAA;IAC1B,QAAQ,EAAE,aAAa,CAAA;IACvB,IAAI,EAAE;QACJ,UAAU,EAAE,cAAc,CAAA;QAC1B,KAAK,EAAE,QAAQ,CAAA;KAChB,EAAE,CAAA;CACJ,CACJ,CAAA;AAED,eAAO,MAAM,gBAAgB,SAAU,oBAAoB,KAAG,MAAM,EAuMnE,CAAA"}
|
|
@@ -12,7 +12,6 @@ export const buildColumnState = args => {
|
|
|
12
12
|
beforeRows,
|
|
13
13
|
clientFields,
|
|
14
14
|
collectionSlug,
|
|
15
|
-
columnPreferences,
|
|
16
15
|
columns,
|
|
17
16
|
customCellProps,
|
|
18
17
|
dataType,
|
|
@@ -39,7 +38,7 @@ export const buildColumnState = args => {
|
|
|
39
38
|
;
|
|
40
39
|
// place the `ID` field first, if it exists
|
|
41
40
|
// do the same for the `useAsTitle` field with precedence over the `ID` field
|
|
42
|
-
// then sort the rest of the fields based on the `defaultColumns` or `
|
|
41
|
+
// then sort the rest of the fields based on the `defaultColumns` or `columns`
|
|
43
42
|
const idFieldIndex = sortedFieldMap?.findIndex(field => fieldIsID(field));
|
|
44
43
|
if (idFieldIndex > -1) {
|
|
45
44
|
const idField = sortedFieldMap.splice(idFieldIndex, 1)[0];
|
|
@@ -50,9 +49,9 @@ export const buildColumnState = args => {
|
|
|
50
49
|
const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0];
|
|
51
50
|
sortedFieldMap.unshift(useAsTitleField);
|
|
52
51
|
}
|
|
53
|
-
const sortTo =
|
|
52
|
+
const sortTo = columns;
|
|
54
53
|
if (sortTo) {
|
|
55
|
-
// sort the fields to the order of `defaultColumns` or `
|
|
54
|
+
// sort the fields to the order of `defaultColumns` or `columns`
|
|
56
55
|
sortedFieldMap = sortFieldMap(sortedFieldMap, sortTo);
|
|
57
56
|
_sortedFieldMap = sortFieldMap(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort
|
|
58
57
|
;
|
|
@@ -72,11 +71,11 @@ export const buildColumnState = args => {
|
|
|
72
71
|
return acc // skip any group without a custom cell
|
|
73
72
|
;
|
|
74
73
|
}
|
|
75
|
-
const
|
|
74
|
+
const columnPref = columns?.find(preference => clientField && 'name' in clientField && preference.accessor === accessor);
|
|
76
75
|
const isActive = isColumnActive({
|
|
77
76
|
accessor,
|
|
78
77
|
activeColumnsIndices,
|
|
79
|
-
|
|
78
|
+
column: columnPref,
|
|
80
79
|
columns
|
|
81
80
|
});
|
|
82
81
|
if (isActive && !activeColumnsIndices.includes(colIndex)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fieldIsHiddenOrDisabled","fieldIsID","fieldIsPresentationalOnly","flattenTopLevelFields","React","RenderServerComponent","SortColumn","filterFields","isColumnActive","renderCell","sortFieldMap","buildColumnState","args","beforeRows","clientFields","collectionSlug","columnPreferences","columns","customCellProps","dataType","docs","enableLinkedCell","enableRowSelections","i18n","payload","serverFields","sortColumnProps","useAsTitle","sortedFieldMap","keepPresentationalFields","moveSubFieldsToTop","_sortedFieldMap","idFieldIndex","findIndex","field","idField","splice","unshift","useAsTitleFieldIndex","name","useAsTitleField","sortTo","activeColumnsIndices","sorted","reduce","acc","clientField","colIndex","accessor","undefined","serverField","find","f","fAccessor","hasCustomCell","admin","components","Cell","type","columnPreference","preference","isActive","includes","push","CustomLabel","CustomLabelToRender","Label","clientProps","customLabelServerProps","Component","importMap","serverProps","fieldAffectsDataSubFields","label","labelWithPrefix","dotAccessor","replace","Heading","_jsx","disable","column","active","renderedCells","map","doc","rowIndex","relationTo","columnIndex","value","isLinkedColumn"],"sources":["../../../../src/providers/TableColumns/buildColumnState/index.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientComponentProps,\n ClientField,\n CollectionPreferences,\n CollectionSlug,\n Column,\n DefaultCellComponentProps,\n Document,\n Field,\n PaginatedDocs,\n Payload,\n SanitizedCollectionConfig,\n ServerComponentProps,\n StaticLabel,\n} from 'payload'\n\nimport {\n fieldIsHiddenOrDisabled,\n fieldIsID,\n fieldIsPresentationalOnly,\n flattenTopLevelFields,\n} from 'payload/shared'\nimport React from 'react'\n\nimport type { SortColumnProps } from '../../../elements/SortColumn/index.js'\n\nimport { RenderServerComponent } from '../../../elements/RenderServerComponent/index.js'\nimport {\n SortColumn,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\n} from '../../../exports/client/index.js'\nimport { filterFields } from './filterFields.js'\nimport { isColumnActive } from './isColumnActive.js'\nimport { renderCell } from './renderCell.js'\nimport { sortFieldMap } from './sortFieldMap.js'\n\nexport type BuildColumnStateArgs = {\n beforeRows?: Column[]\n clientFields: ClientField[]\n columnPreferences: CollectionPreferences['columns']\n columns?: CollectionPreferences['columns']\n customCellProps: DefaultCellComponentProps['customCellProps']\n enableLinkedCell?: boolean\n enableRowSelections: boolean\n enableRowTypes?: boolean\n i18n: I18nClient\n payload: Payload\n serverFields: Field[]\n sortColumnProps?: Partial<SortColumnProps>\n useAsTitle: SanitizedCollectionConfig['admin']['useAsTitle']\n} & (\n | {\n collectionSlug: CollectionSlug\n dataType: 'monomorphic'\n docs: PaginatedDocs['docs']\n }\n | {\n collectionSlug?: undefined\n dataType: 'polymorphic'\n docs: {\n relationTo: CollectionSlug\n value: Document\n }[]\n }\n)\n\nexport const buildColumnState = (args: BuildColumnStateArgs): Column[] => {\n const {\n beforeRows,\n clientFields,\n collectionSlug,\n columnPreferences,\n columns,\n customCellProps,\n dataType,\n docs,\n enableLinkedCell = true,\n enableRowSelections,\n i18n,\n payload,\n serverFields,\n sortColumnProps,\n useAsTitle,\n } = args\n\n // clientFields contains the fake `id` column\n let sortedFieldMap = flattenTopLevelFields(filterFields(clientFields), {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n }) as ClientField[]\n\n let _sortedFieldMap = flattenTopLevelFields(filterFields(serverFields), {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n }) as Field[] // TODO: think of a way to avoid this additional flatten\n\n // place the `ID` field first, if it exists\n // do the same for the `useAsTitle` field with precedence over the `ID` field\n // then sort the rest of the fields based on the `defaultColumns` or `columnPreferences`\n const idFieldIndex = sortedFieldMap?.findIndex((field) => fieldIsID(field))\n\n if (idFieldIndex > -1) {\n const idField = sortedFieldMap.splice(idFieldIndex, 1)[0]\n sortedFieldMap.unshift(idField)\n }\n\n const useAsTitleFieldIndex = useAsTitle\n ? sortedFieldMap.findIndex((field) => 'name' in field && field.name === useAsTitle)\n : -1\n\n if (useAsTitleFieldIndex > -1) {\n const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0]\n sortedFieldMap.unshift(useAsTitleField)\n }\n\n const sortTo = columnPreferences || columns\n\n if (sortTo) {\n // sort the fields to the order of `defaultColumns` or `columnPreferences`\n sortedFieldMap = sortFieldMap<ClientField>(sortedFieldMap, sortTo)\n _sortedFieldMap = sortFieldMap<Field>(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort\n }\n\n const activeColumnsIndices = []\n\n const sorted: Column[] = sortedFieldMap?.reduce((acc, clientField, colIndex) => {\n if (fieldIsHiddenOrDisabled(clientField) && !fieldIsID(clientField)) {\n return acc\n }\n\n const accessor =\n (clientField as any).accessor ?? ('name' in clientField ? clientField.name : undefined)\n\n const serverField = _sortedFieldMap.find((f) => {\n const fAccessor = (f as any).accessor ?? ('name' in f ? f.name : undefined)\n return fAccessor === accessor\n })\n\n const hasCustomCell =\n serverField?.admin &&\n 'components' in serverField.admin &&\n serverField.admin.components &&\n 'Cell' in serverField.admin.components &&\n serverField.admin.components.Cell\n\n if (serverField && serverField.type === 'group' && !hasCustomCell) {\n return acc // skip any group without a custom cell\n }\n\n const columnPreference = columnPreferences?.find(\n (preference) => clientField && 'name' in clientField && preference.accessor === accessor,\n )\n\n const isActive = isColumnActive({\n accessor,\n activeColumnsIndices,\n columnPreference,\n columns,\n })\n\n if (isActive && !activeColumnsIndices.includes(colIndex)) {\n activeColumnsIndices.push(colIndex)\n }\n\n let CustomLabel = undefined\n\n if (dataType === 'monomorphic') {\n const CustomLabelToRender =\n serverField &&\n 'admin' in serverField &&\n 'components' in serverField.admin &&\n 'Label' in serverField.admin.components &&\n serverField.admin.components.Label !== undefined // let it return `null`\n ? serverField.admin.components.Label\n : undefined\n\n // TODO: customComponent will be optional in v4\n const clientProps: Omit<ClientComponentProps, 'customComponents'> = {\n field: clientField,\n }\n\n const customLabelServerProps: Pick<\n ServerComponentProps,\n 'clientField' | 'collectionSlug' | 'field' | 'i18n' | 'payload'\n > = {\n clientField,\n collectionSlug,\n field: serverField,\n i18n,\n payload,\n }\n\n CustomLabel = CustomLabelToRender\n ? RenderServerComponent({\n clientProps,\n Component: CustomLabelToRender,\n importMap: payload.importMap,\n serverProps: customLabelServerProps,\n })\n : undefined\n }\n\n const fieldAffectsDataSubFields =\n clientField &&\n clientField.type &&\n (clientField.type === 'array' ||\n clientField.type === 'group' ||\n clientField.type === 'blocks')\n\n const label =\n clientField && 'labelWithPrefix' in clientField && clientField.labelWithPrefix !== undefined\n ? clientField.labelWithPrefix\n : 'label' in clientField\n ? clientField.label\n : undefined\n\n // Convert accessor to dot notation specifically for SortColumn sorting behavior\n const dotAccessor = accessor?.replace(/-/g, '.')\n\n const Heading = (\n <SortColumn\n disable={fieldAffectsDataSubFields || fieldIsPresentationalOnly(clientField) || undefined}\n Label={CustomLabel}\n label={label as StaticLabel}\n name={dotAccessor}\n {...(sortColumnProps || {})}\n />\n )\n\n const column: Column = {\n accessor,\n active: isActive,\n CustomLabel,\n field: clientField,\n Heading,\n renderedCells: isActive\n ? docs.map((doc, rowIndex) => {\n return renderCell({\n clientField,\n collectionSlug: dataType === 'monomorphic' ? collectionSlug : doc.relationTo,\n columnIndex: colIndex,\n customCellProps,\n doc: dataType === 'monomorphic' ? doc : doc.value,\n enableRowSelections,\n i18n,\n isLinkedColumn: enableLinkedCell && colIndex === activeColumnsIndices[0],\n payload,\n rowIndex,\n serverField,\n })\n })\n : [],\n }\n\n acc.push(column)\n\n return acc\n }, [])\n\n if (beforeRows) {\n sorted.unshift(...beforeRows)\n }\n\n return sorted\n}\n"],"mappings":";AAiBA,SACEA,uBAAuB,EACvBC,SAAS,EACTC,yBAAyB,EACzBC,qBAAqB,QAChB;AACP,OAAOC,KAAA,MAAW;AAIlB,SAASC,qBAAqB,QAAQ;AACtC,SACEC,UAAU,QAEL;AACP,SAASC,YAAY,QAAQ;AAC7B,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAC3B,SAASC,YAAY,QAAQ;AAgC7B,OAAO,MAAMC,gBAAA,GAAoBC,IAAA;EAC/B,MAAM;IACJC,UAAU;IACVC,YAAY;IACZC,cAAc;IACdC,iBAAiB;IACjBC,OAAO;IACPC,eAAe;IACfC,QAAQ;IACRC,IAAI;IACJC,gBAAA,GAAmB,IAAI;IACvBC,mBAAmB;IACnBC,IAAI;IACJC,OAAO;IACPC,YAAY;IACZC,eAAe;IACfC;EAAU,CACX,GAAGf,IAAA;EAEJ;EACA,IAAIgB,cAAA,GAAiBzB,qBAAA,CAAsBI,YAAA,CAAaO,YAAA,GAAe;IACrES,IAAA;IACAM,wBAAA,EAA0B;IAC1BC,kBAAA,EAAoB;EACtB;EAEA,IAAIC,eAAA,GAAkB5B,qBAAA,CAAsBI,YAAA,CAAakB,YAAA,GAAe;IACtEF,IAAA;IACAM,wBAAA,EAA0B;IAC1BC,kBAAA,EAAoB;EACtB,EAAc;EAAA;EAEd;EACA;EACA;EACA,MAAME,YAAA,GAAeJ,cAAA,EAAgBK,SAAA,CAAWC,KAAA,IAAUjC,SAAA,CAAUiC,KAAA;EAEpE,IAAIF,YAAA,GAAe,CAAC,GAAG;IACrB,MAAMG,OAAA,GAAUP,c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AA;UACAkE,cAAA,EAAgBpE,gBAAA,IAAoB0B,QAAA,KAAaL,oBAAoB,CAAC,EAAE;UACxElB,OAAA;UACA6D,QAAA;UACAnC;QACF;MACF,KACA;IACN;IAEAL,GAAA,CAAIkB,IAAI,CAACiB,MAAA;IAET,OAAOnC,GAAA;EACT,GAAG,EAAE;EAEL,IAAIhC,UAAA,EAAY;IACd8B,MAAA,CAAON,OAAO,IAAIxB,UAAA;EACpB;EAEA,OAAO8B,MAAA;AACT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fieldIsHiddenOrDisabled","fieldIsID","fieldIsPresentationalOnly","flattenTopLevelFields","React","RenderServerComponent","SortColumn","filterFields","isColumnActive","renderCell","sortFieldMap","buildColumnState","args","beforeRows","clientFields","collectionSlug","columns","customCellProps","dataType","docs","enableLinkedCell","enableRowSelections","i18n","payload","serverFields","sortColumnProps","useAsTitle","sortedFieldMap","keepPresentationalFields","moveSubFieldsToTop","_sortedFieldMap","idFieldIndex","findIndex","field","idField","splice","unshift","useAsTitleFieldIndex","name","useAsTitleField","sortTo","activeColumnsIndices","sorted","reduce","acc","clientField","colIndex","accessor","undefined","serverField","find","f","fAccessor","hasCustomCell","admin","components","Cell","type","columnPref","preference","isActive","column","includes","push","CustomLabel","CustomLabelToRender","Label","clientProps","customLabelServerProps","Component","importMap","serverProps","fieldAffectsDataSubFields","label","labelWithPrefix","dotAccessor","replace","Heading","_jsx","disable","active","renderedCells","map","doc","rowIndex","relationTo","columnIndex","value","isLinkedColumn"],"sources":["../../../../src/providers/TableColumns/buildColumnState/index.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientComponentProps,\n ClientField,\n CollectionPreferences,\n CollectionSlug,\n Column,\n DefaultCellComponentProps,\n Document,\n Field,\n PaginatedDocs,\n Payload,\n SanitizedCollectionConfig,\n ServerComponentProps,\n StaticLabel,\n} from 'payload'\n\nimport {\n fieldIsHiddenOrDisabled,\n fieldIsID,\n fieldIsPresentationalOnly,\n flattenTopLevelFields,\n} from 'payload/shared'\nimport React from 'react'\n\nimport type { SortColumnProps } from '../../../elements/SortColumn/index.js'\n\nimport { RenderServerComponent } from '../../../elements/RenderServerComponent/index.js'\nimport {\n SortColumn,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\n} from '../../../exports/client/index.js'\nimport { filterFields } from './filterFields.js'\nimport { isColumnActive } from './isColumnActive.js'\nimport { renderCell } from './renderCell.js'\nimport { sortFieldMap } from './sortFieldMap.js'\n\nexport type BuildColumnStateArgs = {\n beforeRows?: Column[]\n clientFields: ClientField[]\n columns?: CollectionPreferences['columns']\n customCellProps: DefaultCellComponentProps['customCellProps']\n enableLinkedCell?: boolean\n enableRowSelections: boolean\n enableRowTypes?: boolean\n i18n: I18nClient\n payload: Payload\n serverFields: Field[]\n sortColumnProps?: Partial<SortColumnProps>\n useAsTitle: SanitizedCollectionConfig['admin']['useAsTitle']\n} & (\n | {\n collectionSlug: CollectionSlug\n dataType: 'monomorphic'\n docs: PaginatedDocs['docs']\n }\n | {\n collectionSlug?: undefined\n dataType: 'polymorphic'\n docs: {\n relationTo: CollectionSlug\n value: Document\n }[]\n }\n)\n\nexport const buildColumnState = (args: BuildColumnStateArgs): Column[] => {\n const {\n beforeRows,\n clientFields,\n collectionSlug,\n columns,\n customCellProps,\n dataType,\n docs,\n enableLinkedCell = true,\n enableRowSelections,\n i18n,\n payload,\n serverFields,\n sortColumnProps,\n useAsTitle,\n } = args\n\n // clientFields contains the fake `id` column\n let sortedFieldMap = flattenTopLevelFields(filterFields(clientFields), {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n }) as ClientField[]\n\n let _sortedFieldMap = flattenTopLevelFields(filterFields(serverFields), {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n }) as Field[] // TODO: think of a way to avoid this additional flatten\n\n // place the `ID` field first, if it exists\n // do the same for the `useAsTitle` field with precedence over the `ID` field\n // then sort the rest of the fields based on the `defaultColumns` or `columns`\n const idFieldIndex = sortedFieldMap?.findIndex((field) => fieldIsID(field))\n\n if (idFieldIndex > -1) {\n const idField = sortedFieldMap.splice(idFieldIndex, 1)[0]\n sortedFieldMap.unshift(idField)\n }\n\n const useAsTitleFieldIndex = useAsTitle\n ? sortedFieldMap.findIndex((field) => 'name' in field && field.name === useAsTitle)\n : -1\n\n if (useAsTitleFieldIndex > -1) {\n const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0]\n sortedFieldMap.unshift(useAsTitleField)\n }\n\n const sortTo = columns\n\n if (sortTo) {\n // sort the fields to the order of `defaultColumns` or `columns`\n sortedFieldMap = sortFieldMap<ClientField>(sortedFieldMap, sortTo)\n _sortedFieldMap = sortFieldMap<Field>(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort\n }\n\n const activeColumnsIndices = []\n\n const sorted: Column[] = sortedFieldMap?.reduce((acc, clientField, colIndex) => {\n if (fieldIsHiddenOrDisabled(clientField) && !fieldIsID(clientField)) {\n return acc\n }\n\n const accessor =\n (clientField as any).accessor ?? ('name' in clientField ? clientField.name : undefined)\n\n const serverField = _sortedFieldMap.find((f) => {\n const fAccessor = (f as any).accessor ?? ('name' in f ? f.name : undefined)\n return fAccessor === accessor\n })\n\n const hasCustomCell =\n serverField?.admin &&\n 'components' in serverField.admin &&\n serverField.admin.components &&\n 'Cell' in serverField.admin.components &&\n serverField.admin.components.Cell\n\n if (serverField && serverField.type === 'group' && !hasCustomCell) {\n return acc // skip any group without a custom cell\n }\n\n const columnPref = columns?.find(\n (preference) => clientField && 'name' in clientField && preference.accessor === accessor,\n )\n\n const isActive = isColumnActive({\n accessor,\n activeColumnsIndices,\n column: columnPref,\n columns,\n })\n\n if (isActive && !activeColumnsIndices.includes(colIndex)) {\n activeColumnsIndices.push(colIndex)\n }\n\n let CustomLabel = undefined\n\n if (dataType === 'monomorphic') {\n const CustomLabelToRender =\n serverField &&\n 'admin' in serverField &&\n 'components' in serverField.admin &&\n 'Label' in serverField.admin.components &&\n serverField.admin.components.Label !== undefined // let it return `null`\n ? serverField.admin.components.Label\n : undefined\n\n // TODO: customComponent will be optional in v4\n const clientProps: Omit<ClientComponentProps, 'customComponents'> = {\n field: clientField,\n }\n\n const customLabelServerProps: Pick<\n ServerComponentProps,\n 'clientField' | 'collectionSlug' | 'field' | 'i18n' | 'payload'\n > = {\n clientField,\n collectionSlug,\n field: serverField,\n i18n,\n payload,\n }\n\n CustomLabel = CustomLabelToRender\n ? RenderServerComponent({\n clientProps,\n Component: CustomLabelToRender,\n importMap: payload.importMap,\n serverProps: customLabelServerProps,\n })\n : undefined\n }\n\n const fieldAffectsDataSubFields =\n clientField &&\n clientField.type &&\n (clientField.type === 'array' ||\n clientField.type === 'group' ||\n clientField.type === 'blocks')\n\n const label =\n clientField && 'labelWithPrefix' in clientField && clientField.labelWithPrefix !== undefined\n ? clientField.labelWithPrefix\n : 'label' in clientField\n ? clientField.label\n : undefined\n\n // Convert accessor to dot notation specifically for SortColumn sorting behavior\n const dotAccessor = accessor?.replace(/-/g, '.')\n\n const Heading = (\n <SortColumn\n disable={fieldAffectsDataSubFields || fieldIsPresentationalOnly(clientField) || undefined}\n Label={CustomLabel}\n label={label as StaticLabel}\n name={dotAccessor}\n {...(sortColumnProps || {})}\n />\n )\n\n const column: Column = {\n accessor,\n active: isActive,\n CustomLabel,\n field: clientField,\n Heading,\n renderedCells: isActive\n ? docs.map((doc, rowIndex) => {\n return renderCell({\n clientField,\n collectionSlug: dataType === 'monomorphic' ? collectionSlug : doc.relationTo,\n columnIndex: colIndex,\n customCellProps,\n doc: dataType === 'monomorphic' ? doc : doc.value,\n enableRowSelections,\n i18n,\n isLinkedColumn: enableLinkedCell && colIndex === activeColumnsIndices[0],\n payload,\n rowIndex,\n serverField,\n })\n })\n : [],\n }\n\n acc.push(column)\n\n return acc\n }, [])\n\n if (beforeRows) {\n sorted.unshift(...be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AA,CAAON,OAAO,IAAIvB,UAAA;EACpB;EAEA,OAAO6B,MAAA;AACT","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ColumnPreference } from 'payload';
|
|
2
|
-
export declare function isColumnActive({ accessor, activeColumnsIndices,
|
|
2
|
+
export declare function isColumnActive({ accessor, activeColumnsIndices, column, columns, }: {
|
|
3
3
|
accessor: string;
|
|
4
4
|
activeColumnsIndices: number[];
|
|
5
|
-
|
|
5
|
+
column: ColumnPreference;
|
|
6
6
|
columns: ColumnPreference[];
|
|
7
7
|
}): boolean;
|
|
8
8
|
//# sourceMappingURL=isColumnActive.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isColumnActive.d.ts","sourceRoot":"","sources":["../../../../src/providers/TableColumns/buildColumnState/isColumnActive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"isColumnActive.d.ts","sourceRoot":"","sources":["../../../../src/providers/TableColumns/buildColumnState/isColumnActive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,oBAAoB,EACpB,MAAM,EACN,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,MAAM,CAAA;IAChB,oBAAoB,EAAE,MAAM,EAAE,CAAA;IAC9B,MAAM,EAAE,gBAAgB,CAAA;IACxB,OAAO,EAAE,gBAAgB,EAAE,CAAA;CAC5B,WAUA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export function isColumnActive({
|
|
2
2
|
accessor,
|
|
3
3
|
activeColumnsIndices,
|
|
4
|
-
|
|
4
|
+
column,
|
|
5
5
|
columns
|
|
6
6
|
}) {
|
|
7
|
-
if (
|
|
8
|
-
return
|
|
7
|
+
if (column) {
|
|
8
|
+
return column.active;
|
|
9
9
|
} else if (columns && Array.isArray(columns) && columns.length > 0) {
|
|
10
|
-
return Boolean(columns.find(
|
|
10
|
+
return Boolean(columns.find(col => col.accessor === accessor)?.active);
|
|
11
11
|
} else if (activeColumnsIndices.length < 4) {
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isColumnActive.js","names":["isColumnActive","accessor","activeColumnsIndices","
|
|
1
|
+
{"version":3,"file":"isColumnActive.js","names":["isColumnActive","accessor","activeColumnsIndices","column","columns","active","Array","isArray","length","Boolean","find","col"],"sources":["../../../../src/providers/TableColumns/buildColumnState/isColumnActive.ts"],"sourcesContent":["import type { ColumnPreference } from 'payload'\n\nexport function isColumnActive({\n accessor,\n activeColumnsIndices,\n column,\n columns,\n}: {\n accessor: string\n activeColumnsIndices: number[]\n column: ColumnPreference\n columns: ColumnPreference[]\n}) {\n if (column) {\n return column.active\n } else if (columns && Array.isArray(columns) && columns.length > 0) {\n return Boolean(columns.find((col) => col.accessor === accessor)?.active)\n } else if (activeColumnsIndices.length < 4) {\n return true\n }\n\n return false\n}\n"],"mappings":"AAEA,OAAO,SAASA,eAAe;EAC7BC,QAAQ;EACRC,oBAAoB;EACpBC,MAAM;EACNC;AAAO,CAMR;EACC,IAAID,MAAA,EAAQ;IACV,OAAOA,MAAA,CAAOE,MAAM;EACtB,OAAO,IAAID,OAAA,IAAWE,KAAA,CAAMC,OAAO,CAACH,OAAA,KAAYA,OAAA,CAAQI,MAAM,GAAG,GAAG;IAClE,OAAOC,OAAA,CAAQL,OAAA,CAAQM,IAAI,CAAEC,GAAA,IAAQA,GAAA,CAAIV,QAAQ,KAAKA,QAAA,GAAWI,MAAA;EACnE,OAAO,IAAIH,oBAAA,CAAqBM,MAAM,GAAG,GAAG;IAC1C,OAAO;EACT;EAEA,OAAO;AACT","ignoreList":[]}
|
|
@@ -149,10 +149,10 @@ const buildTableState = async args => {
|
|
|
149
149
|
collection: collectionSlug,
|
|
150
150
|
depth: 0,
|
|
151
151
|
draft: true,
|
|
152
|
-
limit: query?.limit
|
|
152
|
+
limit: query?.limit,
|
|
153
153
|
locale: req.locale,
|
|
154
154
|
overrideAccess: false,
|
|
155
|
-
page: query?.page
|
|
155
|
+
page: query?.page,
|
|
156
156
|
sort: query?.sort,
|
|
157
157
|
user: req.user,
|
|
158
158
|
where: query?.where
|
|
@@ -168,7 +168,6 @@ const buildTableState = async args => {
|
|
|
168
168
|
clientConfig,
|
|
169
169
|
collectionConfig,
|
|
170
170
|
collections: Array.isArray(collectionSlug) ? collectionSlug : undefined,
|
|
171
|
-
columnPreferences: Array.isArray(collectionSlug) ? collectionPreferences?.columns : undefined,
|
|
172
171
|
columns,
|
|
173
172
|
docs,
|
|
174
173
|
enableRowSelections,
|