refactor: replace all displayField usages with displayFormat
This commit is contained in:
@@ -278,19 +278,19 @@ function MobileCardRow({ row, config, onDelete, onNavigate, navigate, components
|
||||
);
|
||||
}
|
||||
|
||||
function getFormattedDisplayValue(item: any, displayField?: string | string[], enumValue?: string) {
|
||||
function getFormattedDisplayValue(item: any, displayFormat?: string | string[], enumValue?: string) {
|
||||
if (!item) return "";
|
||||
if (enumValue) return resolveTemplate(enumValue, item);
|
||||
if (!displayField) return item.name || item.title || item.label || item.id || JSON.stringify(item);
|
||||
if (!displayFormat) return item.name || item.title || item.label || item.id || JSON.stringify(item);
|
||||
|
||||
if (Array.isArray(displayField)) {
|
||||
return displayField
|
||||
.map(key => item[key])
|
||||
.filter(val => val !== undefined && val !== null)
|
||||
.join(' ');
|
||||
if (Array.isArray(displayFormat)) {
|
||||
return displayFormat
|
||||
.map(key => item[key])
|
||||
.filter(val => val !== undefined && val !== null)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
return item[displayField] || item.id || JSON.stringify(item);
|
||||
return item[displayFormat] || item.id || JSON.stringify(item);
|
||||
}
|
||||
|
||||
function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate, isMobile, components }: any) {
|
||||
@@ -307,7 +307,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
||||
// 1. Single Relation
|
||||
if (field.relation && value && !Array.isArray(value)) {
|
||||
const relationId = typeof value === 'object' ? (value.id || value._id || value.pk) : value;
|
||||
const displayValue = getFormattedDisplayValue(value, field.displayField, field.enumOption?.value);
|
||||
const displayValue = getFormattedDisplayValue(value, field.displayFormat, field.enumOption?.value);
|
||||
|
||||
return (
|
||||
<Chip
|
||||
@@ -327,7 +327,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
||||
// 2. Multi-Select (Array of relations or simple strings)
|
||||
if (field.type === 'array' && Array.isArray(value)) {
|
||||
const enumValue = field.enumOption?.value;
|
||||
const tooltipTitle = value.map((item) => getFormattedDisplayValue(item, field.displayField, enumValue)).join(', ');
|
||||
const tooltipTitle = value.map((item) => getFormattedDisplayValue(item, field.displayFormat, enumValue)).join(', ');
|
||||
|
||||
return (
|
||||
<Tooltip title={tooltipTitle} arrow placement="top">
|
||||
@@ -335,7 +335,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
||||
{value.map((item, idx) => (
|
||||
<Chip
|
||||
key={idx}
|
||||
label={getFormattedDisplayValue(item, field.displayField, enumValue)}
|
||||
label={getFormattedDisplayValue(item, field.displayFormat, enumValue)}
|
||||
size="small"
|
||||
variant="filled"
|
||||
sx={{ maxWidth: 120 }}
|
||||
@@ -355,7 +355,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
||||
|
||||
// 3. Simple Objects
|
||||
if (field.type === 'object' && value) {
|
||||
return getFormattedDisplayValue(value, field.displayField, field.enumOption?.value) || (isMobile ? 'Object' : JSON.stringify(value));
|
||||
return getFormattedDisplayValue(value, field.displayFormat, field.enumOption?.value) || (isMobile ? 'Object' : JSON.stringify(value));
|
||||
}
|
||||
|
||||
if (field.type === 'number' && typeof value === 'number') {
|
||||
|
||||
@@ -124,7 +124,7 @@ function extractOptions(
|
||||
|
||||
if (field.enumOption?.value) return resolveTemplate(field.enumOption.value, item);
|
||||
|
||||
// Use displayFormat if defined, otherwise fall back to displayField logic (for backward compatibility)
|
||||
// Use displayFormat if defined
|
||||
if (field.displayFormat) {
|
||||
return resolveTemplate(field.displayFormat, item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user