fix: custom id field not shown depending on field and db types (#9091)
Closes https://github.com/payloadcms/payload/issues/9080
This commit is contained in:
@@ -5,12 +5,15 @@ import type {
|
||||
SanitizedGlobalConfig,
|
||||
} from 'payload'
|
||||
|
||||
import { fieldAffectsData } from 'payload/shared'
|
||||
|
||||
import { getRouteWithoutAdmin, isAdminRoute } from './shared.js'
|
||||
|
||||
type Args = {
|
||||
adminRoute: string
|
||||
config: SanitizedConfig
|
||||
defaultIDType: Payload['db']['defaultIDType']
|
||||
payload?: Payload
|
||||
route: string
|
||||
}
|
||||
|
||||
@@ -22,7 +25,13 @@ type RouteInfo = {
|
||||
globalSlug?: string
|
||||
}
|
||||
|
||||
export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args): RouteInfo {
|
||||
export function getRouteInfo({
|
||||
adminRoute,
|
||||
config,
|
||||
defaultIDType,
|
||||
payload,
|
||||
route,
|
||||
}: Args): RouteInfo {
|
||||
if (isAdminRoute({ adminRoute, config, route })) {
|
||||
const routeWithoutAdmin = getRouteWithoutAdmin({ adminRoute, route })
|
||||
const routeSegments = routeWithoutAdmin.split('/').filter(Boolean)
|
||||
@@ -30,15 +39,9 @@ export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args)
|
||||
const collectionSlug = entityType === 'collections' ? entitySlug : undefined
|
||||
const globalSlug = entityType === 'globals' ? entitySlug : undefined
|
||||
|
||||
const docID =
|
||||
collectionSlug && createOrID !== 'create'
|
||||
? defaultIDType === 'number'
|
||||
? Number(createOrID)
|
||||
: createOrID
|
||||
: undefined
|
||||
|
||||
let collectionConfig: SanitizedCollectionConfig | undefined
|
||||
let globalConfig: SanitizedGlobalConfig | undefined
|
||||
let idType = defaultIDType
|
||||
|
||||
if (collectionSlug) {
|
||||
collectionConfig = config.collections.find((collection) => collection.slug === collectionSlug)
|
||||
@@ -48,6 +51,20 @@ export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args)
|
||||
globalConfig = config.globals.find((global) => global.slug === globalSlug)
|
||||
}
|
||||
|
||||
// If the collection has an ID field, we need to determine the type of the ID field
|
||||
if (collectionConfig && payload) {
|
||||
if (payload.collections?.[collectionSlug]) {
|
||||
idType = payload.collections?.[collectionSlug].customIDType
|
||||
}
|
||||
}
|
||||
|
||||
const docID =
|
||||
collectionSlug && createOrID !== 'create'
|
||||
? idType === 'number'
|
||||
? Number(createOrID)
|
||||
: createOrID
|
||||
: undefined
|
||||
|
||||
return {
|
||||
collectionConfig,
|
||||
collectionSlug,
|
||||
|
||||
@@ -149,6 +149,7 @@ export const initPage = async ({
|
||||
adminRoute,
|
||||
config: payload.config,
|
||||
defaultIDType: payload.db.defaultIDType,
|
||||
payload,
|
||||
route,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user