@payloadcms/next 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.
@@ -1 +1 @@
1
- {"version":3,"file":"handleServerFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/handleServerFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAYpE,eAAO,MAAM,qBAAqB,EAAE,qBAgCnC,CAAA"}
1
+ {"version":3,"file":"handleServerFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/handleServerFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAapE,eAAO,MAAM,qBAAqB,EAAE,qBAkCnC,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import { copyDataFromLocaleHandler } from '@payloadcms/ui/rsc';
2
2
  import { buildFormStateHandler } from '@payloadcms/ui/utilities/buildFormState';
3
3
  import { buildTableStateHandler } from '@payloadcms/ui/utilities/buildTableState';
4
+ import { getFolderResultsComponentAndDataHandler } from '@payloadcms/ui/utilities/getFolderResultsComponentAndData';
4
5
  import { schedulePublishHandler } from '@payloadcms/ui/utilities/schedulePublishHandler';
5
6
  import { renderDocumentHandler } from '../views/Document/handleServerFunction.js';
6
7
  import { renderDocumentSlotsHandler } from '../views/Document/renderDocumentSlots.js';
@@ -28,6 +29,7 @@ export const handleServerFunctions = async args => {
28
29
  const serverFunctions = {
29
30
  'copy-data-from-locale': copyDataFromLocaleHandler,
30
31
  'form-state': buildFormStateHandler,
32
+ 'get-folder-results-component-and-data': getFolderResultsComponentAndDataHandler,
31
33
  'render-document': renderDocumentHandler,
32
34
  'render-document-slots': renderDocumentSlotsHandler,
33
35
  'render-list': renderListHandler,
@@ -1 +1 @@
1
- {"version":3,"file":"handleServerFunctions.js","names":["copyDataFromLocaleHandler","buildFormStateHandler","buildTableStateHandler","schedulePublishHandler","renderDocumentHandler","renderDocumentSlotsHandler","renderListHandler","initReq","handleServerFunctions","args","name","fnKey","fnArgs","config","configPromise","importMap","req","key","augmentedArgs","serverFunctions","fn","Error"],"sources":["../../src/utilities/handleServerFunctions.ts"],"sourcesContent":["import type { ServerFunction, ServerFunctionHandler } from 'payload'\n\nimport { copyDataFromLocaleHandler } from '@payloadcms/ui/rsc'\nimport { buildFormStateHandler } from '@payloadcms/ui/utilities/buildFormState'\nimport { buildTableStateHandler } from '@payloadcms/ui/utilities/buildTableState'\nimport { schedulePublishHandler } from '@payloadcms/ui/utilities/schedulePublishHandler'\n\nimport { renderDocumentHandler } from '../views/Document/handleServerFunction.js'\nimport { renderDocumentSlotsHandler } from '../views/Document/renderDocumentSlots.js'\nimport { renderListHandler } from '../views/List/handleServerFunction.js'\nimport { initReq } from './initReq.js'\n\nexport const handleServerFunctions: ServerFunctionHandler = async (args) => {\n const { name: fnKey, args: fnArgs, config: configPromise, importMap } = args\n\n const { req } = await initReq({\n configPromise,\n importMap,\n key: 'RootLayout',\n })\n\n const augmentedArgs: Parameters<ServerFunction>[0] = {\n ...fnArgs,\n importMap,\n req,\n }\n\n const serverFunctions = {\n 'copy-data-from-locale': copyDataFromLocaleHandler as any as ServerFunction,\n 'form-state': buildFormStateHandler as any as ServerFunction,\n 'render-document': renderDocumentHandler as any as ServerFunction,\n 'render-document-slots': renderDocumentSlotsHandler as any as ServerFunction,\n 'render-list': renderListHandler as any as ServerFunction,\n 'schedule-publish': schedulePublishHandler as any as ServerFunction,\n 'table-state': buildTableStateHandler as any as ServerFunction,\n }\n\n const fn = serverFunctions[fnKey]\n\n if (!fn) {\n throw new Error(`Unknown Server Function: ${fnKey}`)\n }\n\n return fn(augmentedArgs)\n}\n"],"mappings":"AAEA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,qBAAqB,QAAQ;AACtC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,sBAAsB,QAAQ;AAEvC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,iBAAiB,QAAQ;AAClC,SAASC,OAAO,QAAQ;AAExB,OAAO,MAAMC,qBAAA,GAA+C,MAAOC,IAAA;EACjE,MAAM;IAAEC,IAAA,EAAMC,KAAK;IAAEF,IAAA,EAAMG,MAAM;IAAEC,MAAA,EAAQC,aAAa;IAAEC;EAAS,CAAE,GAAGN,IAAA;EAExE,MAAM;IAAEO;EAAG,CAAE,GAAG,MAAMT,OAAA,CAAQ;IAC5BO,aAAA;IACAC,SAAA;IACAE,GAAA,EAAK;EACP;EAEA,MAAMC,aAAA,GAA+C;IACnD,GAAGN,MAAM;IACTG,SAAA;IACAC;EACF;EAEA,MAAMG,eAAA,GAAkB;IACtB,yBAAyBnB,yBAAA;IACzB,cAAcC,qBAAA;IACd,mBAAmBG,qBAAA;IACnB,yBAAyBC,0BAAA;IACzB,eAAeC,iBAAA;IACf,oBAAoBH,sBAAA;IACpB,eAAeD;EACjB;EAEA,MAAMkB,EAAA,GAAKD,eAAe,CAACR,KAAA,CAAM;EAEjC,IAAI,CAACS,EAAA,EAAI;IACP,MAAM,IAAIC,KAAA,CAAM,4BAA4BV,KAAA,EAAO;EACrD;EAEA,OAAOS,EAAA,CAAGF,aAAA;AACZ","ignoreList":[]}
1
+ {"version":3,"file":"handleServerFunctions.js","names":["copyDataFromLocaleHandler","buildFormStateHandler","buildTableStateHandler","getFolderResultsComponentAndDataHandler","schedulePublishHandler","renderDocumentHandler","renderDocumentSlotsHandler","renderListHandler","initReq","handleServerFunctions","args","name","fnKey","fnArgs","config","configPromise","importMap","req","key","augmentedArgs","serverFunctions","fn","Error"],"sources":["../../src/utilities/handleServerFunctions.ts"],"sourcesContent":["import type { ServerFunction, ServerFunctionHandler } from 'payload'\n\nimport { copyDataFromLocaleHandler } from '@payloadcms/ui/rsc'\nimport { buildFormStateHandler } from '@payloadcms/ui/utilities/buildFormState'\nimport { buildTableStateHandler } from '@payloadcms/ui/utilities/buildTableState'\nimport { getFolderResultsComponentAndDataHandler } from '@payloadcms/ui/utilities/getFolderResultsComponentAndData'\nimport { schedulePublishHandler } from '@payloadcms/ui/utilities/schedulePublishHandler'\n\nimport { renderDocumentHandler } from '../views/Document/handleServerFunction.js'\nimport { renderDocumentSlotsHandler } from '../views/Document/renderDocumentSlots.js'\nimport { renderListHandler } from '../views/List/handleServerFunction.js'\nimport { initReq } from './initReq.js'\n\nexport const handleServerFunctions: ServerFunctionHandler = async (args) => {\n const { name: fnKey, args: fnArgs, config: configPromise, importMap } = args\n\n const { req } = await initReq({\n configPromise,\n importMap,\n key: 'RootLayout',\n })\n\n const augmentedArgs: Parameters<ServerFunction>[0] = {\n ...fnArgs,\n importMap,\n req,\n }\n\n const serverFunctions = {\n 'copy-data-from-locale': copyDataFromLocaleHandler as any as ServerFunction,\n 'form-state': buildFormStateHandler as any as ServerFunction,\n 'get-folder-results-component-and-data':\n getFolderResultsComponentAndDataHandler as any as ServerFunction,\n 'render-document': renderDocumentHandler as any as ServerFunction,\n 'render-document-slots': renderDocumentSlotsHandler as any as ServerFunction,\n 'render-list': renderListHandler as any as ServerFunction,\n 'schedule-publish': schedulePublishHandler as any as ServerFunction,\n 'table-state': buildTableStateHandler as any as ServerFunction,\n }\n\n const fn = serverFunctions[fnKey]\n\n if (!fn) {\n throw new Error(`Unknown Server Function: ${fnKey}`)\n }\n\n return fn(augmentedArgs)\n}\n"],"mappings":"AAEA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,qBAAqB,QAAQ;AACtC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,uCAAuC,QAAQ;AACxD,SAASC,sBAAsB,QAAQ;AAEvC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,iBAAiB,QAAQ;AAClC,SAASC,OAAO,QAAQ;AAExB,OAAO,MAAMC,qBAAA,GAA+C,MAAOC,IAAA;EACjE,MAAM;IAAEC,IAAA,EAAMC,KAAK;IAAEF,IAAA,EAAMG,MAAM;IAAEC,MAAA,EAAQC,aAAa;IAAEC;EAAS,CAAE,GAAGN,IAAA;EAExE,MAAM;IAAEO;EAAG,CAAE,GAAG,MAAMT,OAAA,CAAQ;IAC5BO,aAAA;IACAC,SAAA;IACAE,GAAA,EAAK;EACP;EAEA,MAAMC,aAAA,GAA+C;IACnD,GAAGN,MAAM;IACTG,SAAA;IACAC;EACF;EAEA,MAAMG,eAAA,GAAkB;IACtB,yBAAyBpB,yBAAA;IACzB,cAAcC,qBAAA;IACd,yCACEE,uCAAA;IACF,mBAAmBE,qBAAA;IACnB,yBAAyBC,0BAAA;IACzB,eAAeC,iBAAA;IACf,oBAAoBH,sBAAA;IACpB,eAAeF;EACjB;EAEA,MAAMmB,EAAA,GAAKD,eAAe,CAACR,KAAA,CAAM;EAEjC,IAAI,CAACS,EAAA,EAAI;IACP,MAAM,IAAIC,KAAA,CAAM,4BAA4BV,KAAA,EAAO;EACrD;EAEA,OAAOS,EAAA,CAAGF,aAAA;AACZ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"buildView.d.ts","sourceRoot":"","sources":["../../../src/views/BrowseByFolder/buildView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,+BAA+B,EAE/B,SAAS,EAEV,MAAM,SAAS,CAAA;AAYhB,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,KAAK,EAAE,SAAS,CAAA;CACjB,GAAG,oBAAoB,CAAA;AAExB,eAAO,MAAM,uBAAuB,SAC5B,mBAAmB,KACxB,OAAO,CAAC,+BAA+B,CAiLzC,CAAA"}
1
+ {"version":3,"file":"buildView.d.ts","sourceRoot":"","sources":["../../../src/views/BrowseByFolder/buildView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,+BAA+B,EAI/B,SAAS,EACV,MAAM,SAAS,CAAA;AAShB,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,KAAK,EAAE,SAAS,CAAA;CACjB,GAAG,oBAAoB,CAAA;AAExB,eAAO,MAAM,uBAAuB,SAC5B,mBAAmB,KACxB,OAAO,CAAC,+BAA+B,CAuJzC,CAAA"}
@@ -1,12 +1,10 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { DefaultBrowseByFolderView, FolderProvider, HydrateAuthProvider } from '@payloadcms/ui';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { DefaultBrowseByFolderView, HydrateAuthProvider } from '@payloadcms/ui';
3
3
  import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';
4
+ import { getFolderResultsComponentAndData, upsertPreferences } from '@payloadcms/ui/rsc';
4
5
  import { formatAdminURL } from '@payloadcms/ui/shared';
5
6
  import { redirect } from 'next/navigation.js';
6
- import { getFolderData } from 'payload';
7
- import { buildFolderWhereConstraints } from 'payload/shared';
8
7
  import React from 'react';
9
- import { getPreferences } from '../../utilities/getPreferences.js';
10
8
  export const buildBrowseByFolderView = async args => {
11
9
  const {
12
10
  browseByFolderSlugs: browseByFolderSlugsFromArgs = [],
@@ -34,64 +32,43 @@ export const buildBrowseByFolderView = async args => {
34
32
  },
35
33
  visibleEntities
36
34
  } = initPageResult;
37
- const browseByFolderSlugs = browseByFolderSlugsFromArgs.filter(collectionSlug => permissions?.collections?.[collectionSlug]?.read && visibleEntities.collections.includes(collectionSlug));
38
35
  if (config.folders === false || config.folders.browseByFolder === false) {
39
36
  throw new Error('not-found');
40
37
  }
38
+ const browseByFolderSlugs = browseByFolderSlugsFromArgs.filter(collectionSlug => permissions?.collections?.[collectionSlug]?.read && visibleEntities.collections.includes(collectionSlug));
41
39
  const query = queryFromArgs || queryFromReq;
42
- const selectedCollectionSlugs = Array.isArray(query?.relationTo) && query.relationTo.length ? query.relationTo.filter(slug => browseByFolderSlugs.includes(slug) || config.folders && slug === config.folders.slug) : [...browseByFolderSlugs, config.folders.slug];
40
+ const activeCollectionFolderSlugs = Array.isArray(query?.relationTo) && query.relationTo.length ? query.relationTo.filter(slug => browseByFolderSlugs.includes(slug) || config.folders && slug === config.folders.slug) : [...browseByFolderSlugs, config.folders.slug];
43
41
  const {
44
42
  routes: {
45
43
  admin: adminRoute
46
44
  }
47
45
  } = config;
48
- const folderCollectionConfig = payload.collections[config.folders.slug].config;
49
- const browseByFolderPreferences = await getPreferences('browse-by-folder', payload, user.id, user.collection);
50
- let documentWhere = undefined;
51
- let folderWhere = undefined;
52
- // if folderID, dont make a documentWhere since it only queries root folders
53
- for (const collectionSlug of selectedCollectionSlugs) {
54
- if (collectionSlug === config.folders.slug) {
55
- const folderCollectionConstraints = await buildFolderWhereConstraints({
56
- collectionConfig: folderCollectionConfig,
57
- folderID,
58
- localeCode: fullLocale?.code,
59
- req: initPageResult.req,
60
- search: typeof query?.search === 'string' ? query.search : undefined
61
- });
62
- if (folderCollectionConstraints) {
63
- folderWhere = folderCollectionConstraints;
64
- }
65
- } else if (folderID) {
66
- if (!documentWhere) {
67
- documentWhere = {
68
- or: []
69
- };
70
- }
71
- const collectionConfig = payload.collections[collectionSlug].config;
72
- if (collectionConfig.folders && collectionConfig.folders.browseByFolder === true) {
73
- const collectionConstraints = await buildFolderWhereConstraints({
74
- collectionConfig,
75
- folderID,
76
- localeCode: fullLocale?.code,
77
- req: initPageResult.req,
78
- search: typeof query?.search === 'string' ? query.search : undefined
79
- });
80
- if (collectionConstraints) {
81
- documentWhere.or.push(collectionConstraints);
82
- }
83
- }
46
+ /**
47
+ * @todo: find a pattern to avoid setting preferences on hard navigation, i.e. direct links, page refresh, etc.
48
+ * This will ensure that prefs are only updated when explicitly set by the user
49
+ * This could potentially be done by injecting a `sessionID` into the params and comparing it against a session cookie
50
+ */
51
+ const browseByFolderPreferences = await upsertPreferences({
52
+ key: 'browse-by-folder',
53
+ req: initPageResult.req,
54
+ value: {
55
+ sort: query?.sort
84
56
  }
85
- }
57
+ });
58
+ const sortPreference = browseByFolderPreferences?.sort || '_folderOrDocumentTitle';
59
+ const viewPreference = browseByFolderPreferences?.viewPreference || 'grid';
86
60
  const {
87
61
  breadcrumbs,
88
62
  documents,
63
+ FolderResultsComponent,
89
64
  subfolders
90
- } = await getFolderData({
91
- documentWhere,
65
+ } = await getFolderResultsComponentAndData({
66
+ activeCollectionSlugs: activeCollectionFolderSlugs,
67
+ browseByFolder: false,
68
+ displayAs: viewPreference,
92
69
  folderID,
93
- folderWhere,
94
- req: initPageResult.req
70
+ req: initPageResult.req,
71
+ sort: sortPreference
95
72
  });
96
73
  const resolvedFolderID = breadcrumbs[breadcrumbs.length - 1]?.id;
97
74
  if (!isInDrawer && (resolvedFolderID && folderID && folderID !== resolvedFolderID || folderID && !resolvedFolderID)) {
@@ -120,29 +97,31 @@ export const buildBrowseByFolderView = async args => {
120
97
  // serverProps,
121
98
  // })
122
99
  // documents cannot be created without a parent folder in this view
123
- const hasCreatePermissionCollectionSlugs = folderID ? [config.folders.slug, ...browseByFolderSlugs] : [config.folders.slug];
100
+ const allowCreateCollectionSlugs = resolvedFolderID ? [config.folders.slug, ...browseByFolderSlugs] : [config.folders.slug];
124
101
  return {
125
- View: /*#__PURE__*/_jsxs(FolderProvider, {
126
- breadcrumbs: breadcrumbs,
127
- documents: documents,
128
- filteredCollectionSlugs: selectedCollectionSlugs,
129
- folderCollectionSlugs: browseByFolderSlugs,
130
- folderFieldName: config.folders.fieldName,
131
- folderID: folderID,
132
- subfolders: subfolders,
102
+ View: /*#__PURE__*/_jsxs(_Fragment, {
133
103
  children: [/*#__PURE__*/_jsx(HydrateAuthProvider, {
134
104
  permissions: permissions
135
105
  }), RenderServerComponent({
136
106
  clientProps: {
137
107
  // ...folderViewSlots,
108
+ activeCollectionFolderSlugs,
109
+ allCollectionFolderSlugs: browseByFolderSlugs,
110
+ allowCreateCollectionSlugs,
111
+ baseFolderPath: `/browse-by-folder`,
112
+ breadcrumbs,
138
113
  disableBulkDelete,
139
114
  disableBulkEdit,
115
+ documents,
140
116
  enableRowSelections,
141
- hasCreatePermissionCollectionSlugs,
142
- selectedCollectionSlugs,
143
- viewPreference: browseByFolderPreferences?.value?.viewPreference
117
+ folderFieldName: config.folders.fieldName,
118
+ folderID: resolvedFolderID || null,
119
+ FolderResultsComponent,
120
+ sort: sortPreference,
121
+ subfolders,
122
+ viewPreference
144
123
  },
145
- // Component:config.folders?.components?.views?.list?.Component,
124
+ // Component:config.folders?.components?.views?.BrowseByFolders?.Component,
146
125
  Fallback: DefaultBrowseByFolderView,
147
126
  importMap: payload.importMap,
148
127
  serverProps
@@ -1 +1 @@
1
- {"version":3,"file":"buildView.js","names":["DefaultBrowseByFolderView","FolderProvider","HydrateAuthProvider","RenderServerComponent","formatAdminURL","redirect","getFolderData","buildFolderWhereConstraints","React","getPreferences","buildBrowseByFolderView","args","browseByFolderSlugs","browseByFolderSlugsFromArgs","disableBulkDelete","disableBulkEdit","enableRowSelections","folderID","initPageResult","isInDrawer","params","query","queryFromArgs","searchParams","locale","fullLocale","permissions","req","i18n","payload","config","queryFromReq","user","visibleEntities","filter","collectionSlug","collections","read","includes","folders","browseByFolder","Error","selectedCollectionSlugs","Array","isArray","relationTo","length","slug","routes","admin","adminRoute","folderCollectionConfig","browseByFolderPreferences","id","collection","documentWhere","undefined","folderWhere","folderCollectionConstraints","collectionConfig","localeCode","code","search","or","collectionConstraints","push","breadcrumbs","documents","subfolders","resolvedFolderID","path","serverURL","serverProps","hasCreatePermissionCollectionSlugs","View","_jsxs","filteredCollectionSlugs","folderCollectionSlugs","folderFieldName","fieldName","_jsx","clientProps","viewPreference","value","Fallback","importMap"],"sources":["../../../src/views/BrowseByFolder/buildView.tsx"],"sourcesContent":["import type {\n AdminViewServerProps,\n BuildCollectionFolderViewResult,\n FolderListViewServerPropsOnly,\n ListQuery,\n Where,\n} from 'payload'\n\nimport { DefaultBrowseByFolderView, FolderProvider, HydrateAuthProvider } from '@payloadcms/ui'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { formatAdminURL } from '@payloadcms/ui/shared'\nimport { redirect } from 'next/navigation.js'\nimport { getFolderData } from 'payload'\nimport { buildFolderWhereConstraints } from 'payload/shared'\nimport React from 'react'\n\nimport { getPreferences } from '../../utilities/getPreferences.js'\n\nexport type BuildFolderViewArgs = {\n customCellProps?: Record<string, any>\n disableBulkDelete?: boolean\n disableBulkEdit?: boolean\n enableRowSelections: boolean\n folderID?: number | string\n isInDrawer?: boolean\n overrideEntityVisibility?: boolean\n query: ListQuery\n} & AdminViewServerProps\n\nexport const buildBrowseByFolderView = async (\n args: BuildFolderViewArgs,\n): Promise<BuildCollectionFolderViewResult> => {\n const {\n browseByFolderSlugs: browseByFolderSlugsFromArgs = [],\n disableBulkDelete,\n disableBulkEdit,\n enableRowSelections,\n folderID,\n initPageResult,\n isInDrawer,\n params,\n query: queryFromArgs,\n searchParams,\n } = args\n\n const {\n locale: fullLocale,\n permissions,\n req: {\n i18n,\n payload,\n payload: { config },\n query: queryFromReq,\n user,\n },\n visibleEntities,\n } = initPageResult\n\n const browseByFolderSlugs = browseByFolderSlugsFromArgs.filter(\n (collectionSlug) =>\n permissions?.collections?.[collectionSlug]?.read &&\n visibleEntities.collections.includes(collectionSlug),\n )\n\n if (config.folders === false || config.folders.browseByFolder === false) {\n throw new Error('not-found')\n }\n\n const query = queryFromArgs || queryFromReq\n const selectedCollectionSlugs: string[] =\n Array.isArray(query?.relationTo) && query.relationTo.length\n ? query.relationTo.filter(\n (slug) =>\n browseByFolderSlugs.includes(slug) || (config.folders && slug === config.folders.slug),\n )\n : [...browseByFolderSlugs, config.folders.slug]\n\n const {\n routes: { admin: adminRoute },\n } = config\n\n const folderCollectionConfig = payload.collections[config.folders.slug].config\n\n const browseByFolderPreferences = await getPreferences<{ viewPreference: string }>(\n 'browse-by-folder',\n payload,\n user.id,\n user.collection,\n )\n\n let documentWhere: undefined | Where = undefined\n let folderWhere: undefined | Where = undefined\n // if folderID, dont make a documentWhere since it only queries root folders\n for (const collectionSlug of selectedCollectionSlugs) {\n if (collectionSlug === config.folders.slug) {\n const folderCollectionConstraints = await buildFolderWhereConstraints({\n collectionConfig: folderCollectionConfig,\n folderID,\n localeCode: fullLocale?.code,\n req: initPageResult.req,\n search: typeof query?.search === 'string' ? query.search : undefined,\n })\n\n if (folderCollectionConstraints) {\n folderWhere = folderCollectionConstraints\n }\n } else if (folderID) {\n if (!documentWhere) {\n documentWhere = {\n or: [],\n }\n }\n\n const collectionConfig = payload.collections[collectionSlug].config\n if (collectionConfig.folders && collectionConfig.folders.browseByFolder === true) {\n const collectionConstraints = await buildFolderWhereConstraints({\n collectionConfig,\n folderID,\n localeCode: fullLocale?.code,\n req: initPageResult.req,\n search: typeof query?.search === 'string' ? query.search : undefined,\n })\n\n if (collectionConstraints) {\n documentWhere.or.push(collectionConstraints)\n }\n }\n }\n }\n\n const { breadcrumbs, documents, subfolders } = await getFolderData({\n documentWhere,\n folderID,\n folderWhere,\n req: initPageResult.req,\n })\n\n const resolvedFolderID = breadcrumbs[breadcrumbs.length - 1]?.id\n\n if (\n !isInDrawer &&\n ((resolvedFolderID && folderID && folderID !== resolvedFolderID) ||\n (folderID && !resolvedFolderID))\n ) {\n redirect(\n formatAdminURL({\n adminRoute,\n path: config.admin.routes.browseByFolder,\n serverURL: config.serverURL,\n }),\n )\n }\n\n const serverProps: Omit<FolderListViewServerPropsOnly, 'collectionConfig' | 'listPreferences'> = {\n documents,\n i18n,\n locale: fullLocale,\n params,\n payload,\n permissions,\n searchParams,\n subfolders,\n user,\n }\n\n // const folderViewSlots = renderFolderViewSlots({\n // clientProps: {\n // },\n // description: staticDescription,\n // payload,\n // serverProps,\n // })\n\n // documents cannot be created without a parent folder in this view\n const hasCreatePermissionCollectionSlugs = folderID\n ? [config.folders.slug, ...browseByFolderSlugs]\n : [config.folders.slug]\n\n return {\n View: (\n <FolderProvider\n breadcrumbs={breadcrumbs}\n documents={documents}\n filteredCollectionSlugs={selectedCollectionSlugs}\n folderCollectionSlugs={browseByFolderSlugs}\n folderFieldName={config.folders.fieldName}\n folderID={folderID}\n subfolders={subfolders}\n >\n <HydrateAuthProvider permissions={permissions} />\n {RenderServerComponent({\n clientProps: {\n // ...folderViewSlots,\n disableBulkDelete,\n disableBulkEdit,\n enableRowSelections,\n hasCreatePermissionCollectionSlugs,\n selectedCollectionSlugs,\n viewPreference: browseByFolderPreferences?.value?.viewPreference,\n },\n // Component:config.folders?.components?.views?.list?.Component,\n Fallback: DefaultBrowseByFolderView,\n importMap: payload.importMap,\n serverProps,\n })}\n </FolderProvider>\n ),\n }\n}\n"],"mappings":";AAQA,SAASA,yBAAyB,EAAEC,cAAc,EAAEC,mBAAmB,QAAQ;AAC/E,SAASC,qBAAqB,QAAQ;AACtC,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,2BAA2B,QAAQ;AAC5C,OAAOC,KAAA,MAAW;AAElB,SAASC,cAAc,QAAQ;AAa/B,OAAO,MAAMC,uBAAA,GAA0B,MACr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BAAA;MACvBkE,eAAA,EAAiBhD,MAAA,CAAOS,OAAO,CAACwC,SAAS;MACzC9D,QAAA,EAAUA,QAAA;MACVmD,UAAA,EAAYA,UAAA;8BAEZY,IAAA,CAAC9E,mBAAA;QAAoBwB,WAAA,EAAaA;UACjCvB,qBAAA,CAAsB;QACrB8E,WAAA,EAAa;UACX;UACAnE,iBAAA;UACAC,eAAA;UACAC,mBAAA;UACAyD,kCAAA;UACA/B,uBAAA;UACAwC,cAAA,EAAgB9B,yBAAA,EAA2B+B,KAAA,EAAOD;QACpD;QACA;QACAE,QAAA,EAAUpF,yBAAA;QACVqF,SAAA,EAAWxD,OAAA,CAAQwD,SAAS;QAC5Bb;MACF;;EAGN;AACF","ignoreList":[]}
1
+ {"version":3,"file":"buildView.js","names":["DefaultBrowseByFolderView","HydrateAuthProvider","RenderServerComponent","getFolderResultsComponentAndData","upsertPreferences","formatAdminURL","redirect","React","buildBrowseByFolderView","args","browseByFolderSlugs","browseByFolderSlugsFromArgs","disableBulkDelete","disableBulkEdit","enableRowSelections","folderID","initPageResult","isInDrawer","params","query","queryFromArgs","searchParams","locale","fullLocale","permissions","req","i18n","payload","config","queryFromReq","user","visibleEntities","folders","browseByFolder","Error","filter","collectionSlug","collections","read","includes","activeCollectionFolderSlugs","Array","isArray","relationTo","length","slug","routes","admin","adminRoute","browseByFolderPreferences","key","value","sort","sortPreference","viewPreference","breadcrumbs","documents","FolderResultsComponent","subfolders","activeCollectionSlugs","displayAs","resolvedFolderID","id","path","serverURL","serverProps","allowCreateCollectionSlugs","View","_jsxs","_Fragment","_jsx","clientProps","allCollectionFolderSlugs","baseFolderPath","folderFieldName","fieldName","Fallback","importMap"],"sources":["../../../src/views/BrowseByFolder/buildView.tsx"],"sourcesContent":["import type {\n AdminViewServerProps,\n BuildCollectionFolderViewResult,\n FolderListViewClientProps,\n FolderListViewServerPropsOnly,\n FolderSortKeys,\n ListQuery,\n} from 'payload'\n\nimport { DefaultBrowseByFolderView, HydrateAuthProvider } from '@payloadcms/ui'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { getFolderResultsComponentAndData, upsertPreferences } from '@payloadcms/ui/rsc'\nimport { formatAdminURL } from '@payloadcms/ui/shared'\nimport { redirect } from 'next/navigation.js'\nimport React from 'react'\n\nexport type BuildFolderViewArgs = {\n customCellProps?: Record<string, any>\n disableBulkDelete?: boolean\n disableBulkEdit?: boolean\n enableRowSelections: boolean\n folderID?: number | string\n isInDrawer?: boolean\n overrideEntityVisibility?: boolean\n query: ListQuery\n} & AdminViewServerProps\n\nexport const buildBrowseByFolderView = async (\n args: BuildFolderViewArgs,\n): Promise<BuildCollectionFolderViewResult> => {\n const {\n browseByFolderSlugs: browseByFolderSlugsFromArgs = [],\n disableBulkDelete,\n disableBulkEdit,\n enableRowSelections,\n folderID,\n initPageResult,\n isInDrawer,\n params,\n query: queryFromArgs,\n searchParams,\n } = args\n\n const {\n locale: fullLocale,\n permissions,\n req: {\n i18n,\n payload,\n payload: { config },\n query: queryFromReq,\n user,\n },\n visibleEntities,\n } = initPageResult\n\n if (config.folders === false || config.folders.browseByFolder === false) {\n throw new Error('not-found')\n }\n\n const browseByFolderSlugs = browseByFolderSlugsFromArgs.filter(\n (collectionSlug) =>\n permissions?.collections?.[collectionSlug]?.read &&\n visibleEntities.collections.includes(collectionSlug),\n )\n\n const query = queryFromArgs || queryFromReq\n const activeCollectionFolderSlugs: string[] =\n Array.isArray(query?.relationTo) && query.relationTo.length\n ? query.relationTo.filter(\n (slug) =>\n browseByFolderSlugs.includes(slug) || (config.folders && slug === config.folders.slug),\n )\n : [...browseByFolderSlugs, config.folders.slug]\n\n const {\n routes: { admin: adminRoute },\n } = config\n\n /**\n * @todo: find a pattern to avoid setting preferences on hard navigation, i.e. direct links, page refresh, etc.\n * This will ensure that prefs are only updated when explicitly set by the user\n * This could potentially be done by injecting a `sessionID` into the params and comparing it against a session cookie\n */\n const browseByFolderPreferences = await upsertPreferences<{\n sort?: FolderSortKeys\n viewPreference?: 'grid' | 'list'\n }>({\n key: 'browse-by-folder',\n req: initPageResult.req,\n value: {\n sort: query?.sort as FolderSortKeys,\n },\n })\n\n const sortPreference: FolderSortKeys = browseByFolderPreferences?.sort || '_folderOrDocumentTitle'\n const viewPreference = browseByFolderPreferences?.viewPreference || 'grid'\n\n const { breadcrumbs, documents, FolderResultsComponent, subfolders } =\n await getFolderResultsComponentAndData({\n activeCollectionSlugs: activeCollectionFolderSlugs,\n browseByFolder: false,\n displayAs: viewPreference,\n folderID,\n req: initPageResult.req,\n sort: sortPreference,\n })\n\n const resolvedFolderID = breadcrumbs[breadcrumbs.length - 1]?.id\n\n if (\n !isInDrawer &&\n ((resolvedFolderID && folderID && folderID !== resolvedFolderID) ||\n (folderID && !resolvedFolderID))\n ) {\n redirect(\n formatAdminURL({\n adminRoute,\n path: config.admin.routes.browseByFolder,\n serverURL: config.serverURL,\n }),\n )\n }\n\n const serverProps: Omit<FolderListViewServerPropsOnly, 'collectionConfig' | 'listPreferences'> = {\n documents,\n i18n,\n locale: fullLocale,\n params,\n payload,\n permissions,\n searchParams,\n subfolders,\n user,\n }\n\n // const folderViewSlots = renderFolderViewSlots({\n // clientProps: {\n // },\n // description: staticDescription,\n // payload,\n // serverProps,\n // })\n\n // documents cannot be created without a parent folder in this view\n const allowCreateCollectionSlugs = resolvedFolderID\n ? [config.folders.slug, ...browseByFolderSlugs]\n : [config.folders.slug]\n\n return {\n View: (\n <>\n <HydrateAuthProvider permissions={permissions} />\n {RenderServerComponent({\n clientProps: {\n // ...folderViewSlots,\n activeCollectionFolderSlugs,\n allCollectionFolderSlugs: browseByFolderSlugs,\n allowCreateCollectionSlugs,\n baseFolderPath: `/browse-by-folder`,\n breadcrumbs,\n disableBulkDelete,\n disableBulkEdit,\n documents,\n enableRowSelections,\n folderFieldName: config.folders.fieldName,\n folderID: resolvedFolderID || null,\n FolderResultsComponent,\n sort: sortPreference,\n subfolders,\n viewPreference,\n } satisfies FolderListViewClientProps,\n // Component:config.folders?.components?.views?.BrowseByFolders?.Component,\n Fallback: DefaultBrowseByFolderView,\n importMap: payload.importMap,\n serverProps,\n })}\n </>\n ),\n }\n}\n"],"mappings":";AASA,SAASA,yBAAyB,EAAEC,mBAAmB,QAAQ;AAC/D,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gCAAgC,EAAEC,iBAAiB,QAAQ;AACpE,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,OAAOC,KAAA,MAAW;AAalB,OAAO,MAAMC,uBAAA,GAA0B,MACrCC,IAAA;EAEA,MAAM;IACJC,mBAAA,EAAqBC,2BAAA,GAA8B,EAAE;IACrDC,iBAAiB;IACjBC,eAAe;IACfC,mBAAmB;IACnBC,QAAQ;IACRC,cAAc;IACdC,UAAU;IACVC,MAAM;IACNC,KAAA,EAAOC,aAAa;IACpBC;EAAY,CACb,GAAGZ,IAAA;EAEJ,MAAM;IACJa,MAAA,EAAQC,UAAU;IAClBC,WAAW;IACXC,GAAA,EAAK;MACHC,IAAI;MACJC,OAAO;MACPA,OAAA,EAAS;QAAEC;MAAM,CAAE;MACnBT,KAAA,EAAOU,YAAY;MACnBC;IAAI,CACL;IACDC;EAAe,CAChB,GAAGf,cAAA;EAEJ,IAAIY,MAAA,CAAOI,OAAO,KAAK,SAASJ,MAAA,CAAOI,OAAO,CAACC,cAAc,KAAK,OAAO;IACvE,MAAM,IAAIC,KAAA,CAAM;EAClB;EAEA,MAAMxB,mBAAA,GAAsBC,2BAAA,CAA4BwB,MAAM,CAC3DC,cAAA,IACCZ,WAAA,EAAaa,WAAA,GAAcD,cAAA,CAAe,EAAEE,IAAA,IAC5CP,eAAA,CAAgBM,WAAW,CAACE,QAAQ,CAACH,cAAA;EAGzC,MAAMjB,KAAA,GAAQC,aAAA,IAAiBS,YAAA;EAC/B,MAAMW,2BAAA,GACJC,KAAA,CAAMC,OAAO,CAACvB,KAAA,EAAOwB,UAAA,KAAexB,KAAA,CAAMwB,UAAU,CAAC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;MACxC+B,SAAA,EAAWpC,MAAA,CAAOoC;IACpB;EAEJ;EAEA,MAAMC,WAAA,GAA2F;IAC/FT,SAAA;IACA9B,IAAA;IACAJ,MAAA,EAAQC,UAAA;IACRL,MAAA;IACAS,OAAA;IACAH,WAAA;IACAH,YAAA;IACAqC,UAAA;IACA5B;EACF;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA,MAAMoC,0BAAA,GAA6BL,gBAAA,GAC/B,CAACjC,MAAA,CAAOI,OAAO,CAACa,IAAI,E,GAAKnC,mBAAA,CAAoB,GAC7C,CAACkB,MAAA,CAAOI,OAAO,CAACa,IAAI,CAAC;EAEzB,OAAO;IACLsB,IAAA,eACEC,KAAA,CAAAC,SAAA;8BACEC,IAAA,CAACrE,mBAAA;QAAoBuB,WAAA,EAAaA;UACjCtB,qBAAA,CAAsB;QACrBqE,WAAA,EAAa;UACX;UACA/B,2BAAA;UACAgC,wBAAA,EAA0B9D,mBAAA;UAC1BwD,0BAAA;UACAO,cAAA,EAAgB,mBAAmB;UACnClB,WAAA;UACA3C,iBAAA;UACAC,eAAA;UACA2C,SAAA;UACA1C,mBAAA;UACA4D,eAAA,EAAiB9C,MAAA,CAAOI,OAAO,CAAC2C,SAAS;UACzC5D,QAAA,EAAU8C,gBAAA,IAAoB;UAC9BJ,sBAAA;UACAL,IAAA,EAAMC,cAAA;UACNK,UAAA;UACAJ;QACF;QACA;QACAsB,QAAA,EAAU5E,yBAAA;QACV6E,SAAA,EAAWlD,OAAA,CAAQkD,SAAS;QAC5BZ;MACF;;EAGN;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"buildView.d.ts","sourceRoot":"","sources":["../../../src/views/CollectionFolders/buildView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,+BAA+B,EAE/B,SAAS,EAEV,MAAM,SAAS,CAAA;AAchB,MAAM,MAAM,kCAAkC,GAAG;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,KAAK,EAAE,SAAS,CAAA;CACjB,GAAG,oBAAoB,CAAA;AAExB;;GAEG;AACH,eAAO,MAAM,yBAAyB,SAC9B,kCAAkC,KACvC,OAAO,CAAC,+BAA+B,CAkLzC,CAAA"}
1
+ {"version":3,"file":"buildView.d.ts","sourceRoot":"","sources":["../../../src/views/CollectionFolders/buildView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,+BAA+B,EAI/B,SAAS,EACV,MAAM,SAAS,CAAA;AAWhB,MAAM,MAAM,kCAAkC,GAAG;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,KAAK,EAAE,SAAS,CAAA;CACjB,GAAG,oBAAoB,CAAA;AAExB;;GAEG;AACH,eAAO,MAAM,yBAAyB,SAC9B,kCAAkC,KACvC,OAAO,CAAC,+BAA+B,CA0KzC,CAAA"}
@@ -1,12 +1,10 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { DefaultCollectionFolderView, FolderProvider, HydrateAuthProvider } from '@payloadcms/ui';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { DefaultCollectionFolderView, HydrateAuthProvider } from '@payloadcms/ui';
3
3
  import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';
4
+ import { getFolderResultsComponentAndData, upsertPreferences } from '@payloadcms/ui/rsc';
4
5
  import { formatAdminURL } from '@payloadcms/ui/shared';
5
6
  import { redirect } from 'next/navigation.js';
6
- import { getFolderData } from 'payload';
7
- import { buildFolderWhereConstraints } from 'payload/shared';
8
7
  import React from 'react';
9
- import { getPreferences } from '../../utilities/getPreferences.js';
10
8
  /**
11
9
  * Builds the entire view for collection-folder views on the server
12
10
  */
@@ -41,56 +39,48 @@ export const buildCollectionFolderView = async args => {
41
39
  },
42
40
  visibleEntities
43
41
  } = initPageResult;
44
- if (!permissions?.collections?.[collectionSlug]?.read) {
42
+ if (!config.folders) {
43
+ throw new Error('not-found');
44
+ }
45
+ if (!permissions?.collections?.[collectionSlug]?.read || !permissions?.collections?.[config.folders.slug].read) {
45
46
  throw new Error('not-found');
46
47
  }
47
48
  if (collectionConfig) {
49
+ if (!visibleEntities.collections.includes(collectionSlug) && !overrideEntityVisibility || !config.folders) {
50
+ throw new Error('not-found');
51
+ }
48
52
  const query = queryFromArgs || queryFromReq;
49
- const collectionFolderPreferences = await getPreferences(`${collectionSlug}-collection-folder`, payload, user.id, user.collection);
50
- const sortPreference = collectionFolderPreferences?.value.sort;
53
+ /**
54
+ * @todo: find a pattern to avoid setting preferences on hard navigation, i.e. direct links, page refresh, etc.
55
+ * This will ensure that prefs are only updated when explicitly set by the user
56
+ * This could potentially be done by injecting a `sessionID` into the params and comparing it against a session cookie
57
+ */
58
+ const collectionFolderPreferences = await upsertPreferences({
59
+ key: `${collectionSlug}-collection-folder`,
60
+ req: initPageResult.req,
61
+ value: {
62
+ sort: query?.sort
63
+ }
64
+ });
65
+ const sortPreference = collectionFolderPreferences?.sort || '_folderOrDocumentTitle';
66
+ const viewPreference = collectionFolderPreferences?.viewPreference || 'grid';
51
67
  const {
52
68
  routes: {
53
69
  admin: adminRoute
54
70
  }
55
71
  } = config;
56
- if (!visibleEntities.collections.includes(collectionSlug) && !overrideEntityVisibility || !config.folders) {
57
- throw new Error('not-found');
58
- }
59
- let folderWhere;
60
- const folderCollectionConfig = payload.collections[config.folders.slug].config;
61
- const folderCollectionConstraints = await buildFolderWhereConstraints({
62
- collectionConfig: folderCollectionConfig,
63
- folderID,
64
- localeCode: fullLocale?.code,
65
- req: initPageResult.req,
66
- search: typeof query?.search === 'string' ? query.search : undefined,
67
- sort: sortPreference
68
- });
69
- if (folderCollectionConstraints) {
70
- folderWhere = folderCollectionConstraints;
71
- }
72
- let documentWhere;
73
- const collectionConstraints = await buildFolderWhereConstraints({
74
- collectionConfig,
75
- folderID,
76
- localeCode: fullLocale?.code,
77
- req: initPageResult.req,
78
- search: typeof query?.search === 'string' ? query.search : undefined,
79
- sort: sortPreference
80
- });
81
- if (collectionConstraints) {
82
- documentWhere = collectionConstraints;
83
- }
84
72
  const {
85
73
  breadcrumbs,
86
74
  documents,
75
+ FolderResultsComponent,
87
76
  subfolders
88
- } = await getFolderData({
89
- collectionSlug,
90
- documentWhere,
77
+ } = await getFolderResultsComponentAndData({
78
+ activeCollectionSlugs: [config.folders.slug, collectionSlug],
79
+ browseByFolder: false,
80
+ displayAs: viewPreference,
91
81
  folderID,
92
- folderWhere,
93
- req: initPageResult.req
82
+ req: initPageResult.req,
83
+ sort: sortPreference
94
84
  });
95
85
  const resolvedFolderID = breadcrumbs[breadcrumbs.length - 1]?.id;
96
86
  if (!isInDrawer && (resolvedFolderID && folderID && folderID !== resolvedFolderID || folderID && !resolvedFolderID)) {
@@ -100,11 +90,6 @@ export const buildCollectionFolderView = async args => {
100
90
  serverURL: config.serverURL
101
91
  }));
102
92
  }
103
- const newDocumentURL = formatAdminURL({
104
- adminRoute,
105
- path: `/collections/${collectionSlug}/create`
106
- });
107
- const hasCreatePermission = permissions?.collections?.[collectionSlug]?.create;
108
93
  const serverProps = {
109
94
  collectionConfig,
110
95
  documents,
@@ -133,29 +118,30 @@ export const buildCollectionFolderView = async args => {
133
118
  // })
134
119
  const search = query?.search;
135
120
  return {
136
- View: /*#__PURE__*/_jsxs(FolderProvider, {
137
- breadcrumbs: breadcrumbs,
138
- collectionSlug: collectionSlug,
139
- documents: documents,
140
- folderCollectionSlugs: [collectionSlug],
141
- folderFieldName: config.folders.fieldName,
142
- folderID: folderID,
143
- search: search,
144
- subfolders: subfolders,
121
+ View: /*#__PURE__*/_jsxs(_Fragment, {
145
122
  children: [/*#__PURE__*/_jsx(HydrateAuthProvider, {
146
123
  permissions: permissions
147
124
  }), RenderServerComponent({
148
125
  clientProps: {
149
126
  // ...folderViewSlots,
127
+ allCollectionFolderSlugs: [config.folders.slug, collectionSlug],
128
+ allowCreateCollectionSlugs: [permissions?.collections?.[config.folders.slug]?.create ? config.folders.slug : null, permissions?.collections?.[collectionSlug]?.create ? collectionSlug : null].filter(Boolean),
129
+ baseFolderPath: `/collections/${collectionSlug}/${config.folders.slug}`,
130
+ breadcrumbs,
150
131
  collectionSlug,
151
132
  disableBulkDelete,
152
133
  disableBulkEdit,
134
+ documents,
153
135
  enableRowSelections,
154
- hasCreatePermission,
155
- newDocumentURL,
156
- viewPreference: collectionFolderPreferences?.value?.viewPreference
136
+ folderFieldName: config.folders.fieldName,
137
+ folderID: resolvedFolderID || null,
138
+ FolderResultsComponent,
139
+ search,
140
+ sort: sortPreference,
141
+ subfolders,
142
+ viewPreference
157
143
  },
158
- Component: collectionConfig?.admin?.components?.views?.list?.Component,
144
+ // Component: collectionConfig?.admin?.components?.views?.Folders?.Component,
159
145
  Fallback: DefaultCollectionFolderView,
160
146
  importMap: payload.importMap,
161
147
  serverProps
@@ -1 +1 @@
1
- {"version":3,"file":"buildView.js","names":["DefaultCollectionFolderView","FolderProvider","HydrateAuthProvider","RenderServerComponent","formatAdminURL","redirect","getFolderData","buildFolderWhereConstraints","React","getPreferences","buildCollectionFolderView","args","disableBulkDelete","disableBulkEdit","enableRowSelections","folderID","initPageResult","isInDrawer","overrideEntityVisibility","params","query","queryFromArgs","searchParams","collectionConfig","slug","collectionSlug","locale","fullLocale","permissions","req","i18n","payload","config","queryFromReq","user","visibleEntities","collections","read","Error","collectionFolderPreferences","id","collection","sortPreference","value","sort","routes","admin","adminRoute","includes","folders","folderWhere","folderCollectionConfig","folderCollectionConstraints","localeCode","code","search","undefined","documentWhere","collectionConstraints","breadcrumbs","documents","subfolders","resolvedFolderID","length","path","serverURL","newDocumentURL","hasCreatePermission","create","serverProps","View","_jsxs","folderCollectionSlugs","folderFieldName","fieldName","_jsx","clientProps","viewPreference","Component","components","views","list","Fallback","importMap"],"sources":["../../../src/views/CollectionFolders/buildView.tsx"],"sourcesContent":["import type {\n AdminViewServerProps,\n BuildCollectionFolderViewResult,\n FolderListViewServerPropsOnly,\n ListQuery,\n Where,\n} from 'payload'\n\nimport { DefaultCollectionFolderView, FolderProvider, HydrateAuthProvider } from '@payloadcms/ui'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { formatAdminURL } from '@payloadcms/ui/shared'\nimport { redirect } from 'next/navigation.js'\nimport { getFolderData } from 'payload'\nimport { buildFolderWhereConstraints } from 'payload/shared'\nimport React from 'react'\n\nimport { getPreferences } from '../../utilities/getPreferences.js'\n\n// import { renderFolderViewSlots } from './renderFolderViewSlots.js'\n\nexport type BuildCollectionFolderViewStateArgs = {\n disableBulkDelete?: boolean\n disableBulkEdit?: boolean\n enableRowSelections: boolean\n folderID?: number | string\n isInDrawer?: boolean\n overrideEntityVisibility?: boolean\n query: ListQuery\n} & AdminViewServerProps\n\n/**\n * Builds the entire view for collection-folder views on the server\n */\nexport const buildCollectionFolderView = async (\n args: BuildCollectionFolderViewStateArgs,\n): Promise<BuildCollectionFolderViewResult> => {\n const {\n disableBulkDelete,\n disableBulkEdit,\n enableRowSelections,\n folderID,\n initPageResult,\n isInDrawer,\n overrideEntityVisibility,\n params,\n query: queryFromArgs,\n searchParams,\n } = args\n\n const {\n collectionConfig,\n collectionConfig: { slug: collectionSlug },\n locale: fullLocale,\n permissions,\n req: {\n i18n,\n payload,\n payload: { config },\n query: queryFromReq,\n user,\n },\n visibleEntities,\n } = initPageResult\n\n if (!permissions?.collections?.[collectionSlug]?.read) {\n throw new Error('not-found')\n }\n\n if (collectionConfig) {\n const query = queryFromArgs || queryFromReq\n\n const collectionFolderPreferences = await getPreferences<{\n sort?: string\n viewPreference: string\n }>(`${collectionSlug}-collection-folder`, payload, user.id, user.collection)\n\n const sortPreference = collectionFolderPreferences?.value.sort\n\n const {\n routes: { admin: adminRoute },\n } = config\n\n if (\n (!visibleEntities.collections.includes(collectionSlug) && !overrideEntityVisibility) ||\n !config.folders\n ) {\n throw new Error('not-found')\n }\n\n let folderWhere: undefined | Where\n const folderCollectionConfig = payload.collections[config.folders.slug].config\n const folderCollectionConstraints = await buildFolderWhereConstraints({\n collectionConfig: folderCollectionConfig,\n folderID,\n localeCode: fullLocale?.code,\n req: initPageResult.req,\n search: typeof query?.search === 'string' ? query.search : undefined,\n sort: sortPreference,\n })\n\n if (folderCollectionConstraints) {\n folderWhere = folderCollectionConstraints\n }\n\n let documentWhere: undefined | Where\n const collectionConstraints = await buildFolderWhereConstraints({\n collectionConfig,\n folderID,\n localeCode: fullLocale?.code,\n req: initPageResult.req,\n search: typeof query?.search === 'string' ? query.search : undefined,\n sort: sortPreference,\n })\n if (collectionConstraints) {\n documentWhere = collectionConstraints\n }\n\n const { breadcrumbs, documents, subfolders } = await getFolderData({\n collectionSlug,\n documentWhere,\n folderID,\n folderWhere,\n req: initPageResult.req,\n })\n\n const resolvedFolderID = breadcrumbs[breadcrumbs.length - 1]?.id\n\n if (\n !isInDrawer &&\n ((resolvedFolderID && folderID && folderID !== resolvedFolderID) ||\n (folderID && !resolvedFolderID))\n ) {\n redirect(\n formatAdminURL({\n adminRoute,\n path: `/collections/${collectionSlug}/${config.folders.slug}`,\n serverURL: config.serverURL,\n }),\n )\n }\n\n const newDocumentURL = formatAdminURL({\n adminRoute,\n path: `/collections/${collectionSlug}/create`,\n })\n\n const hasCreatePermission = permissions?.collections?.[collectionSlug]?.create\n\n const serverProps: FolderListViewServerPropsOnly = {\n collectionConfig,\n documents,\n i18n,\n locale: fullLocale,\n params,\n payload,\n permissions,\n searchParams,\n subfolders,\n user,\n }\n\n // We could support slots in the folder view in the future\n // const folderViewSlots = renderFolderViewSlots({\n // clientProps: {\n // collectionSlug,\n // hasCreatePermission,\n // newDocumentURL,\n // },\n // collectionConfig,\n // description: typeof collectionConfig.admin.description === 'function'\n // ? collectionConfig.admin.description({ t: i18n.t })\n // : collectionConfig.admin.description,\n // payload,\n // serverProps,\n // })\n\n const search = query?.search as string\n\n return {\n View: (\n <FolderProvider\n breadcrumbs={breadcrumbs}\n collectionSlug={collectionSlug}\n documents={documents}\n folderCollectionSlugs={[collectionSlug]}\n folderFieldName={config.folders.fieldName}\n folderID={folderID}\n search={search}\n subfolders={subfolders}\n >\n <HydrateAuthProvider permissions={permissions} />\n {RenderServerComponent({\n clientProps: {\n // ...folderViewSlots,\n collectionSlug,\n disableBulkDelete,\n disableBulkEdit,\n enableRowSelections,\n hasCreatePermission,\n newDocumentURL,\n viewPreference: collectionFolderPreferences?.value?.viewPreference,\n },\n Component: collectionConfig?.admin?.components?.views?.list?.Component,\n Fallback: DefaultCollectionFolderView,\n importMap: payload.importMap,\n serverProps,\n })}\n </FolderProvider>\n ),\n }\n }\n\n throw new Error('not-found')\n}\n"],"mappings":";AAQA,SAASA,2BAA2B,EAAEC,cAAc,EAAEC,mBAAmB,QAAQ;AACjF,SAASC,qBAAqB,QAAQ;AACtC,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,2BAA2B,QAAQ;AAC5C,OAAOC,KAAA,MAAW;AAElB,SAASC,cAAc,QAAQ;AAc/B;;;AAGA,OAAO,MAAMC,yBAAA,GAA4B,MACvCC,IAAA;EAEA,MAAM;IACJC,iBAAiB;IACjBC,eAAe;IACfC,mBAAmB;IACnBC,QAAQ;IACRC,cAAc;IACdC,UAAU;IACVC,wBAAwB;IACxBC,MAAM;IACNC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["DefaultCollectionFolderView","HydrateAuthProvider","RenderServerComponent","getFolderResultsComponentAndData","upsertPreferences","formatAdminURL","redirect","React","buildCollectionFolderView","args","disableBulkDelete","disableBulkEdit","enableRowSelections","folderID","initPageResult","isInDrawer","overrideEntityVisibility","params","query","queryFromArgs","searchParams","collectionConfig","slug","collectionSlug","locale","fullLocale","permissions","req","i18n","payload","config","queryFromReq","user","visibleEntities","folders","Error","collections","read","includes","collectionFolderPreferences","key","value","sort","sortPreference","viewPreference","routes","admin","adminRoute","breadcrumbs","documents","FolderResultsComponent","subfolders","activeCollectionSlugs","browseByFolder","displayAs","resolvedFolderID","length","id","path","serverURL","serverProps","search","View","_jsxs","_Fragment","_jsx","clientProps","allCollectionFolderSlugs","allowCreateCollectionSlugs","create","filter","Boolean","baseFolderPath","folderFieldName","fieldName","Fallback","importMap"],"sources":["../../../src/views/CollectionFolders/buildView.tsx"],"sourcesContent":["import type {\n AdminViewServerProps,\n BuildCollectionFolderViewResult,\n FolderListViewClientProps,\n FolderListViewServerPropsOnly,\n FolderSortKeys,\n ListQuery,\n} from 'payload'\n\nimport { DefaultCollectionFolderView, HydrateAuthProvider } from '@payloadcms/ui'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { getFolderResultsComponentAndData, upsertPreferences } from '@payloadcms/ui/rsc'\nimport { formatAdminURL } from '@payloadcms/ui/shared'\nimport { redirect } from 'next/navigation.js'\nimport React from 'react'\n\n// import { renderFolderViewSlots } from './renderFolderViewSlots.js'\n\nexport type BuildCollectionFolderViewStateArgs = {\n disableBulkDelete?: boolean\n disableBulkEdit?: boolean\n enableRowSelections: boolean\n folderID?: number | string\n isInDrawer?: boolean\n overrideEntityVisibility?: boolean\n query: ListQuery\n} & AdminViewServerProps\n\n/**\n * Builds the entire view for collection-folder views on the server\n */\nexport const buildCollectionFolderView = async (\n args: BuildCollectionFolderViewStateArgs,\n): Promise<BuildCollectionFolderViewResult> => {\n const {\n disableBulkDelete,\n disableBulkEdit,\n enableRowSelections,\n folderID,\n initPageResult,\n isInDrawer,\n overrideEntityVisibility,\n params,\n query: queryFromArgs,\n searchParams,\n } = args\n\n const {\n collectionConfig,\n collectionConfig: { slug: collectionSlug },\n locale: fullLocale,\n permissions,\n req: {\n i18n,\n payload,\n payload: { config },\n query: queryFromReq,\n user,\n },\n visibleEntities,\n } = initPageResult\n\n if (!config.folders) {\n throw new Error('not-found')\n }\n\n if (\n !permissions?.collections?.[collectionSlug]?.read ||\n !permissions?.collections?.[config.folders.slug].read\n ) {\n throw new Error('not-found')\n }\n\n if (collectionConfig) {\n if (\n (!visibleEntities.collections.includes(collectionSlug) && !overrideEntityVisibility) ||\n !config.folders\n ) {\n throw new Error('not-found')\n }\n\n const query = queryFromArgs || queryFromReq\n\n /**\n * @todo: find a pattern to avoid setting preferences on hard navigation, i.e. direct links, page refresh, etc.\n * This will ensure that prefs are only updated when explicitly set by the user\n * This could potentially be done by injecting a `sessionID` into the params and comparing it against a session cookie\n */\n const collectionFolderPreferences = await upsertPreferences<{\n sort?: FolderSortKeys\n viewPreference?: 'grid' | 'list'\n }>({\n key: `${collectionSlug}-collection-folder`,\n req: initPageResult.req,\n value: {\n sort: query?.sort as FolderSortKeys,\n },\n })\n\n const sortPreference: FolderSortKeys =\n collectionFolderPreferences?.sort || '_folderOrDocumentTitle'\n const viewPreference = collectionFolderPreferences?.viewPreference || 'grid'\n\n const {\n routes: { admin: adminRoute },\n } = config\n\n const { breadcrumbs, documents, FolderResultsComponent, subfolders } =\n await getFolderResultsComponentAndData({\n activeCollectionSlugs: [config.folders.slug, collectionSlug],\n browseByFolder: false,\n displayAs: viewPreference,\n folderID,\n req: initPageResult.req,\n sort: sortPreference,\n })\n\n const resolvedFolderID = breadcrumbs[breadcrumbs.length - 1]?.id\n\n if (\n !isInDrawer &&\n ((resolvedFolderID && folderID && folderID !== resolvedFolderID) ||\n (folderID && !resolvedFolderID))\n ) {\n redirect(\n formatAdminURL({\n adminRoute,\n path: `/collections/${collectionSlug}/${config.folders.slug}`,\n serverURL: config.serverURL,\n }),\n )\n }\n\n const serverProps: FolderListViewServerPropsOnly = {\n collectionConfig,\n documents,\n i18n,\n locale: fullLocale,\n params,\n payload,\n permissions,\n searchParams,\n subfolders,\n user,\n }\n\n // We could support slots in the folder view in the future\n // const folderViewSlots = renderFolderViewSlots({\n // clientProps: {\n // collectionSlug,\n // hasCreatePermission,\n // newDocumentURL,\n // },\n // collectionConfig,\n // description: typeof collectionConfig.admin.description === 'function'\n // ? collectionConfig.admin.description({ t: i18n.t })\n // : collectionConfig.admin.description,\n // payload,\n // serverProps,\n // })\n\n const search = query?.search as string\n\n return {\n View: (\n <>\n <HydrateAuthProvider permissions={permissions} />\n {RenderServerComponent({\n clientProps: {\n // ...folderViewSlots,\n allCollectionFolderSlugs: [config.folders.slug, collectionSlug],\n allowCreateCollectionSlugs: [\n permissions?.collections?.[config.folders.slug]?.create\n ? config.folders.slug\n : null,\n permissions?.collections?.[collectionSlug]?.create ? collectionSlug : null,\n ].filter(Boolean),\n baseFolderPath: `/collections/${collectionSlug}/${config.folders.slug}`,\n breadcrumbs,\n collectionSlug,\n disableBulkDelete,\n disableBulkEdit,\n documents,\n enableRowSelections,\n folderFieldName: config.folders.fieldName,\n folderID: resolvedFolderID || null,\n FolderResultsComponent,\n search,\n sort: sortPreference,\n subfolders,\n viewPreference,\n } satisfies FolderListViewClientProps,\n // Component: collectionConfig?.admin?.components?.views?.Folders?.Component,\n Fallback: DefaultCollectionFolderView,\n importMap: payload.importMap,\n serverProps,\n })}\n </>\n ),\n }\n }\n\n throw new Error('not-found')\n}\n"],"mappings":";AASA,SAASA,2BAA2B,EAAEC,mBAAmB,QAAQ;AACjE,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gCAAgC,EAAEC,iBAAiB,QAAQ;AACpE,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,OAAOC,KAAA,MAAW;AAclB;;;AAGA,OAAO,MAAMC,yBAAA,GA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A;UAAoByB,WAAA,EAAaA;YACjCxB,qBAAA,CAAsB;UACrBgE,WAAA,EAAa;YACX;YACAC,wBAAA,EAA0B,CAACrC,MAAA,CAAOI,OAAO,CAACZ,IAAI,EAAEC,cAAA,CAAe;YAC/D6C,0BAAA,EAA4B,CAC1B1C,WAAA,EAAaU,WAAA,GAAcN,MAAA,CAAOI,OAAO,CAACZ,IAAI,CAAC,EAAE+C,MAAA,GAC7CvC,MAAA,CAAOI,OAAO,CAACZ,IAAI,GACnB,MACJI,WAAA,EAAaU,WAAA,GAAcb,cAAA,CAAe,EAAE8C,MAAA,GAAS9C,cAAA,GAAiB,KACvE,CAAC+C,MAAM,CAACC,OAAA;YACTC,cAAA,EAAgB,gBAAgBjD,cAAA,IAAkBO,MAAA,CAAOI,OAAO,CAACZ,IAAI,EAAE;YACvE0B,WAAA;YACAzB,cAAA;YACAb,iBAAA;YACAC,eAAA;YACAsC,SAAA;YACArC,mBAAA;YACA6D,eAAA,EAAiB3C,MAAA,CAAOI,OAAO,CAACwC,SAAS;YACzC7D,QAAA,EAAU0C,gBAAA,IAAoB;YAC9BL,sBAAA;YACAW,MAAA;YACAnB,IAAA,EAAMC,cAAA;YACNQ,UAAA;YACAP;UACF;UACA;UACA+B,QAAA,EAAU3E,2BAAA;UACV4E,SAAA,EAAW/C,OAAA,CAAQ+C,SAAS;UAC5BhB;QACF;;IAGN;EACF;EAEA,MAAM,IAAIzB,KAAA,CAAM;AAClB","ignoreList":[]}
@@ -267,7 +267,9 @@ const PreviewView = ({
267
267
  abortAndIgnore(abortOnSave);
268
268
  };
269
269
  });
270
- const shouldShowDocumentLockedModal = documentIsLocked && currentEditor && (typeof currentEditor === 'object' ? currentEditor.id !== user?.id : currentEditor !== user?.id) && !isReadOnlyForIncomingUser && !showTakeOverModal && !documentLockStateRef.current?.hasShownLockedModal && !isLockExpired;
270
+ const shouldShowDocumentLockedModal = documentIsLocked && currentEditor && (typeof currentEditor === 'object' ? currentEditor.id !== user?.id : currentEditor !== user?.id) && !isReadOnlyForIncomingUser && !showTakeOverModal &&
271
+ // eslint-disable-next-line react-compiler/react-compiler
272
+ !documentLockStateRef.current?.hasShownLockedModal && !isLockExpired;
271
273
  return /*#__PURE__*/_jsx(OperationProvider, {
272
274
  operation: operation,
273
275
  children: /*#__PURE__*/_jsxs(Form, {