fix(ui): properly handles ID field component type based on payload.db.defaultIDType (#7416)
## Description Fixes #7354 Since the `defaultIDType` for IDs in `postgres` are of type `number` - the `contains` operator should be available in the filter options. This PR checks the `defaultIDType` of ID and properly outputs the correct component type for IDs I.e if ID is of type `number` - the filter operators for ID should correspond to the the operators of type number as well The `contains` operator only belongs on fields of type string, aka of component type `text` - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] Existing test suite passes locally with my changes
This commit is contained in:
@@ -6,7 +6,7 @@ import type { SanitizedCollectionConfig, TypeWithID } from '../collections/confi
|
|||||||
import type { SanitizedConfig } from '../config/types.js'
|
import type { SanitizedConfig } from '../config/types.js'
|
||||||
import type { Field, FieldAffectingData, RichTextField, Validate } from '../fields/config/types.js'
|
import type { Field, FieldAffectingData, RichTextField, Validate } from '../fields/config/types.js'
|
||||||
import type { SanitizedGlobalConfig } from '../globals/config/types.js'
|
import type { SanitizedGlobalConfig } from '../globals/config/types.js'
|
||||||
import type { JsonObject, PayloadRequest, RequestContext } from '../types/index.js'
|
import type { JsonObject, Payload, PayloadRequest, RequestContext } from '../types/index.js'
|
||||||
import type { WithServerSidePropsComponentProps } from './elements/WithServerSideProps.js'
|
import type { WithServerSidePropsComponentProps } from './elements/WithServerSideProps.js'
|
||||||
|
|
||||||
export type RichTextFieldProps<Value extends object, AdapterProps, ExtraFieldProperties = {}> = {
|
export type RichTextFieldProps<Value extends object, AdapterProps, ExtraFieldProperties = {}> = {
|
||||||
@@ -189,6 +189,7 @@ type RichTextAdapterBase<
|
|||||||
WithServerSideProps: React.FC<Omit<WithServerSidePropsComponentProps, 'serverOnlyProps'>>
|
WithServerSideProps: React.FC<Omit<WithServerSidePropsComponentProps, 'serverOnlyProps'>>
|
||||||
config: SanitizedConfig
|
config: SanitizedConfig
|
||||||
i18n: I18nClient
|
i18n: I18nClient
|
||||||
|
payload: Payload
|
||||||
schemaPath: string
|
schemaPath: string
|
||||||
}) => Map<string, React.ReactNode>
|
}) => Map<string, React.ReactNode>
|
||||||
generateSchemaMap?: (args: {
|
generateSchemaMap?: (args: {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import type {
|
|||||||
import type {
|
import type {
|
||||||
Field,
|
Field,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
|
Payload,
|
||||||
PayloadRequest,
|
PayloadRequest,
|
||||||
ReplaceAny,
|
ReplaceAny,
|
||||||
RequestContext,
|
RequestContext,
|
||||||
@@ -283,6 +284,7 @@ export type ServerFeature<ServerProps, ClientFeatureProps> = {
|
|||||||
generateComponentMap?: (args: {
|
generateComponentMap?: (args: {
|
||||||
config: SanitizedConfig
|
config: SanitizedConfig
|
||||||
i18n: I18nClient
|
i18n: I18nClient
|
||||||
|
payload: Payload
|
||||||
props: ServerProps
|
props: ServerProps
|
||||||
schemaPath: string
|
schemaPath: string
|
||||||
}) => {
|
}) => {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const getGenerateComponentMap =
|
|||||||
(args: {
|
(args: {
|
||||||
resolvedFeatureMap: ResolvedServerFeatureMap
|
resolvedFeatureMap: ResolvedServerFeatureMap
|
||||||
}): RichTextAdapter['generateComponentMap'] =>
|
}): RichTextAdapter['generateComponentMap'] =>
|
||||||
({ WithServerSideProps, config, i18n, schemaPath }) => {
|
({ WithServerSideProps, config, i18n, payload, schemaPath }) => {
|
||||||
const componentMap = new Map()
|
const componentMap = new Map()
|
||||||
|
|
||||||
// turn args.resolvedFeatureMap into an array of [key, value] pairs, ordered by value.order, lowest order first:
|
// turn args.resolvedFeatureMap into an array of [key, value] pairs, ordered by value.order, lowest order first:
|
||||||
@@ -35,6 +35,7 @@ export const getGenerateComponentMap =
|
|||||||
const components = resolvedFeature.generateComponentMap({
|
const components = resolvedFeature.generateComponentMap({
|
||||||
config,
|
config,
|
||||||
i18n,
|
i18n,
|
||||||
|
payload,
|
||||||
props: resolvedFeature.sanitizedServerFeatureProps,
|
props: resolvedFeature.sanitizedServerFeatureProps,
|
||||||
schemaPath,
|
schemaPath,
|
||||||
})
|
})
|
||||||
@@ -80,6 +81,7 @@ export const getGenerateComponentMap =
|
|||||||
fieldSchema: fields,
|
fieldSchema: fields,
|
||||||
i18n,
|
i18n,
|
||||||
parentPath: `${schemaPath}.lexical_internal_feature.${featureKey}.fields.${schemaKey}`,
|
parentPath: `${schemaPath}.lexical_internal_feature.${featureKey}.fields.${schemaKey}`,
|
||||||
|
payload,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { defaultLeaves as leafTypes } from './field/leaves/index.js'
|
|||||||
|
|
||||||
export const getGenerateComponentMap =
|
export const getGenerateComponentMap =
|
||||||
(args: AdapterArguments): RichTextAdapter['generateComponentMap'] =>
|
(args: AdapterArguments): RichTextAdapter['generateComponentMap'] =>
|
||||||
({ WithServerSideProps, config, i18n }) => {
|
({ WithServerSideProps, config, i18n, payload }) => {
|
||||||
const componentMap = new Map()
|
const componentMap = new Map()
|
||||||
|
|
||||||
;(args?.admin?.leaves || Object.values(leafTypes)).forEach((leaf) => {
|
;(args?.admin?.leaves || Object.values(leafTypes)).forEach((leaf) => {
|
||||||
@@ -67,6 +67,7 @@ export const getGenerateComponentMap =
|
|||||||
config,
|
config,
|
||||||
fieldSchema: args.admin?.link?.fields as Field[],
|
fieldSchema: args.admin?.link?.fields as Field[],
|
||||||
i18n,
|
i18n,
|
||||||
|
payload,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -93,6 +94,7 @@ export const getGenerateComponentMap =
|
|||||||
config,
|
config,
|
||||||
fieldSchema: args?.admin?.upload?.collections[collection.slug]?.fields,
|
fieldSchema: args?.admin?.upload?.collections[collection.slug]?.fields,
|
||||||
i18n,
|
i18n,
|
||||||
|
payload,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { I18nClient } from '@payloadcms/translations'
|
|||||||
import type {
|
import type {
|
||||||
AdminViewProps,
|
AdminViewProps,
|
||||||
EditViewProps,
|
EditViewProps,
|
||||||
|
Payload,
|
||||||
SanitizedCollectionConfig,
|
SanitizedCollectionConfig,
|
||||||
SanitizedConfig,
|
SanitizedConfig,
|
||||||
} from 'payload'
|
} from 'payload'
|
||||||
@@ -26,6 +27,7 @@ export const mapCollections = (args: {
|
|||||||
collections: SanitizedCollectionConfig[]
|
collections: SanitizedCollectionConfig[]
|
||||||
config: SanitizedConfig
|
config: SanitizedConfig
|
||||||
i18n: I18nClient
|
i18n: I18nClient
|
||||||
|
payload: Payload
|
||||||
readOnly?: boolean
|
readOnly?: boolean
|
||||||
}): {
|
}): {
|
||||||
[key: SanitizedCollectionConfig['slug']]: CollectionComponentMap
|
[key: SanitizedCollectionConfig['slug']]: CollectionComponentMap
|
||||||
@@ -38,6 +40,7 @@ export const mapCollections = (args: {
|
|||||||
config,
|
config,
|
||||||
i18n,
|
i18n,
|
||||||
i18n: { t },
|
i18n: { t },
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
} = args
|
} = args
|
||||||
|
|
||||||
@@ -189,6 +192,7 @@ export const mapCollections = (args: {
|
|||||||
config,
|
config,
|
||||||
fieldSchema: fields,
|
fieldSchema: fields,
|
||||||
i18n,
|
i18n,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
}),
|
}),
|
||||||
isPreviewEnabled: !!collectionConfig?.admin?.preview,
|
isPreviewEnabled: !!collectionConfig?.admin?.preview,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import type {
|
|||||||
MappedTab,
|
MappedTab,
|
||||||
NumberFieldProps,
|
NumberFieldProps,
|
||||||
Option,
|
Option,
|
||||||
|
Payload,
|
||||||
PointFieldProps,
|
PointFieldProps,
|
||||||
RadioFieldProps,
|
RadioFieldProps,
|
||||||
ReducedBlock,
|
ReducedBlock,
|
||||||
@@ -67,6 +68,7 @@ export const mapFields = (args: {
|
|||||||
filter?: (field: Field) => boolean
|
filter?: (field: Field) => boolean
|
||||||
i18n: I18nClient
|
i18n: I18nClient
|
||||||
parentPath?: string
|
parentPath?: string
|
||||||
|
payload: Payload
|
||||||
readOnly?: boolean
|
readOnly?: boolean
|
||||||
}): FieldMap => {
|
}): FieldMap => {
|
||||||
const {
|
const {
|
||||||
@@ -78,6 +80,7 @@ export const mapFields = (args: {
|
|||||||
i18n,
|
i18n,
|
||||||
i18n: { t },
|
i18n: { t },
|
||||||
parentPath,
|
parentPath,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
} = args
|
} = args
|
||||||
|
|
||||||
@@ -193,6 +196,7 @@ export const mapFields = (args: {
|
|||||||
filter,
|
filter,
|
||||||
i18n,
|
i18n,
|
||||||
parentPath: path,
|
parentPath: path,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
}),
|
}),
|
||||||
isSortable: field.admin?.isSortable,
|
isSortable: field.admin?.isSortable,
|
||||||
@@ -217,6 +221,7 @@ export const mapFields = (args: {
|
|||||||
filter,
|
filter,
|
||||||
i18n,
|
i18n,
|
||||||
parentPath: `${path}.${block.slug}`,
|
parentPath: `${path}.${block.slug}`,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -303,6 +308,7 @@ export const mapFields = (args: {
|
|||||||
filter,
|
filter,
|
||||||
i18n,
|
i18n,
|
||||||
parentPath: path,
|
parentPath: path,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
}),
|
}),
|
||||||
initCollapsed: field.admin?.initCollapsed,
|
initCollapsed: field.admin?.initCollapsed,
|
||||||
@@ -364,6 +370,7 @@ export const mapFields = (args: {
|
|||||||
filter,
|
filter,
|
||||||
i18n,
|
i18n,
|
||||||
parentPath: path,
|
parentPath: path,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
}),
|
}),
|
||||||
hideGutter: field.admin?.hideGutter,
|
hideGutter: field.admin?.hideGutter,
|
||||||
@@ -494,6 +501,7 @@ export const mapFields = (args: {
|
|||||||
WithServerSideProps,
|
WithServerSideProps,
|
||||||
config,
|
config,
|
||||||
i18n,
|
i18n,
|
||||||
|
payload,
|
||||||
schemaPath: path,
|
schemaPath: path,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -526,6 +534,7 @@ export const mapFields = (args: {
|
|||||||
filter,
|
filter,
|
||||||
i18n,
|
i18n,
|
||||||
parentPath: path,
|
parentPath: path,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
}),
|
}),
|
||||||
readOnly: field.admin?.readOnly,
|
readOnly: field.admin?.readOnly,
|
||||||
@@ -548,6 +557,7 @@ export const mapFields = (args: {
|
|||||||
filter,
|
filter,
|
||||||
i18n,
|
i18n,
|
||||||
parentPath: path,
|
parentPath: path,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -835,7 +845,7 @@ export const mapFields = (args: {
|
|||||||
// TODO: For all fields (not just this one) we need to add the name to both .fieldComponentPropsBase.name AND .name. This can probably be improved
|
// TODO: For all fields (not just this one) we need to add the name to both .fieldComponentPropsBase.name AND .name. This can probably be improved
|
||||||
result.push({
|
result.push({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
type: 'text',
|
type: payload.db.defaultIDType === 'number' ? 'number' : 'text',
|
||||||
CustomField: null,
|
CustomField: null,
|
||||||
cellComponentProps: {
|
cellComponentProps: {
|
||||||
name: 'id',
|
name: 'id',
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { I18nClient } from '@payloadcms/translations'
|
import type { I18nClient } from '@payloadcms/translations'
|
||||||
import type { EditViewProps, SanitizedConfig, SanitizedGlobalConfig } from 'payload'
|
import type { EditViewProps, Payload, SanitizedConfig, SanitizedGlobalConfig } from 'payload'
|
||||||
|
|
||||||
import { isReactComponentOrFunction } from 'payload/shared'
|
import { isReactComponentOrFunction } from 'payload/shared'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
@@ -23,6 +23,7 @@ export const mapGlobals = ({
|
|||||||
config: SanitizedConfig
|
config: SanitizedConfig
|
||||||
globals: SanitizedGlobalConfig[]
|
globals: SanitizedGlobalConfig[]
|
||||||
i18n: I18nClient
|
i18n: I18nClient
|
||||||
|
payload: Payload
|
||||||
readOnly?: boolean
|
readOnly?: boolean
|
||||||
}
|
}
|
||||||
}): {
|
}): {
|
||||||
@@ -35,6 +36,7 @@ export const mapGlobals = ({
|
|||||||
globals,
|
globals,
|
||||||
i18n,
|
i18n,
|
||||||
i18n: { t },
|
i18n: { t },
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
} = args
|
} = args
|
||||||
|
|
||||||
@@ -122,6 +124,7 @@ export const mapGlobals = ({
|
|||||||
config,
|
config,
|
||||||
fieldSchema: fields,
|
fieldSchema: fields,
|
||||||
i18n,
|
i18n,
|
||||||
|
payload,
|
||||||
readOnly: readOnlyOverride,
|
readOnly: readOnlyOverride,
|
||||||
}),
|
}),
|
||||||
isPreviewEnabled: !!globalConfig?.admin?.preview,
|
isPreviewEnabled: !!globalConfig?.admin?.preview,
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export const buildComponentMap = (args: {
|
|||||||
collections: config.collections,
|
collections: config.collections,
|
||||||
config,
|
config,
|
||||||
i18n,
|
i18n,
|
||||||
|
payload,
|
||||||
readOnly,
|
readOnly,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ export const buildComponentMap = (args: {
|
|||||||
config,
|
config,
|
||||||
globals: config.globals,
|
globals: config.globals,
|
||||||
i18n,
|
i18n,
|
||||||
|
payload,
|
||||||
readOnly,
|
readOnly,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user