fix(record-picker): show N/A when no value

This commit is contained in:
chenos 2022-12-09 10:42:30 +08:00
parent 28b71dcda3
commit 0ddd73cf3b

View File

@ -16,6 +16,13 @@ interface IEllipsisWithTooltipRef {
setPopoverVisible: (boolean) => void; setPopoverVisible: (boolean) => void;
} }
const toValue = (value, placeholder) => {
if (value === null || value === undefined) {
return placeholder;
}
return value;
};
export const ReadPrettyRecordPicker: React.FC = observer((props: any) => { export const ReadPrettyRecordPicker: React.FC = observer((props: any) => {
const { ellipsis } = props; const { ellipsis } = props;
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
@ -34,8 +41,7 @@ export const ReadPrettyRecordPicker: React.FC = observer((props: any) => {
const ellipsisWithTooltipRef = useRef<IEllipsisWithTooltipRef>(); const ellipsisWithTooltipRef = useRef<IEllipsisWithTooltipRef>();
const renderRecords = () => const renderRecords = () =>
toArr(field.value).map((record, index, arr) => { toArr(field.value).map((record, index, arr) => {
const val = const val = toValue(compile(record?.[fieldNames?.label || 'label']), 'N/A');
compile(record?.[fieldNames?.label || 'label']) || record?.[fieldNames?.value || 'value'] || record?.id;
return ( return (
<Fragment key={`${record.id}_${index}`}> <Fragment key={`${record.id}_${index}`}>
<span> <span>