removed displayField
This commit is contained in:
@@ -278,19 +278,10 @@ function MobileCardRow({ row, config, onDelete, onNavigate, navigate, components
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFormattedDisplayValue(item: any, displayFormat?: string | string[], enumValue?: string) {
|
function getFormattedDisplayValue(item: any, displayFormat: string) {
|
||||||
if (!item) return "";
|
if (!item) return "";
|
||||||
if (enumValue) return resolveTemplate(enumValue, item);
|
|
||||||
if (!displayFormat) return item.name || item.title || item.label || item.id || JSON.stringify(item);
|
|
||||||
|
|
||||||
if (Array.isArray(displayFormat)) {
|
return resolveTemplate(displayFormat, item);
|
||||||
return displayFormat
|
|
||||||
.map(key => item[key])
|
|
||||||
.filter(val => val !== undefined && val !== null)
|
|
||||||
.join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
return item[displayFormat] || item.id || JSON.stringify(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate, isMobile, components }: any) {
|
function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate, isMobile, components }: any) {
|
||||||
@@ -307,7 +298,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
|||||||
// 1. Single Relation
|
// 1. Single Relation
|
||||||
if (field.relation && value && !Array.isArray(value)) {
|
if (field.relation && value && !Array.isArray(value)) {
|
||||||
const relationId = typeof value === 'object' ? (value.id || value._id || value.pk) : value;
|
const relationId = typeof value === 'object' ? (value.id || value._id || value.pk) : value;
|
||||||
const displayValue = getFormattedDisplayValue(value, field.displayFormat, field.enumOption?.value);
|
const displayValue = getFormattedDisplayValue(value, field.displayFormat);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chip
|
<Chip
|
||||||
@@ -327,7 +318,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
|||||||
// 2. Multi-Select (Array of relations or simple strings)
|
// 2. Multi-Select (Array of relations or simple strings)
|
||||||
if (field.type === 'array' && Array.isArray(value)) {
|
if (field.type === 'array' && Array.isArray(value)) {
|
||||||
const enumValue = field.enumOption?.value;
|
const enumValue = field.enumOption?.value;
|
||||||
const tooltipTitle = value.map((item) => getFormattedDisplayValue(item, field.displayFormat, enumValue)).join(', ');
|
const tooltipTitle = value.map((item) => getFormattedDisplayValue(item, field.displayFormat)).join(', ');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip title={tooltipTitle} arrow placement="top">
|
<Tooltip title={tooltipTitle} arrow placement="top">
|
||||||
@@ -335,7 +326,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
|||||||
{value.map((item, idx) => (
|
{value.map((item, idx) => (
|
||||||
<Chip
|
<Chip
|
||||||
key={idx}
|
key={idx}
|
||||||
label={getFormattedDisplayValue(item, field.displayFormat, enumValue)}
|
label={getFormattedDisplayValue(item, field.displayFormat)}
|
||||||
size="small"
|
size="small"
|
||||||
variant="filled"
|
variant="filled"
|
||||||
sx={{ maxWidth: 120 }}
|
sx={{ maxWidth: 120 }}
|
||||||
@@ -355,7 +346,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
|||||||
|
|
||||||
// 3. Simple Objects
|
// 3. Simple Objects
|
||||||
if (field.type === 'object' && value) {
|
if (field.type === 'object' && value) {
|
||||||
return getFormattedDisplayValue(value, field.displayFormat, field.enumOption?.value) || (isMobile ? 'Object' : JSON.stringify(value));
|
return getFormattedDisplayValue(value, field.displayFormat) || (isMobile ? 'Object' : JSON.stringify(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.type === 'number' && typeof value === 'number') {
|
if (field.type === 'number' && typeof value === 'number') {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function getFieldOptions(field: ResourceField, relationData?: any[]): Sel
|
|||||||
}
|
}
|
||||||
|
|
||||||
return data.map(item => ({
|
return data.map(item => ({
|
||||||
key: String(item[enumOption.key] ?? ''),
|
key: String(item[enumOption.key]),
|
||||||
value: resolveTemplate(enumOption.value, item),
|
value: resolveTemplate(enumOption.value, item),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user