fix(ui): undefined operators for virtual field with unsupported field types (#13820)
### What? Fixes crash when virtual fields use field types not supported by the WhereBuilder (e.g. 'group' fields). <img width="1336" height="459" alt="Screenshot 2025-09-16 at 11 00 30 AM" src="https://github.com/user-attachments/assets/3adbb507-3033-4f52-b7cc-3c5bad74900b" /> ### Why? Users reported a crash with error "Cannot read properties of undefined (reading 'operators')" when entering collection list views with virtual fields that have `type: 'group'`. The issue occurred because: - Virtual fields can use any field type including 'group' - The `fieldTypes` object in WhereBuilder only supports specific field types (text, number, select, etc.) - Code tried to access `fieldTypes[field.type].operators` when `field.type` was 'group', causing undefined access ### How? - Refactored virtual field handling to use a unified processing flow instead of separate early returns - Virtual fields now set the `pathPrefix` to their virtual path and continue through normal field validation --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211315667956059 --------- Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import { fieldAffectsData } from 'payload/shared'
|
||||
|
||||
export const createNestedClientFieldPath = (parentPath: string, field: ClientField): string => {
|
||||
if (parentPath) {
|
||||
if (fieldAffectsData(field)) {
|
||||
if (fieldAffectsData(field) && field.name) {
|
||||
return `${parentPath}.${field.name}`
|
||||
}
|
||||
return parentPath
|
||||
|
||||
@@ -26,9 +26,10 @@ export const reduceFieldsToOptions = ({
|
||||
fields,
|
||||
i18n,
|
||||
labelPrefix,
|
||||
pathPrefix,
|
||||
pathPrefix: pathPrefixFromArgs,
|
||||
}: ReduceFieldOptionsArgs): ReducedField[] => {
|
||||
return fields.reduce((reduced, field) => {
|
||||
let pathPrefix = pathPrefixFromArgs
|
||||
// Do not filter out `field.admin.disableListFilter` fields here, as these should still render as disabled if they appear in the URL query
|
||||
// Filter out `virtual: true` fields since they are regular virtuals and not backed by a DB field
|
||||
if (
|
||||
@@ -40,18 +41,11 @@ export const reduceFieldsToOptions = ({
|
||||
|
||||
// Handle virtual:string fields (virtual relationships, e.g. "post.title")
|
||||
if ('virtual' in field && typeof field.virtual === 'string') {
|
||||
const baseLabel = ('label' in field && field.label) || ('name' in field && field.name) || ''
|
||||
const localizedLabel = getTranslation(baseLabel, i18n)
|
||||
|
||||
reduced.push({
|
||||
label: localizedLabel,
|
||||
plainTextLabel: localizedLabel,
|
||||
value: field.virtual, // e.g. "post.title"
|
||||
...fieldTypes[field.type],
|
||||
field,
|
||||
operators: fieldTypes[field.type].operators,
|
||||
})
|
||||
return reduced
|
||||
pathPrefix = pathPrefix ? pathPrefix + '.' + field.virtual : field.virtual
|
||||
if (fieldAffectsData(field)) {
|
||||
// ignore virtual field names
|
||||
field.name = ''
|
||||
}
|
||||
}
|
||||
|
||||
if (field.type === 'tabs' && 'tabs' in field) {
|
||||
|
||||
Reference in New Issue
Block a user