@payloadcms/next 3.80.0-internal.c396c15 → 3.80.0-internal.cdd7ef7
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/HierarchyTypeField/index.d.ts +9 -0
- package/dist/elements/HierarchyTypeField/index.d.ts.map +1 -0
- package/dist/elements/HierarchyTypeField/index.js +114 -0
- package/dist/elements/HierarchyTypeField/index.js.map +1 -0
- package/dist/elements/HierarchyTypeField/index.server.d.ts +9 -0
- package/dist/elements/HierarchyTypeField/index.server.d.ts.map +1 -0
- package/dist/elements/HierarchyTypeField/index.server.js +32 -0
- package/dist/elements/HierarchyTypeField/index.server.js.map +1 -0
- package/dist/elements/Nav/SidebarTabs/TabError/index.d.ts +8 -0
- package/dist/elements/Nav/SidebarTabs/TabError/index.d.ts.map +1 -0
- package/dist/elements/Nav/SidebarTabs/TabError/index.js +42 -0
- package/dist/elements/Nav/SidebarTabs/TabError/index.js.map +1 -0
- package/dist/elements/Nav/SidebarTabs/constants.d.ts +2 -0
- package/dist/elements/Nav/SidebarTabs/constants.d.ts.map +1 -0
- package/dist/elements/Nav/SidebarTabs/constants.js +2 -0
- package/dist/elements/Nav/SidebarTabs/constants.js.map +1 -0
- package/dist/elements/Nav/SidebarTabs/index.client.d.ts +22 -0
- package/dist/elements/Nav/SidebarTabs/index.client.d.ts.map +1 -0
- package/dist/elements/Nav/SidebarTabs/index.client.js +194 -0
- package/dist/elements/Nav/SidebarTabs/index.client.js.map +1 -0
- package/dist/elements/Nav/SidebarTabs/index.d.ts +17 -0
- package/dist/elements/Nav/SidebarTabs/index.d.ts.map +1 -0
- package/dist/elements/Nav/SidebarTabs/index.js +85 -0
- package/dist/elements/Nav/SidebarTabs/index.js.map +1 -0
- package/dist/elements/Nav/SidebarTabs/renderTabServerFn.d.ts +10 -0
- package/dist/elements/Nav/SidebarTabs/renderTabServerFn.d.ts.map +1 -0
- package/dist/elements/Nav/SidebarTabs/renderTabServerFn.js +54 -0
- package/dist/elements/Nav/SidebarTabs/renderTabServerFn.js.map +1 -0
- package/dist/elements/Nav/getNavPrefs.d.ts.map +1 -1
- package/dist/elements/Nav/getNavPrefs.js +36 -2
- package/dist/elements/Nav/getNavPrefs.js.map +1 -1
- package/dist/elements/Nav/index.client.d.ts.map +1 -1
- package/dist/elements/Nav/index.client.js +27 -44
- package/dist/elements/Nav/index.client.js.map +1 -1
- package/dist/elements/Nav/index.d.ts.map +1 -1
- package/dist/elements/Nav/index.js +35 -7
- package/dist/elements/Nav/index.js.map +1 -1
- package/dist/exports/client.d.ts +2 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +2 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/rsc.d.ts +2 -1
- package/dist/exports/rsc.d.ts.map +1 -1
- package/dist/exports/rsc.js +2 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/exports/utilities.d.ts +2 -0
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +1 -0
- package/dist/exports/utilities.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/utilities/getHierarchyAncestry.d.ts +24 -0
- package/dist/utilities/getHierarchyAncestry.d.ts.map +1 -0
- package/dist/utilities/getHierarchyAncestry.js +103 -0
- package/dist/utilities/getHierarchyAncestry.js.map +1 -0
- package/dist/utilities/handleServerFunctions.js +2 -2
- package/dist/utilities/handleServerFunctions.js.map +1 -1
- package/dist/views/Account/ResetPreferences/index.d.ts.map +1 -1
- package/dist/views/Account/ResetPreferences/index.js +2 -4
- package/dist/views/Account/ResetPreferences/index.js.map +1 -1
- package/dist/views/Document/renderDocumentSlots.d.ts.map +1 -1
- package/dist/views/Document/renderDocumentSlots.js +8 -0
- package/dist/views/Document/renderDocumentSlots.js.map +1 -1
- package/dist/views/List/handleHierarchy.d.ts +18 -0
- package/dist/views/List/handleHierarchy.d.ts.map +1 -0
- package/dist/views/List/handleHierarchy.js +258 -0
- package/dist/views/List/handleHierarchy.js.map +1 -0
- package/dist/views/List/index.d.ts.map +1 -1
- package/dist/views/List/index.js +84 -28
- package/dist/views/List/index.js.map +1 -1
- package/dist/views/Root/getRouteData.d.ts +1 -4
- package/dist/views/Root/getRouteData.d.ts.map +1 -1
- package/dist/views/Root/getRouteData.js +27 -91
- package/dist/views/Root/getRouteData.js.map +1 -1
- package/dist/views/Root/index.d.ts.map +1 -1
- package/dist/views/Root/index.js +5 -11
- package/dist/views/Root/index.js.map +1 -1
- package/dist/views/Root/metadata.d.ts.map +1 -1
- package/dist/views/Root/metadata.js +1 -37
- package/dist/views/Root/metadata.js.map +1 -1
- package/package.json +7 -7
- package/dist/views/BrowseByFolder/buildView.d.ts +0 -13
- package/dist/views/BrowseByFolder/buildView.d.ts.map +0 -1
- package/dist/views/BrowseByFolder/buildView.js +0 -170
- package/dist/views/BrowseByFolder/buildView.js.map +0 -1
- package/dist/views/BrowseByFolder/index.d.ts +0 -4
- package/dist/views/BrowseByFolder/index.d.ts.map +0 -1
- package/dist/views/BrowseByFolder/index.js +0 -20
- package/dist/views/BrowseByFolder/index.js.map +0 -1
- package/dist/views/BrowseByFolder/metadata.d.ts +0 -4
- package/dist/views/BrowseByFolder/metadata.d.ts.map +0 -1
- package/dist/views/BrowseByFolder/metadata.js +0 -18
- package/dist/views/BrowseByFolder/metadata.js.map +0 -1
- package/dist/views/CollectionFolders/buildView.d.ts +0 -15
- package/dist/views/CollectionFolders/buildView.d.ts.map +0 -1
- package/dist/views/CollectionFolders/buildView.js +0 -156
- package/dist/views/CollectionFolders/buildView.js.map +0 -1
- package/dist/views/CollectionFolders/index.d.ts +0 -4
- package/dist/views/CollectionFolders/index.d.ts.map +0 -1
- package/dist/views/CollectionFolders/index.js +0 -20
- package/dist/views/CollectionFolders/index.js.map +0 -1
- package/dist/views/CollectionFolders/metadata.d.ts +0 -7
- package/dist/views/CollectionFolders/metadata.d.ts.map +0 -1
- package/dist/views/CollectionFolders/metadata.js +0 -25
- package/dist/views/CollectionFolders/metadata.js.map +0 -1
- package/dist/views/CollectionFolders/renderFolderViewSlots.d.ts +0 -11
- package/dist/views/CollectionFolders/renderFolderViewSlots.d.ts.map +0 -1
- package/dist/views/CollectionFolders/renderFolderViewSlots.js +0 -64
- package/dist/views/CollectionFolders/renderFolderViewSlots.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Payload, PayloadRequest } from 'payload';
|
|
2
|
+
export type HierarchyAncestryItem = {
|
|
3
|
+
id: number | string;
|
|
4
|
+
path: Array<{
|
|
5
|
+
id: number | string;
|
|
6
|
+
title: string;
|
|
7
|
+
}>;
|
|
8
|
+
title: string;
|
|
9
|
+
};
|
|
10
|
+
export type HierarchyAncestryResult = {
|
|
11
|
+
items: HierarchyAncestryItem[];
|
|
12
|
+
};
|
|
13
|
+
export type GetHierarchyAncestryArgs = {
|
|
14
|
+
hierarchySlug: string;
|
|
15
|
+
ids: (number | string)[];
|
|
16
|
+
payload: Payload;
|
|
17
|
+
user?: PayloadRequest['user'];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Returns full ancestry paths for hierarchy items.
|
|
21
|
+
* Each item includes its own title and the path from root to self.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getHierarchyAncestry({ hierarchySlug, ids, payload, user, }: GetHierarchyAncestryArgs): Promise<HierarchyAncestryResult>;
|
|
24
|
+
//# sourceMappingURL=getHierarchyAncestry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHierarchyAncestry.d.ts","sourceRoot":"","sources":["../../src/utilities/getHierarchyAncestry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEtD,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,IAAI,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACnD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,qBAAqB,EAAE,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,MAAM,CAAA;IACrB,GAAG,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;CAC9B,CAAA;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,aAAa,EACb,GAAG,EACH,OAAO,EACP,IAAI,GACL,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAyH7D"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns full ancestry paths for hierarchy items.
|
|
3
|
+
* Each item includes its own title and the path from root to self.
|
|
4
|
+
*/export async function getHierarchyAncestry({
|
|
5
|
+
hierarchySlug,
|
|
6
|
+
ids,
|
|
7
|
+
payload,
|
|
8
|
+
user
|
|
9
|
+
}) {
|
|
10
|
+
if (ids.length === 0) {
|
|
11
|
+
return {
|
|
12
|
+
items: []
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const collectionConfig = payload.collections[hierarchySlug]?.config;
|
|
16
|
+
const hierarchyConfig = collectionConfig?.hierarchy && typeof collectionConfig.hierarchy === 'object' ? collectionConfig.hierarchy : undefined;
|
|
17
|
+
if (!hierarchyConfig) {
|
|
18
|
+
throw new Error(`Collection "${hierarchySlug}" is not a hierarchy`);
|
|
19
|
+
}
|
|
20
|
+
const parentFieldName = hierarchyConfig.parentFieldName;
|
|
21
|
+
const useAsTitle = collectionConfig.admin?.useAsTitle || 'id';
|
|
22
|
+
// Cache for already-fetched items to avoid redundant queries
|
|
23
|
+
const itemCache = new Map();
|
|
24
|
+
const fetchItem = async id => {
|
|
25
|
+
const cached = itemCache.get(id);
|
|
26
|
+
if (cached) {
|
|
27
|
+
return cached;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const item = await payload.findByID({
|
|
31
|
+
id,
|
|
32
|
+
collection: hierarchySlug,
|
|
33
|
+
depth: 0,
|
|
34
|
+
overrideAccess: false,
|
|
35
|
+
user
|
|
36
|
+
});
|
|
37
|
+
if (item) {
|
|
38
|
+
itemCache.set(id, item);
|
|
39
|
+
}
|
|
40
|
+
return item;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const getTitle = (item, id) => {
|
|
46
|
+
const rawTitle = item[useAsTitle] || item.id || id;
|
|
47
|
+
if (rawTitle && typeof rawTitle === 'object') {
|
|
48
|
+
return JSON.stringify(rawTitle);
|
|
49
|
+
}
|
|
50
|
+
if (typeof rawTitle === 'string') {
|
|
51
|
+
return rawTitle;
|
|
52
|
+
}
|
|
53
|
+
if (typeof rawTitle === 'number') {
|
|
54
|
+
return String(rawTitle);
|
|
55
|
+
}
|
|
56
|
+
return String(id);
|
|
57
|
+
};
|
|
58
|
+
const getParentId = item => {
|
|
59
|
+
const parentValue = item[parentFieldName];
|
|
60
|
+
if (!parentValue) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (typeof parentValue === 'object' && parentValue !== null && 'id' in parentValue) {
|
|
64
|
+
return parentValue.id;
|
|
65
|
+
}
|
|
66
|
+
return parentValue;
|
|
67
|
+
};
|
|
68
|
+
const buildPath = async (startItem, startId) => {
|
|
69
|
+
const path = [];
|
|
70
|
+
let currentItem = startItem;
|
|
71
|
+
let currentId = startId;
|
|
72
|
+
while (currentItem && currentId !== null) {
|
|
73
|
+
path.unshift({
|
|
74
|
+
id: currentId,
|
|
75
|
+
title: getTitle(currentItem, currentId)
|
|
76
|
+
});
|
|
77
|
+
const nextParentId = getParentId(currentItem);
|
|
78
|
+
if (!nextParentId) {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
currentItem = await fetchItem(nextParentId);
|
|
82
|
+
currentId = nextParentId;
|
|
83
|
+
}
|
|
84
|
+
return path;
|
|
85
|
+
};
|
|
86
|
+
const items = [];
|
|
87
|
+
for (const id of ids) {
|
|
88
|
+
const item = await fetchItem(id);
|
|
89
|
+
if (!item) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const path = await buildPath(item, id);
|
|
93
|
+
items.push({
|
|
94
|
+
id,
|
|
95
|
+
path,
|
|
96
|
+
title: getTitle(item, id)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
items
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=getHierarchyAncestry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHierarchyAncestry.js","names":["getHierarchyAncestry","hierarchySlug","ids","payload","user","length","items","collectionConfig","collections","config","hierarchyConfig","hierarchy","undefined","Error","parentFieldName","useAsTitle","admin","itemCache","Map","fetchItem","id","cached","get","item","findByID","collection","depth","overrideAccess","set","getTitle","rawTitle","JSON","stringify","String","getParentId","parentValue","buildPath","startItem","startId","path","currentItem","currentId","unshift","title","nextParentId","push"],"sources":["../../src/utilities/getHierarchyAncestry.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\n\nexport type HierarchyAncestryItem = {\n id: number | string\n path: Array<{ id: number | string; title: string }>\n title: string\n}\n\nexport type HierarchyAncestryResult = {\n items: HierarchyAncestryItem[]\n}\n\nexport type GetHierarchyAncestryArgs = {\n hierarchySlug: string\n ids: (number | string)[]\n payload: Payload\n user?: PayloadRequest['user']\n}\n\n/**\n * Returns full ancestry paths for hierarchy items.\n * Each item includes its own title and the path from root to self.\n */\nexport async function getHierarchyAncestry({\n hierarchySlug,\n ids,\n payload,\n user,\n}: GetHierarchyAncestryArgs): Promise<HierarchyAncestryResult> {\n if (ids.length === 0) {\n return { items: [] }\n }\n\n const collectionConfig = payload.collections[hierarchySlug]?.config\n const hierarchyConfig =\n collectionConfig?.hierarchy && typeof collectionConfig.hierarchy === 'object'\n ? collectionConfig.hierarchy\n : undefined\n\n if (!hierarchyConfig) {\n throw new Error(`Collection \"${hierarchySlug}\" is not a hierarchy`)\n }\n\n const parentFieldName = hierarchyConfig.parentFieldName\n const useAsTitle = collectionConfig.admin?.useAsTitle || 'id'\n\n // Cache for already-fetched items to avoid redundant queries\n const itemCache = new Map<number | string, Record<string, unknown>>()\n\n const fetchItem = async (id: number | string): Promise<null | Record<string, unknown>> => {\n const cached = itemCache.get(id)\n if (cached) {\n return cached\n }\n\n try {\n const item = await payload.findByID({\n id,\n collection: hierarchySlug,\n depth: 0,\n overrideAccess: false,\n user,\n })\n\n if (item) {\n itemCache.set(id, item)\n }\n\n return item\n } catch {\n return null\n }\n }\n\n const getTitle = (item: Record<string, unknown>, id: number | string): string => {\n const rawTitle = item[useAsTitle] || item.id || id\n\n if (rawTitle && typeof rawTitle === 'object') {\n return JSON.stringify(rawTitle)\n }\n\n if (typeof rawTitle === 'string') {\n return rawTitle\n }\n\n if (typeof rawTitle === 'number') {\n return String(rawTitle)\n }\n\n return String(id)\n }\n\n const getParentId = (item: Record<string, unknown>): null | number | string => {\n const parentValue = item[parentFieldName]\n\n if (!parentValue) {\n return null\n }\n\n if (typeof parentValue === 'object' && parentValue !== null && 'id' in parentValue) {\n return (parentValue as { id: number | string }).id\n }\n\n return parentValue as number | string\n }\n\n const buildPath = async (\n startItem: Record<string, unknown>,\n startId: number | string,\n ): Promise<Array<{ id: number | string; title: string }>> => {\n const path: Array<{ id: number | string; title: string }> = []\n let currentItem: null | Record<string, unknown> = startItem\n let currentId: null | number | string = startId\n\n while (currentItem && currentId !== null) {\n path.unshift({\n id: currentId,\n title: getTitle(currentItem, currentId),\n })\n\n const nextParentId = getParentId(currentItem)\n if (!nextParentId) {\n break\n }\n\n currentItem = await fetchItem(nextParentId)\n currentId = nextParentId\n }\n\n return path\n }\n\n const items: HierarchyAncestryItem[] = []\n\n for (const id of ids) {\n const item = await fetchItem(id)\n if (!item) {\n continue\n }\n\n const path = await buildPath(item, id)\n items.push({\n id,\n path,\n title: getTitle(item, id),\n })\n }\n\n return { items }\n}\n"],"mappings":"AAmBA;;;GAIA,OAAO,eAAeA,qBAAqB;EACzCC,aAAa;EACbC,GAAG;EACHC,OAAO;EACPC;AAAI,CACqB;EACzB,IAAIF,GAAA,CAAIG,MAAM,KAAK,GAAG;IACpB,OAAO;MAAEC,KAAA,EAAO;IAAG;EACrB;EAEA,MAAMC,gBAAA,GAAmBJ,OAAA,CAAQK,WAAW,CAACP,aAAA,CAAc,EAAEQ,MAAA;EAC7D,MAAMC,eAAA,GACJH,gBAAA,EAAkBI,SAAA,IAAa,OAAOJ,gBAAA,CAAiBI,SAAS,KAAK,WACjEJ,gBAAA,CAAiBI,SAAS,GAC1BC,SAAA;EAEN,IAAI,CAACF,eAAA,EAAiB;IACpB,MAAM,IAAIG,KAAA,CAAM,eAAeZ,aAAA,sBAAmC;EACpE;EAEA,MAAMa,eAAA,GAAkBJ,eAAA,CAAgBI,eAAe;EACvD,MAAMC,UAAA,GAAaR,gBAAA,CAAiBS,KAAK,EAAED,UAAA,IAAc;EAEzD;EACA,MAAME,SAAA,GAAY,IAAIC,GAAA;EAEtB,MAAMC,SAAA,GAAY,MAAOC,EAAA;IACvB,MAAMC,MAAA,GAASJ,SAAA,CAAUK,GAAG,CAACF,EAAA;IAC7B,IAAIC,MAAA,EAAQ;MACV,OAAOA,MAAA;IACT;IAEA,IAAI;MACF,MAAME,IAAA,GAAO,MAAMpB,OAAA,CAAQqB,QAAQ,CAAC;QAClCJ,EAAA;QACAK,UAAA,EAAYxB,aAAA;QACZyB,KAAA,EAAO;QACPC,cAAA,EAAgB;QAChBvB;MACF;MAEA,IAAImB,IAAA,EAAM;QACRN,SAAA,CAAUW,GAAG,CAACR,EAAA,EAAIG,IAA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SAAA,GAAYG,YAAA;IACd;IAEA,OAAOL,IAAA;EACT;EAEA,MAAMjC,KAAA,GAAiC,EAAE;EAEzC,KAAK,MAAMc,EAAA,IAAMlB,GAAA,EAAK;IACpB,MAAMqB,IAAA,GAAO,MAAMJ,SAAA,CAAUC,EAAA;IAC7B,IAAI,CAACG,IAAA,EAAM;MACT;IACF;IAEA,MAAMgB,IAAA,GAAO,MAAMH,SAAA,CAAUb,IAAA,EAAMH,EAAA;IACnCd,KAAA,CAAMuC,IAAI,CAAC;MACTzB,EAAA;MACAmB,IAAA;MACAI,KAAA,EAAOd,QAAA,CAASN,IAAA,EAAMH,EAAA;IACxB;EACF;EAEA,OAAO;IAAEd;EAAM;AACjB","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { _internal_renderFieldHandler, 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';
|
|
5
4
|
import { schedulePublishHandler } from '@payloadcms/ui/utilities/schedulePublishHandler';
|
|
5
|
+
import { renderTabHandler } from '../elements/Nav/SidebarTabs/renderTabServerFn.js';
|
|
6
6
|
import { getDefaultLayoutHandler } from '../views/Dashboard/Default/ModularDashboard/renderWidget/getDefaultLayoutServerFn.js';
|
|
7
7
|
import { renderWidgetHandler } from '../views/Dashboard/Default/ModularDashboard/renderWidget/renderWidgetServerFn.js';
|
|
8
8
|
import { renderDocumentHandler } from '../views/Document/handleServerFunction.js';
|
|
@@ -14,11 +14,11 @@ const baseServerFunctions = {
|
|
|
14
14
|
'copy-data-from-locale': copyDataFromLocaleHandler,
|
|
15
15
|
'form-state': buildFormStateHandler,
|
|
16
16
|
'get-default-layout': getDefaultLayoutHandler,
|
|
17
|
-
'get-folder-results-component-and-data': getFolderResultsComponentAndDataHandler,
|
|
18
17
|
'render-document': renderDocumentHandler,
|
|
19
18
|
'render-document-slots': renderDocumentSlotsHandler,
|
|
20
19
|
'render-field': _internal_renderFieldHandler,
|
|
21
20
|
'render-list': renderListHandler,
|
|
21
|
+
'render-tab': renderTabHandler,
|
|
22
22
|
'render-widget': renderWidgetHandler,
|
|
23
23
|
'schedule-publish': schedulePublishHandler,
|
|
24
24
|
slugify: slugifyHandler,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleServerFunctions.js","names":["_internal_renderFieldHandler","copyDataFromLocaleHandler","buildFormStateHandler","buildTableStateHandler","
|
|
1
|
+
{"version":3,"file":"handleServerFunctions.js","names":["_internal_renderFieldHandler","copyDataFromLocaleHandler","buildFormStateHandler","buildTableStateHandler","schedulePublishHandler","renderTabHandler","getDefaultLayoutHandler","renderWidgetHandler","renderDocumentHandler","renderDocumentSlotsHandler","renderListHandler","initReq","slugifyHandler","baseServerFunctions","slugify","handleServerFunctions","args","name","fnKey","fnArgs","config","configPromise","importMap","serverFunctions","extraServerFunctions","cookies","locale","permissions","req","key","augmentedArgs","fn","Error"],"sources":["../../src/utilities/handleServerFunctions.ts"],"sourcesContent":["import type { DefaultServerFunctionArgs, ServerFunction, ServerFunctionHandler } from 'payload'\n\nimport { _internal_renderFieldHandler, 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 { renderTabHandler } from '../elements/Nav/SidebarTabs/renderTabServerFn.js'\nimport { getDefaultLayoutHandler } from '../views/Dashboard/Default/ModularDashboard/renderWidget/getDefaultLayoutServerFn.js'\nimport { renderWidgetHandler } from '../views/Dashboard/Default/ModularDashboard/renderWidget/renderWidgetServerFn.js'\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'\nimport { slugifyHandler } from './slugify.js'\n\nconst baseServerFunctions: Record<string, ServerFunction<any, any>> = {\n 'copy-data-from-locale': copyDataFromLocaleHandler,\n 'form-state': buildFormStateHandler,\n 'get-default-layout': getDefaultLayoutHandler,\n 'render-document': renderDocumentHandler,\n 'render-document-slots': renderDocumentSlotsHandler,\n 'render-field': _internal_renderFieldHandler,\n 'render-list': renderListHandler,\n 'render-tab': renderTabHandler,\n 'render-widget': renderWidgetHandler,\n 'schedule-publish': schedulePublishHandler,\n slugify: slugifyHandler,\n 'table-state': buildTableStateHandler,\n}\n\nexport const handleServerFunctions: ServerFunctionHandler = async (args) => {\n const {\n name: fnKey,\n args: fnArgs,\n config: configPromise,\n importMap,\n serverFunctions: extraServerFunctions,\n } = args\n\n const { cookies, locale, permissions, req } = await initReq({\n configPromise,\n importMap,\n key: 'RootLayout',\n })\n\n const augmentedArgs: DefaultServerFunctionArgs = {\n ...fnArgs,\n cookies,\n importMap,\n locale,\n permissions,\n req,\n }\n\n const fn = extraServerFunctions?.[fnKey] || baseServerFunctions[fnKey]\n\n if (!fn) {\n throw new Error(`Unknown Server Function: ${fnKey}`)\n }\n\n return fn(augmentedArgs)\n}\n"],"mappings":"AAEA,SAASA,4BAA4B,EAAEC,yBAAyB,QAAQ;AACxE,SAASC,qBAAqB,QAAQ;AACtC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,sBAAsB,QAAQ;AAEvC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,iBAAiB,QAAQ;AAClC,SAASC,OAAO,QAAQ;AACxB,SAASC,cAAc,QAAQ;AAE/B,MAAMC,mBAAA,GAAgE;EACpE,yBAAyBZ,yBAAA;EACzB,cAAcC,qBAAA;EACd,sBAAsBI,uBAAA;EACtB,mBAAmBE,qBAAA;EACnB,yBAAyBC,0BAAA;EACzB,gBAAgBT,4BAAA;EAChB,eAAeU,iBAAA;EACf,cAAcL,gBAAA;EACd,iBAAiBE,mBAAA;EACjB,oBAAoBH,sBAAA;EACpBU,OAAA,EAASF,cAAA;EACT,eAAeT;AACjB;AAEA,OAAO,MAAMY,qBAAA,GAA+C,MAAOC,IAAA;EACjE,MAAM;IACJC,IAAA,EAAMC,KAAK;IACXF,IAAA,EAAMG,MAAM;IACZC,MAAA,EAAQC,aAAa;IACrBC,SAAS;IACTC,eAAA,EAAiBC;EAAoB,CACtC,GAAGR,IAAA;EAEJ,MAAM;IAAES,OAAO;IAAEC,MAAM;IAAEC,WAAW;IAAEC;EAAG,CAAE,GAAG,MAAMjB,OAAA,CAAQ;IAC1DU,aAAA;IACAC,SAAA;IACAO,GAAA,EAAK;EACP;EAEA,MAAMC,aAAA,GAA2C;IAC/C,GAAGX,MAAM;IACTM,OAAA;IACAH,SAAA;IACAI,MAAA;IACAC,WAAA;IACAC;EACF;EAEA,MAAMG,EAAA,GAAKP,oBAAA,GAAuBN,KAAA,CAAM,IAAIL,mBAAmB,CAACK,KAAA,CAAM;EAEtE,IAAI,CAACa,EAAA,EAAI;IACP,MAAM,IAAIC,KAAA,CAAM,4BAA4Bd,KAAA,EAAO;EACrD;EAEA,OAAOa,EAAA,CAAGD,aAAA;AACZ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Account/ResetPreferences/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAgBxC,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC;IACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAC1B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Account/ResetPreferences/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAgBxC,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC;IACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAC1B,CAsEA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","Button","ConfirmationModal","toast","useConfig","useModal","useTranslation","formatAdminURL","qs","Fragment","useCallback","confirmResetModalSlug","ResetPreferences","t0","$","user","openModal","t","config","t1","routes","t2","api","apiRoute","t3","stringifiedQuery","stringify","depth","where","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","Button","ConfirmationModal","toast","useConfig","useModal","useTranslation","formatAdminURL","qs","Fragment","useCallback","confirmResetModalSlug","ResetPreferences","t0","$","user","openModal","t","config","t1","routes","t2","api","apiRoute","t3","stringifiedQuery","stringify","depth","where","equals","id","addQueryPrefix","res","fetch","path","credentials","headers","method","json","message","ok","success","error","t4","_err","handleResetPreferences","t5","_jsxs","children","_jsx","buttonStyle","onClick","body","confirmingLabel","heading","modalSlug","onConfirm"],"sources":["../../../../src/views/Account/ResetPreferences/index.tsx"],"sourcesContent":["'use client'\nimport type { TypedUser } from 'payload'\n\nimport {\n Button,\n ConfirmationModal,\n toast,\n useConfig,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport * as qs from 'qs-esm'\nimport { Fragment, useCallback } from 'react'\n\nconst confirmResetModalSlug = 'confirm-reset-modal'\n\nexport const ResetPreferences: React.FC<{\n readonly user?: TypedUser\n}> = ({ user }) => {\n const { openModal } = useModal()\n const { t } = useTranslation()\n const {\n config: {\n routes: { api: apiRoute },\n },\n } = useConfig()\n\n const handleResetPreferences = useCallback(async () => {\n if (!user) {\n return\n }\n\n const stringifiedQuery = qs.stringify(\n {\n depth: 0,\n where: {\n 'user.value': {\n equals: user.id,\n },\n },\n },\n { addQueryPrefix: true },\n )\n\n try {\n const res = await fetch(\n formatAdminURL({\n apiRoute,\n path: `/payload-preferences${stringifiedQuery}`,\n }),\n {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'DELETE',\n },\n )\n\n const json = await res.json()\n const message = json.message\n\n if (res.ok) {\n toast.success(message)\n } else {\n toast.error(message)\n }\n } catch (_err) {\n // swallow error\n }\n }, [apiRoute, user])\n\n return (\n <Fragment>\n <div>\n <Button buttonStyle=\"secondary\" onClick={() => openModal(confirmResetModalSlug)}>\n {t('general:resetPreferences')}\n </Button>\n </div>\n <ConfirmationModal\n body={t('general:resetPreferencesDescription')}\n confirmingLabel={t('general:resettingPreferences')}\n heading={t('general:resetPreferences')}\n modalSlug={confirmResetModalSlug}\n onConfirm={handleResetPreferences}\n />\n </Fragment>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SACEC,MAAM,EACNC,iBAAiB,EACjBC,KAAK,EACLC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT;AACP,SAASC,cAAc,QAAQ;AAC/B,YAAYC,EAAA,MAAQ;AACpB,SAASC,QAAQ,EAAEC,WAAW,QAAQ;AAEtC,MAAMC,qBAAA,GAAwB;AAE9B,OAAO,MAAMC,gBAAA,GAERC,EAAA;EAAA,MAAAC,CAAA,GAAAd,EAAA;EAAC;IAAAe;EAAA,IAAAF,EAAQ;EACZ;IAAAG;EAAA,IAAsBX,QAAA;EACtB;IAAAY;EAAA,IAAcX,cAAA;EACd;IAAAY,MAAA,EAAAC;EAAA,IAIIf,SAAA;EAHM;IAAAgB,MAAA,EAAAC;EAAA,IAAAF,EAEP;EADS;IAAAG,GAAA,EAAAC;EAAA,IAAAF,EAAiB;EAAA,IAAAG,EAAA;EAAA,IAAAV,CAAA,QAAAS,QAAA,IAAA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B,EAAA;IAF7DG,EAAA,GAAAC,KAAA,CAAAtC,QAAA;MAAAuC,QAAA,GACEC,IAAA,CAAC;QAAAD,QAAA,EACCC,IAAA,CAAAhD,MAAA;UAAAiD,WAAA,EAAoB;UAAAC,OAAA,EAAqBR,EAAgB;UAAAK,QAAA,EACtD/B,CAAA,CAAE;QAAA,C;UAGPgC,IAAA,CAAA/C,iBAAA;QAAAkD,IAAA,EACQnC,CAAA,CAAE;QAAAoC,eAAA,EACSpC,CAAA,CAAE;QAAAqC,OAAA,EACVrC,CAAA,CAAE;QAAAsC,SAAA,EAAA5C,qBAAA;QAAA6C,SAAA,EAEAX;MAAA,C;;;;;;;;;SAXfC,E;CAeJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderDocumentSlots.d.ts","sourceRoot":"","sources":["../../../src/views/Document/renderDocumentSlots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EAEb,MAAM,EACN,cAAc,EAGd,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EAGpB,cAAc,EAMf,MAAM,SAAS,CAAA;AAQhB,eAAO,MAAM,mBAAmB,EAAE,CAAC,IAAI,EAAE;IACvC,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,oBAAoB,CAAA;IACjC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAK,
|
|
1
|
+
{"version":3,"file":"renderDocumentSlots.d.ts","sourceRoot":"","sources":["../../../src/views/Document/renderDocumentSlots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EAEb,MAAM,EACN,cAAc,EAGd,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EAGpB,cAAc,EAMf,MAAM,SAAS,CAAA;AAQhB,eAAO,MAAM,mBAAmB,EAAE,CAAC,IAAI,EAAE;IACvC,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,oBAAoB,CAAA;IACjC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAK,aA6LL,CAAA;AAED,eAAO,MAAM,0BAA0B,EAAE,cAAc,CAAC;IACtD,cAAc,EAAE,MAAM,CAAA;IACtB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACrB,CAwBA,CAAA"}
|
|
@@ -31,6 +31,14 @@ export const renderDocumentSlots = args => {
|
|
|
31
31
|
serverProps: serverProps
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
+
const BeforeDocumentMeta = collectionConfig?.admin?.components?.edit?.BeforeDocumentMeta || globalConfig?.admin?.components?.elements?.BeforeDocumentMeta;
|
|
35
|
+
if (BeforeDocumentMeta) {
|
|
36
|
+
components.BeforeDocumentMeta = RenderServerComponent({
|
|
37
|
+
Component: BeforeDocumentMeta,
|
|
38
|
+
importMap: req.payload.importMap,
|
|
39
|
+
serverProps
|
|
40
|
+
});
|
|
41
|
+
}
|
|
34
42
|
const EditMenuItems = collectionConfig?.admin?.components?.edit?.editMenuItems;
|
|
35
43
|
if (EditMenuItems) {
|
|
36
44
|
components.EditMenuItems = RenderServerComponent({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderDocumentSlots.js","names":["ViewDescription","RenderServerComponent","hasDraftsEnabled","getDocumentPermissions","renderDocumentSlots","args","id","collectionConfig","globalConfig","hasSavePermission","locale","permissions","req","components","unsavedDraftWithValidations","undefined","isPreviewEnabled","admin","preview","serverProps","i18n","payload","user","BeforeDocumentControls","edit","beforeDocumentControls","elements","Component","importMap","EditMenuItems","editMenuItems","CustomPreviewButton","PreviewButton","LivePreview","views","livePreview","descriptionFromConfig","description","staticDescription","t","CustomDescription","Description","hasDescription","clientProps","collectionSlug","slug","Fallback","versions","drafts","CustomStatus","Status","CustomPublishButton","PublishButton","CustomUnpublishButton","UnpublishButton","CustomSaveDraftButton","SaveDraftButton","draftsEnabled","CustomSaveButton","SaveButton","upload","Upload","controls","UploadControls","renderDocumentSlotsHandler","collections","config","Error","data"],"sources":["../../../src/views/Document/renderDocumentSlots.tsx"],"sourcesContent":["import type {\n BeforeDocumentControlsServerPropsOnly,\n DocumentSlots,\n EditMenuItemsServerPropsOnly,\n Locale,\n PayloadRequest,\n PreviewButtonServerPropsOnly,\n PublishButtonServerPropsOnly,\n SanitizedCollectionConfig,\n SanitizedGlobalConfig,\n SanitizedPermissions,\n SaveButtonServerPropsOnly,\n SaveDraftButtonServerPropsOnly,\n ServerFunction,\n ServerProps,\n StaticDescription,\n UnpublishButtonServerPropsOnly,\n ViewDescriptionClientProps,\n ViewDescriptionServerPropsOnly,\n} from 'payload'\n\nimport { ViewDescription } from '@payloadcms/ui'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { hasDraftsEnabled } from 'payload/shared'\n\nimport { getDocumentPermissions } from './getDocumentPermissions.js'\n\nexport const renderDocumentSlots: (args: {\n collectionConfig?: SanitizedCollectionConfig\n globalConfig?: SanitizedGlobalConfig\n hasSavePermission: boolean\n id?: number | string\n locale: Locale\n permissions: SanitizedPermissions\n req: PayloadRequest\n}) => DocumentSlots = (args) => {\n const { id, collectionConfig, globalConfig, hasSavePermission, locale, permissions, req } = args\n\n const components: DocumentSlots = {} as DocumentSlots\n\n const unsavedDraftWithValidations = undefined\n\n const isPreviewEnabled = collectionConfig?.admin?.preview || globalConfig?.admin?.preview\n\n const serverProps: ServerProps = {\n id,\n i18n: req.i18n,\n locale,\n payload: req.payload,\n permissions,\n user: req.user,\n // TODO: Add remaining serverProps\n }\n\n const BeforeDocumentControls =\n collectionConfig?.admin?.components?.edit?.beforeDocumentControls ||\n globalConfig?.admin?.components?.elements?.beforeDocumentControls\n\n if (BeforeDocumentControls) {\n components.BeforeDocumentControls = RenderServerComponent({\n Component: BeforeDocumentControls,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies BeforeDocumentControlsServerPropsOnly,\n })\n }\n\n const EditMenuItems = collectionConfig?.admin?.components?.edit?.editMenuItems\n\n if (EditMenuItems) {\n components.EditMenuItems = RenderServerComponent({\n Component: EditMenuItems,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies EditMenuItemsServerPropsOnly,\n })\n }\n\n const CustomPreviewButton =\n collectionConfig?.admin?.components?.edit?.PreviewButton ||\n globalConfig?.admin?.components?.elements?.PreviewButton\n\n if (isPreviewEnabled && CustomPreviewButton) {\n components.PreviewButton = RenderServerComponent({\n Component: CustomPreviewButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies PreviewButtonServerPropsOnly,\n })\n }\n\n const LivePreview =\n collectionConfig?.admin?.components?.views?.edit?.livePreview ||\n globalConfig?.admin?.components?.views?.edit?.livePreview\n\n if (LivePreview?.Component) {\n components.LivePreview = RenderServerComponent({\n Component: LivePreview.Component,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n\n const descriptionFromConfig =\n collectionConfig?.admin?.description || globalConfig?.admin?.description\n\n const staticDescription: StaticDescription =\n typeof descriptionFromConfig === 'function'\n ? descriptionFromConfig({ t: req.i18n.t })\n : descriptionFromConfig\n\n const CustomDescription =\n collectionConfig?.admin?.components?.Description ||\n globalConfig?.admin?.components?.elements?.Description\n\n const hasDescription = CustomDescription || staticDescription\n\n if (hasDescription) {\n components.Description = RenderServerComponent({\n clientProps: {\n collectionSlug: collectionConfig?.slug,\n description: staticDescription,\n } satisfies ViewDescriptionClientProps,\n Component: CustomDescription,\n Fallback: ViewDescription,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies ViewDescriptionServerPropsOnly,\n })\n }\n\n if (collectionConfig?.versions?.drafts || globalConfig?.versions?.drafts) {\n const CustomStatus =\n collectionConfig?.admin?.components?.edit?.Status ||\n globalConfig?.admin?.components?.elements?.Status\n\n if (CustomStatus) {\n components.Status = RenderServerComponent({\n Component: CustomStatus,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n }\n\n if (hasSavePermission) {\n if (hasDraftsEnabled(collectionConfig || globalConfig)) {\n const CustomPublishButton =\n collectionConfig?.admin?.components?.edit?.PublishButton ||\n globalConfig?.admin?.components?.elements?.PublishButton\n\n if (CustomPublishButton) {\n components.PublishButton = RenderServerComponent({\n Component: CustomPublishButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies PublishButtonServerPropsOnly,\n })\n }\n\n const CustomUnpublishButton =\n collectionConfig?.admin?.components?.edit?.UnpublishButton ||\n globalConfig?.admin?.components?.elements?.UnpublishButton\n\n if (CustomUnpublishButton) {\n components.UnpublishButton = RenderServerComponent({\n Component: CustomUnpublishButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies UnpublishButtonServerPropsOnly,\n })\n }\n\n const CustomSaveDraftButton =\n collectionConfig?.admin?.components?.edit?.SaveDraftButton ||\n globalConfig?.admin?.components?.elements?.SaveDraftButton\n\n const draftsEnabled = hasDraftsEnabled(collectionConfig || globalConfig)\n\n if ((draftsEnabled || unsavedDraftWithValidations) && CustomSaveDraftButton) {\n components.SaveDraftButton = RenderServerComponent({\n Component: CustomSaveDraftButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies SaveDraftButtonServerPropsOnly,\n })\n }\n } else {\n const CustomSaveButton =\n collectionConfig?.admin?.components?.edit?.SaveButton ||\n globalConfig?.admin?.components?.elements?.SaveButton\n\n if (CustomSaveButton) {\n components.SaveButton = RenderServerComponent({\n Component: CustomSaveButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies SaveButtonServerPropsOnly,\n })\n }\n }\n }\n\n if (collectionConfig?.upload && collectionConfig?.admin?.components?.edit?.Upload) {\n components.Upload = RenderServerComponent({\n Component: collectionConfig.admin.components.edit.Upload,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n\n if (collectionConfig?.upload && collectionConfig.upload.admin?.components?.controls) {\n components.UploadControls = RenderServerComponent({\n Component: collectionConfig.upload.admin.components.controls,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n\n return components\n}\n\nexport const renderDocumentSlotsHandler: ServerFunction<{\n collectionSlug: string\n id?: number | string\n}> = async (args) => {\n const { id, collectionSlug, locale, permissions, req } = args\n\n const collectionConfig = req.payload.collections[collectionSlug]?.config\n\n if (!collectionConfig) {\n throw new Error(req.t('error:incorrectCollection'))\n }\n\n const { hasSavePermission } = await getDocumentPermissions({\n id,\n collectionConfig,\n data: {},\n req,\n })\n\n return renderDocumentSlots({\n id,\n collectionConfig,\n hasSavePermission,\n locale,\n permissions,\n req,\n })\n}\n"],"mappings":"AAqBA,SAASA,eAAe,QAAQ;AAChC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AAEjC,SAASC,sBAAsB,QAAQ;AAEvC,OAAO,MAAMC,mBAAA,GAQUC,IAAA;EACrB,MAAM;IAAEC,EAAE;IAAEC,gBAAgB;IAAEC,YAAY;IAAEC,iBAAiB;IAAEC,MAAM;IAAEC,WAAW;IAAEC;EAAG,CAAE,GAAGP,IAAA;EAE5F,MAAMQ,UAAA,GAA4B,CAAC;EAEnC,MAAMC,2BAAA,GAA8BC,SAAA;EAEpC,MAAMC,gBAAA,GAAmBT,gBAAA,EAAkBU,KAAA,EAAOC,OAAA,IAAWV,YAAA,EAAcS,KAAA,EAAOC,OAAA;EAElF,MAAMC,WAAA,GAA2B;IAC/Bb,EAAA;IACAc,IAAA,EAAMR,GAAA,CAAIQ,IAAI;IACdV,MAAA;IACAW,OAAA,EAAST,GAAA,CAAIS,OAAO;IACpBV,WAAA;IACAW,IAAA,EAAMV,GAAA,CAAIU;EAEZ;EAEA,MAAMC,sBAAA,GACJhB,gB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A;EACV,MAAM;IAAEC,EAAE;IAAEsC,cAAc;IAAElC,MAAM;IAAEC,WAAW;IAAEC;EAAG,CAAE,GAAGP,IAAA;EAEzD,MAAME,gBAAA,GAAmBK,GAAA,CAAIS,OAAO,CAAC4C,WAAW,CAACrB,cAAA,CAAe,EAAEsB,MAAA;EAElE,IAAI,CAAC3D,gBAAA,EAAkB;IACrB,MAAM,IAAI4D,KAAA,CAAMvD,GAAA,CAAI2B,CAAC,CAAC;EACxB;EAEA,MAAM;IAAE9B;EAAiB,CAAE,GAAG,MAAMN,sBAAA,CAAuB;IACzDG,EAAA;IACAC,gBAAA;IACA6D,IAAA,EAAM,CAAC;IACPxD;EACF;EAEA,OAAOR,mBAAA,CAAoB;IACzBE,EAAA;IACAC,gBAAA;IACAE,iBAAA;IACAC,MAAA;IACAC,WAAA;IACAC;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"renderDocumentSlots.js","names":["ViewDescription","RenderServerComponent","hasDraftsEnabled","getDocumentPermissions","renderDocumentSlots","args","id","collectionConfig","globalConfig","hasSavePermission","locale","permissions","req","components","unsavedDraftWithValidations","undefined","isPreviewEnabled","admin","preview","serverProps","i18n","payload","user","BeforeDocumentControls","edit","beforeDocumentControls","elements","Component","importMap","BeforeDocumentMeta","EditMenuItems","editMenuItems","CustomPreviewButton","PreviewButton","LivePreview","views","livePreview","descriptionFromConfig","description","staticDescription","t","CustomDescription","Description","hasDescription","clientProps","collectionSlug","slug","Fallback","versions","drafts","CustomStatus","Status","CustomPublishButton","PublishButton","CustomUnpublishButton","UnpublishButton","CustomSaveDraftButton","SaveDraftButton","draftsEnabled","CustomSaveButton","SaveButton","upload","Upload","controls","UploadControls","renderDocumentSlotsHandler","collections","config","Error","data"],"sources":["../../../src/views/Document/renderDocumentSlots.tsx"],"sourcesContent":["import type {\n BeforeDocumentControlsServerPropsOnly,\n DocumentSlots,\n EditMenuItemsServerPropsOnly,\n Locale,\n PayloadRequest,\n PreviewButtonServerPropsOnly,\n PublishButtonServerPropsOnly,\n SanitizedCollectionConfig,\n SanitizedGlobalConfig,\n SanitizedPermissions,\n SaveButtonServerPropsOnly,\n SaveDraftButtonServerPropsOnly,\n ServerFunction,\n ServerProps,\n StaticDescription,\n UnpublishButtonServerPropsOnly,\n ViewDescriptionClientProps,\n ViewDescriptionServerPropsOnly,\n} from 'payload'\n\nimport { ViewDescription } from '@payloadcms/ui'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { hasDraftsEnabled } from 'payload/shared'\n\nimport { getDocumentPermissions } from './getDocumentPermissions.js'\n\nexport const renderDocumentSlots: (args: {\n collectionConfig?: SanitizedCollectionConfig\n globalConfig?: SanitizedGlobalConfig\n hasSavePermission: boolean\n id?: number | string\n locale: Locale\n permissions: SanitizedPermissions\n req: PayloadRequest\n}) => DocumentSlots = (args) => {\n const { id, collectionConfig, globalConfig, hasSavePermission, locale, permissions, req } = args\n\n const components: DocumentSlots = {} as DocumentSlots\n\n const unsavedDraftWithValidations = undefined\n\n const isPreviewEnabled = collectionConfig?.admin?.preview || globalConfig?.admin?.preview\n\n const serverProps: ServerProps = {\n id,\n i18n: req.i18n,\n locale,\n payload: req.payload,\n permissions,\n user: req.user,\n // TODO: Add remaining serverProps\n }\n\n const BeforeDocumentControls =\n collectionConfig?.admin?.components?.edit?.beforeDocumentControls ||\n globalConfig?.admin?.components?.elements?.beforeDocumentControls\n\n if (BeforeDocumentControls) {\n components.BeforeDocumentControls = RenderServerComponent({\n Component: BeforeDocumentControls,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies BeforeDocumentControlsServerPropsOnly,\n })\n }\n\n const BeforeDocumentMeta =\n collectionConfig?.admin?.components?.edit?.BeforeDocumentMeta ||\n globalConfig?.admin?.components?.elements?.BeforeDocumentMeta\n\n if (BeforeDocumentMeta) {\n components.BeforeDocumentMeta = RenderServerComponent({\n Component: BeforeDocumentMeta,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n\n const EditMenuItems = collectionConfig?.admin?.components?.edit?.editMenuItems\n\n if (EditMenuItems) {\n components.EditMenuItems = RenderServerComponent({\n Component: EditMenuItems,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies EditMenuItemsServerPropsOnly,\n })\n }\n\n const CustomPreviewButton =\n collectionConfig?.admin?.components?.edit?.PreviewButton ||\n globalConfig?.admin?.components?.elements?.PreviewButton\n\n if (isPreviewEnabled && CustomPreviewButton) {\n components.PreviewButton = RenderServerComponent({\n Component: CustomPreviewButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies PreviewButtonServerPropsOnly,\n })\n }\n\n const LivePreview =\n collectionConfig?.admin?.components?.views?.edit?.livePreview ||\n globalConfig?.admin?.components?.views?.edit?.livePreview\n\n if (LivePreview?.Component) {\n components.LivePreview = RenderServerComponent({\n Component: LivePreview.Component,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n\n const descriptionFromConfig =\n collectionConfig?.admin?.description || globalConfig?.admin?.description\n\n const staticDescription: StaticDescription =\n typeof descriptionFromConfig === 'function'\n ? descriptionFromConfig({ t: req.i18n.t })\n : descriptionFromConfig\n\n const CustomDescription =\n collectionConfig?.admin?.components?.Description ||\n globalConfig?.admin?.components?.elements?.Description\n\n const hasDescription = CustomDescription || staticDescription\n\n if (hasDescription) {\n components.Description = RenderServerComponent({\n clientProps: {\n collectionSlug: collectionConfig?.slug,\n description: staticDescription,\n } satisfies ViewDescriptionClientProps,\n Component: CustomDescription,\n Fallback: ViewDescription,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies ViewDescriptionServerPropsOnly,\n })\n }\n\n if (collectionConfig?.versions?.drafts || globalConfig?.versions?.drafts) {\n const CustomStatus =\n collectionConfig?.admin?.components?.edit?.Status ||\n globalConfig?.admin?.components?.elements?.Status\n\n if (CustomStatus) {\n components.Status = RenderServerComponent({\n Component: CustomStatus,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n }\n\n if (hasSavePermission) {\n if (hasDraftsEnabled(collectionConfig || globalConfig)) {\n const CustomPublishButton =\n collectionConfig?.admin?.components?.edit?.PublishButton ||\n globalConfig?.admin?.components?.elements?.PublishButton\n\n if (CustomPublishButton) {\n components.PublishButton = RenderServerComponent({\n Component: CustomPublishButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies PublishButtonServerPropsOnly,\n })\n }\n\n const CustomUnpublishButton =\n collectionConfig?.admin?.components?.edit?.UnpublishButton ||\n globalConfig?.admin?.components?.elements?.UnpublishButton\n\n if (CustomUnpublishButton) {\n components.UnpublishButton = RenderServerComponent({\n Component: CustomUnpublishButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies UnpublishButtonServerPropsOnly,\n })\n }\n\n const CustomSaveDraftButton =\n collectionConfig?.admin?.components?.edit?.SaveDraftButton ||\n globalConfig?.admin?.components?.elements?.SaveDraftButton\n\n const draftsEnabled = hasDraftsEnabled(collectionConfig || globalConfig)\n\n if ((draftsEnabled || unsavedDraftWithValidations) && CustomSaveDraftButton) {\n components.SaveDraftButton = RenderServerComponent({\n Component: CustomSaveDraftButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies SaveDraftButtonServerPropsOnly,\n })\n }\n } else {\n const CustomSaveButton =\n collectionConfig?.admin?.components?.edit?.SaveButton ||\n globalConfig?.admin?.components?.elements?.SaveButton\n\n if (CustomSaveButton) {\n components.SaveButton = RenderServerComponent({\n Component: CustomSaveButton,\n importMap: req.payload.importMap,\n serverProps: serverProps satisfies SaveButtonServerPropsOnly,\n })\n }\n }\n }\n\n if (collectionConfig?.upload && collectionConfig?.admin?.components?.edit?.Upload) {\n components.Upload = RenderServerComponent({\n Component: collectionConfig.admin.components.edit.Upload,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n\n if (collectionConfig?.upload && collectionConfig.upload.admin?.components?.controls) {\n components.UploadControls = RenderServerComponent({\n Component: collectionConfig.upload.admin.components.controls,\n importMap: req.payload.importMap,\n serverProps,\n })\n }\n\n return components\n}\n\nexport const renderDocumentSlotsHandler: ServerFunction<{\n collectionSlug: string\n id?: number | string\n}> = async (args) => {\n const { id, collectionSlug, locale, permissions, req } = args\n\n const collectionConfig = req.payload.collections[collectionSlug]?.config\n\n if (!collectionConfig) {\n throw new Error(req.t('error:incorrectCollection'))\n }\n\n const { hasSavePermission } = await getDocumentPermissions({\n id,\n collectionConfig,\n data: {},\n req,\n })\n\n return renderDocumentSlots({\n id,\n collectionConfig,\n hasSavePermission,\n locale,\n permissions,\n req,\n })\n}\n"],"mappings":"AAqBA,SAASA,eAAe,QAAQ;AAChC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AAEjC,SAASC,sBAAsB,QAAQ;AAEvC,OAAO,MAAMC,mBAAA,GAQUC,IAAA;EACrB,MAAM;IAAEC,EAAE;IAAEC,gBAAgB;IAAEC,YAAY;IAAEC,iBAAiB;IAAEC,MAAM;IAAEC,WAAW;IAAEC;EAAG,CAAE,GAAGP,IAAA;EAE5F,MAAMQ,UAAA,GAA4B,CAAC;EAEnC,MAAMC,2BAAA,GAA8BC,SAAA;EAEpC,MAAMC,gBAAA,GAAmBT,gBAAA,EAAkBU,KAAA,EAAOC,OAAA,IAAWV,YAAA,EAAcS,KAAA,EAAOC,OAAA;EAElF,MAAMC,WAAA,GAA2B;IAC/Bb,EAAA;IACAc,IAAA,EAAMR,GAAA,CAAIQ,IAAI;IACdV,MAAA;IACAW,OAAA,EAAST,GAAA,CAAIS,OAAO;IACpBV,WAAA;IACAW,IAAA,EAAMV,GAAA,CAAIU;EAEZ;EAEA,MAAMC,sBAAA,GACJhB,gBAAA,EAAkBU,KAAA,EAAOJ,UAAA,EAAYW,IAAA,EAAMC,sBAAA,IAC3CjB,YAAA,EAAcS,KAAA,EAAOJ,UAAA,EAAYa,QAAA,EAAUD,sBAAA;EAE7C,IAAIF,sBAAA,EAAwB;IAC1BV,UAAA,CAAWU,sBAAsB,GAAGtB,qBAAA,CAAsB;MACxD0B,SAAA,EAAWJ,sBAAA;MACXK,SAA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AAS;MAChCT;IACF;EACF;EAEA,OAAON,UAAA;AACT;AAEA,OAAO,MAAMoD,0BAAA,GAGR,MAAO5D,IAAA;EACV,MAAM;IAAEC,EAAE;IAAEuC,cAAc;IAAEnC,MAAM;IAAEC,WAAW;IAAEC;EAAG,CAAE,GAAGP,IAAA;EAEzD,MAAME,gBAAA,GAAmBK,GAAA,CAAIS,OAAO,CAAC6C,WAAW,CAACrB,cAAA,CAAe,EAAEsB,MAAA;EAElE,IAAI,CAAC5D,gBAAA,EAAkB;IACrB,MAAM,IAAI6D,KAAA,CAAMxD,GAAA,CAAI4B,CAAC,CAAC;EACxB;EAEA,MAAM;IAAE/B;EAAiB,CAAE,GAAG,MAAMN,sBAAA,CAAuB;IACzDG,EAAA;IACAC,gBAAA;IACA8D,IAAA,EAAM,CAAC;IACPzD;EACF;EAEA,OAAOR,mBAAA,CAAoB;IACzBE,EAAA;IACAC,gBAAA;IACAE,iBAAA;IACAC,MAAA;IACAC,WAAA;IACAC;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HierarchyViewData, PayloadRequest, SanitizedCollectionConfig, SanitizedPermissions, Where } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches hierarchy data for a collection with a selected parent.
|
|
4
|
+
* Returns data that can be rendered client-side by HierarchyTable.
|
|
5
|
+
*/
|
|
6
|
+
export declare const handleHierarchy: ({ baseFilter, collectionConfig, collectionSlug, parentId, permissions, req, search, typeFilter, user, }: {
|
|
7
|
+
baseFilter?: null | Where;
|
|
8
|
+
collectionConfig: SanitizedCollectionConfig;
|
|
9
|
+
collectionSlug: string;
|
|
10
|
+
parentId: null | number | string;
|
|
11
|
+
permissions?: SanitizedPermissions;
|
|
12
|
+
req: PayloadRequest;
|
|
13
|
+
search?: string;
|
|
14
|
+
/** Filter hierarchy items by their collectionSpecific type field */
|
|
15
|
+
typeFilter?: string[];
|
|
16
|
+
user: PayloadRequest["user"];
|
|
17
|
+
}) => Promise<HierarchyViewData>;
|
|
18
|
+
//# sourceMappingURL=handleHierarchy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleHierarchy.d.ts","sourceRoot":"","sources":["../../../src/views/List/handleHierarchy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EAEd,yBAAyB,EACzB,oBAAoB,EAEpB,KAAK,EACN,MAAM,SAAS,CAAA;AAMhB;;;GAGG;AACH,eAAO,MAAM,eAAe,4GAUzB;IACD,UAAU,CAAC,EAAE,IAAI,GAAG,KAAK,CAAA;IACzB,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;IAChC,WAAW,CAAC,EAAE,oBAAoB,CAAA;IAClC,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;CAC7B,KAAG,OAAO,CAAC,iBAAiB,CAkP5B,CAAA"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { getTranslation } from '@payloadcms/translations';
|
|
2
|
+
import { getAncestors } from 'payload';
|
|
3
|
+
import { combineWhereConstraints, DEFAULT_HIERARCHY_LIST_LIMIT } from 'payload/shared';
|
|
4
|
+
/**
|
|
5
|
+
* Fetches hierarchy data for a collection with a selected parent.
|
|
6
|
+
* Returns data that can be rendered client-side by HierarchyTable.
|
|
7
|
+
*/
|
|
8
|
+
export const handleHierarchy = async ({
|
|
9
|
+
baseFilter,
|
|
10
|
+
collectionConfig,
|
|
11
|
+
collectionSlug,
|
|
12
|
+
parentId,
|
|
13
|
+
permissions,
|
|
14
|
+
req,
|
|
15
|
+
search,
|
|
16
|
+
typeFilter,
|
|
17
|
+
user
|
|
18
|
+
}) => {
|
|
19
|
+
const hierarchyConfig = collectionConfig.hierarchy && typeof collectionConfig.hierarchy === 'object' ? collectionConfig.hierarchy : undefined;
|
|
20
|
+
if (!hierarchyConfig) {
|
|
21
|
+
throw new Error('Collection is not a hierarchy');
|
|
22
|
+
}
|
|
23
|
+
const parentFieldName = hierarchyConfig.parentFieldName;
|
|
24
|
+
const useAsTitle = collectionConfig.admin?.useAsTitle || 'id';
|
|
25
|
+
// Fetch the parent item and breadcrumbs (skip for root level)
|
|
26
|
+
let parent = null;
|
|
27
|
+
let breadcrumbs = [];
|
|
28
|
+
if (parentId !== null) {
|
|
29
|
+
try {
|
|
30
|
+
const [item, ancestors] = await Promise.all([req.payload.findByID({
|
|
31
|
+
id: parentId,
|
|
32
|
+
collection: collectionSlug,
|
|
33
|
+
depth: 0,
|
|
34
|
+
overrideAccess: false,
|
|
35
|
+
req,
|
|
36
|
+
user
|
|
37
|
+
}), getAncestors({
|
|
38
|
+
id: parentId,
|
|
39
|
+
collectionSlug,
|
|
40
|
+
req
|
|
41
|
+
})]);
|
|
42
|
+
parent = item;
|
|
43
|
+
breadcrumbs = ancestors;
|
|
44
|
+
} catch (_error) {
|
|
45
|
+
req.payload.logger.warn({
|
|
46
|
+
msg: `Hierarchy item not found: ${parentId}`
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Build children where clause
|
|
51
|
+
// For root level (parentId is null), find items without a parent
|
|
52
|
+
// For nested level, find items with this specific parent
|
|
53
|
+
const parentCondition = parentId === null ? {
|
|
54
|
+
or: [{
|
|
55
|
+
[parentFieldName]: {
|
|
56
|
+
exists: false
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
[parentFieldName]: {
|
|
60
|
+
equals: null
|
|
61
|
+
}
|
|
62
|
+
}]
|
|
63
|
+
} : {
|
|
64
|
+
[parentFieldName]: {
|
|
65
|
+
equals: parentId
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
// Build type filter condition if typeFilter is provided and collectionSpecific is configured
|
|
69
|
+
// Filter to folders that allow ANY of the selected types OR are unrestricted
|
|
70
|
+
let typeCondition;
|
|
71
|
+
if (typeFilter && typeFilter.length > 0 && hierarchyConfig.collectionSpecific && typeof hierarchyConfig.collectionSpecific === 'object') {
|
|
72
|
+
const typeFieldName = hierarchyConfig.collectionSpecific.fieldName;
|
|
73
|
+
// Exclude the hierarchy collection itself from the filter (folders always show folders)
|
|
74
|
+
const filteredTypes = typeFilter.filter(t => t !== collectionSlug);
|
|
75
|
+
if (filteredTypes.length > 0) {
|
|
76
|
+
typeCondition = {
|
|
77
|
+
or: [{
|
|
78
|
+
[typeFieldName]: {
|
|
79
|
+
in: filteredTypes
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
[typeFieldName]: {
|
|
83
|
+
exists: false
|
|
84
|
+
}
|
|
85
|
+
}]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Combine conditions: parent + search + typeFilter
|
|
90
|
+
const conditions = [parentCondition];
|
|
91
|
+
if (search) {
|
|
92
|
+
conditions.push({
|
|
93
|
+
[useAsTitle]: {
|
|
94
|
+
like: search
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (typeCondition) {
|
|
99
|
+
conditions.push(typeCondition);
|
|
100
|
+
}
|
|
101
|
+
const childrenWhere = conditions.length > 1 ? {
|
|
102
|
+
and: conditions
|
|
103
|
+
} : parentCondition;
|
|
104
|
+
// Fetch children (hierarchy items with this parent, or root items if parentId is null)
|
|
105
|
+
const childrenData = await req.payload.find({
|
|
106
|
+
collection: collectionSlug,
|
|
107
|
+
depth: 0,
|
|
108
|
+
draft: true,
|
|
109
|
+
fallbackLocale: false,
|
|
110
|
+
includeLockStatus: true,
|
|
111
|
+
limit: DEFAULT_HIERARCHY_LIST_LIMIT,
|
|
112
|
+
locale: req.locale,
|
|
113
|
+
overrideAccess: false,
|
|
114
|
+
page: 1,
|
|
115
|
+
req,
|
|
116
|
+
user,
|
|
117
|
+
where: combineWhereConstraints([childrenWhere, baseFilter])
|
|
118
|
+
});
|
|
119
|
+
// Fetch related documents from other collections
|
|
120
|
+
// At root level: show unassigned documents (where hierarchy field doesn't exist)
|
|
121
|
+
// At nested level: show documents assigned to the selected hierarchy item
|
|
122
|
+
const relatedDocumentsByCollection = {};
|
|
123
|
+
const relatedBaseFilters = {};
|
|
124
|
+
// Use pre-computed relatedCollections from sanitized hierarchy config
|
|
125
|
+
const relatedCollectionsConfig = hierarchyConfig.relatedCollections || {};
|
|
126
|
+
for (const [relatedSlug, fieldInfo] of Object.entries(relatedCollectionsConfig)) {
|
|
127
|
+
if (relatedSlug === collectionSlug) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const relatedCollectionConfig = req.payload.collections[relatedSlug]?.config;
|
|
131
|
+
if (!relatedCollectionConfig) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
// Check if user has read permission for this collection
|
|
135
|
+
if (!permissions?.collections?.[relatedSlug]?.read) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const {
|
|
139
|
+
fieldName,
|
|
140
|
+
hasMany
|
|
141
|
+
} = fieldInfo;
|
|
142
|
+
// Get baseFilter for this related collection
|
|
143
|
+
const relatedBaseFilter = await (relatedCollectionConfig.admin?.baseFilter ?? relatedCollectionConfig.admin?.baseListFilter)?.({
|
|
144
|
+
limit: DEFAULT_HIERARCHY_LIST_LIMIT,
|
|
145
|
+
page: 1,
|
|
146
|
+
req,
|
|
147
|
+
sort: undefined
|
|
148
|
+
});
|
|
149
|
+
if (relatedBaseFilter) {
|
|
150
|
+
relatedBaseFilters[relatedSlug] = relatedBaseFilter;
|
|
151
|
+
}
|
|
152
|
+
// Build where clause based on whether we're at root or nested level
|
|
153
|
+
let relationshipWhere;
|
|
154
|
+
if (parentId === null) {
|
|
155
|
+
// Root level: find documents where hierarchy field doesn't exist, is null, or is empty array
|
|
156
|
+
const conditions = [{
|
|
157
|
+
[fieldName]: {
|
|
158
|
+
exists: false
|
|
159
|
+
}
|
|
160
|
+
}, {
|
|
161
|
+
[fieldName]: {
|
|
162
|
+
equals: null
|
|
163
|
+
}
|
|
164
|
+
}];
|
|
165
|
+
if (hasMany) {
|
|
166
|
+
// hasMany fields store cleared values as empty arrays
|
|
167
|
+
conditions.push({
|
|
168
|
+
[fieldName]: {
|
|
169
|
+
equals: []
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
relationshipWhere = {
|
|
174
|
+
or: conditions
|
|
175
|
+
};
|
|
176
|
+
} else {
|
|
177
|
+
// Nested level: find documents assigned to this hierarchy item
|
|
178
|
+
// "in" operator works for both hasMany and single relationship fields
|
|
179
|
+
relationshipWhere = {
|
|
180
|
+
[fieldName]: {
|
|
181
|
+
in: [parentId]
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
// Add search filter if provided
|
|
186
|
+
const relatedUseAsTitle = relatedCollectionConfig.admin?.useAsTitle || 'id';
|
|
187
|
+
const whereWithSearch = search ? {
|
|
188
|
+
and: [relationshipWhere, {
|
|
189
|
+
[relatedUseAsTitle]: {
|
|
190
|
+
like: search
|
|
191
|
+
}
|
|
192
|
+
}]
|
|
193
|
+
} : relationshipWhere;
|
|
194
|
+
// Combine relationship where with related collection's baseFilter
|
|
195
|
+
const where = combineWhereConstraints([whereWithSearch, relatedBaseFilter]);
|
|
196
|
+
try {
|
|
197
|
+
const data = await req.payload.find({
|
|
198
|
+
collection: relatedSlug,
|
|
199
|
+
depth: 0,
|
|
200
|
+
draft: true,
|
|
201
|
+
fallbackLocale: false,
|
|
202
|
+
includeLockStatus: true,
|
|
203
|
+
limit: DEFAULT_HIERARCHY_LIST_LIMIT,
|
|
204
|
+
locale: req.locale,
|
|
205
|
+
overrideAccess: false,
|
|
206
|
+
page: 1,
|
|
207
|
+
req,
|
|
208
|
+
user,
|
|
209
|
+
where
|
|
210
|
+
});
|
|
211
|
+
if (data.totalDocs > 0) {
|
|
212
|
+
relatedDocumentsByCollection[relatedSlug] = {
|
|
213
|
+
hasMany,
|
|
214
|
+
label: getTranslation(relatedCollectionConfig.labels?.plural, req.i18n),
|
|
215
|
+
result: data
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
req.payload.logger.warn({
|
|
220
|
+
err: error,
|
|
221
|
+
msg: `Failed to query related collection ${relatedSlug}`
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Extract allowed collections from parent's collectionSpecific field
|
|
226
|
+
// - undefined: collectionSpecific not configured, no filtering needed
|
|
227
|
+
// - []: parent folder accepts everything, can only move to unrestricted destinations
|
|
228
|
+
// - [{ slug, label }, ...]: parent folder has restrictions
|
|
229
|
+
let allowedCollections;
|
|
230
|
+
if (hierarchyConfig.collectionSpecific && parent) {
|
|
231
|
+
const typeFieldName = hierarchyConfig.collectionSpecific.fieldName;
|
|
232
|
+
const typeValues = parent[typeFieldName];
|
|
233
|
+
if (typeValues && typeValues.length > 0) {
|
|
234
|
+
allowedCollections = typeValues.map(slug => {
|
|
235
|
+
const config = req.payload.collections[slug]?.config;
|
|
236
|
+
const label = config ? getTranslation(config.labels?.plural, req.i18n) : slug;
|
|
237
|
+
return {
|
|
238
|
+
slug,
|
|
239
|
+
label
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
// Parent folder accepts everything (type is null or empty)
|
|
244
|
+
allowedCollections = [];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
allowedCollections,
|
|
249
|
+
breadcrumbs,
|
|
250
|
+
childrenData,
|
|
251
|
+
parent,
|
|
252
|
+
parentFieldName,
|
|
253
|
+
parentId,
|
|
254
|
+
relatedBaseFilters: Object.keys(relatedBaseFilters).length > 0 ? relatedBaseFilters : undefined,
|
|
255
|
+
relatedDocumentsByCollection
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
//# sourceMappingURL=handleHierarchy.js.map
|