Skip to content

Commit 9a970d2

Browse files
authored
fix: custom id field not shown depending on field and db types (#9091)
Closes #9080
1 parent 8a20231 commit 9a970d2

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

packages/next/src/utilities/initPage/handleAdminPage.ts

+25-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import type {
55
SanitizedGlobalConfig,
66
} from 'payload'
77

8+
import { fieldAffectsData } from 'payload/shared'
9+
810
import { getRouteWithoutAdmin, isAdminRoute } from './shared.js'
911

1012
type Args = {
1113
adminRoute: string
1214
config: SanitizedConfig
1315
defaultIDType: Payload['db']['defaultIDType']
16+
payload?: Payload
1417
route: string
1518
}
1619

@@ -22,23 +25,23 @@ type RouteInfo = {
2225
globalSlug?: string
2326
}
2427

25-
export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args): RouteInfo {
28+
export function getRouteInfo({
29+
adminRoute,
30+
config,
31+
defaultIDType,
32+
payload,
33+
route,
34+
}: Args): RouteInfo {
2635
if (isAdminRoute({ adminRoute, config, route })) {
2736
const routeWithoutAdmin = getRouteWithoutAdmin({ adminRoute, route })
2837
const routeSegments = routeWithoutAdmin.split('/').filter(Boolean)
2938
const [entityType, entitySlug, createOrID] = routeSegments
3039
const collectionSlug = entityType === 'collections' ? entitySlug : undefined
3140
const globalSlug = entityType === 'globals' ? entitySlug : undefined
3241

33-
const docID =
34-
collectionSlug && createOrID !== 'create'
35-
? defaultIDType === 'number'
36-
? Number(createOrID)
37-
: createOrID
38-
: undefined
39-
4042
let collectionConfig: SanitizedCollectionConfig | undefined
4143
let globalConfig: SanitizedGlobalConfig | undefined
44+
let idType = defaultIDType
4245

4346
if (collectionSlug) {
4447
collectionConfig = config.collections.find((collection) => collection.slug === collectionSlug)
@@ -48,6 +51,20 @@ export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args)
4851
globalConfig = config.globals.find((global) => global.slug === globalSlug)
4952
}
5053

54+
// If the collection has an ID field, we need to determine the type of the ID field
55+
if (collectionConfig && payload) {
56+
if (payload.collections?.[collectionSlug]) {
57+
idType = payload.collections?.[collectionSlug].customIDType
58+
}
59+
}
60+
61+
const docID =
62+
collectionSlug && createOrID !== 'create'
63+
? idType === 'number'
64+
? Number(createOrID)
65+
: createOrID
66+
: undefined
67+
5168
return {
5269
collectionConfig,
5370
collectionSlug,

packages/next/src/utilities/initPage/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export const initPage = async ({
149149
adminRoute,
150150
config: payload.config,
151151
defaultIDType: payload.db.defaultIDType,
152+
payload,
152153
route,
153154
})
154155

0 commit comments

Comments
 (0)