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,
|
SanitizedGlobalConfig,
|
||||||
} from 'payload'
|
} from 'payload'
|
||||||
|
|
||||||
|
import { fieldAffectsData } from 'payload/shared'
|
||||||
|
|
||||||
import { getRouteWithoutAdmin, isAdminRoute } from './shared.js'
|
import { getRouteWithoutAdmin, isAdminRoute } from './shared.js'
|
||||||
|
|
||||||
type Args = {
|
type Args = {
|
||||||
adminRoute: string
|
adminRoute: string
|
||||||
config: SanitizedConfig
|
config: SanitizedConfig
|
||||||
defaultIDType: Payload['db']['defaultIDType']
|
defaultIDType: Payload['db']['defaultIDType']
|
||||||
|
payload?: Payload
|
||||||
route: string
|
route: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +25,13 @@ type RouteInfo = {
|
|||||||
globalSlug?: string
|
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 })) {
|
if (isAdminRoute({ adminRoute, config, route })) {
|
||||||
const routeWithoutAdmin = getRouteWithoutAdmin({ adminRoute, route })
|
const routeWithoutAdmin = getRouteWithoutAdmin({ adminRoute, route })
|
||||||
const routeSegments = routeWithoutAdmin.split('/').filter(Boolean)
|
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 collectionSlug = entityType === 'collections' ? entitySlug : undefined
|
||||||
const globalSlug = entityType === 'globals' ? entitySlug : undefined
|
const globalSlug = entityType === 'globals' ? entitySlug : undefined
|
||||||
|
|
||||||
const docID =
|
|
||||||
collectionSlug && createOrID !== 'create'
|
|
||||||
? defaultIDType === 'number'
|
|
||||||
? Number(createOrID)
|
|
||||||
: createOrID
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
let collectionConfig: SanitizedCollectionConfig | undefined
|
let collectionConfig: SanitizedCollectionConfig | undefined
|
||||||
let globalConfig: SanitizedGlobalConfig | undefined
|
let globalConfig: SanitizedGlobalConfig | undefined
|
||||||
|
let idType = defaultIDType
|
||||||
|
|
||||||
if (collectionSlug) {
|
if (collectionSlug) {
|
||||||
collectionConfig = config.collections.find((collection) => collection.slug === 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)
|
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 {
|
return {
|
||||||
collectionConfig,
|
collectionConfig,
|
||||||
collectionSlug,
|
collectionSlug,
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ export const initPage = async ({
|
|||||||
adminRoute,
|
adminRoute,
|
||||||
config: payload.config,
|
config: payload.config,
|
||||||
defaultIDType: payload.db.defaultIDType,
|
defaultIDType: payload.db.defaultIDType,
|
||||||
|
payload,
|
||||||
route,
|
route,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user