0
0
Fork 0

Merge pull request '#8018 - Show fields instead null/undefined' (!737) from 8018_location_label into dev

Reviewed-on: verdnatura/salix-front#737
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Javier Segarra 2024-09-30 10:55:04 +00:00
commit d4dc12ebe3
1 changed files with 33 additions and 4 deletions

View File

@ -12,14 +12,43 @@ const props = defineProps({
default: null,
},
});
const formatLocation = (obj, properties) => {
const parts = properties.map((prop) => {
if (typeof prop === 'string') {
return obj[prop];
} else if (typeof prop === 'function') {
return prop(obj);
}
return null;
});
const filteredParts = parts.filter(
(part) => part !== null && part !== undefined && part !== ''
);
return filteredParts.join(', ');
};
const locationProperties = [
'postcode',
(obj) =>
obj.city
? `${obj.city}${obj.province?.name ? `(${obj.province.name})` : ''}`
: null,
(obj) => obj.country?.name,
];
const modelValue = ref(
props.location
? `${props.location?.postcode}, ${props.location?.city}(${props.location?.province?.name}), ${props.location?.country?.name}`
: null
props.location ? formatLocation(props.location, locationProperties) : null
);
function showLabel(data) {
return `${data.code}, ${data.town}(${data.province}), ${data.country}`;
const dataProperties = [
'code',
(obj) => (obj.town ? `${obj.town}(${obj.province})` : null),
'country',
];
return formatLocation(data, dataProperties);
}
const handleModelValue = (data) => {
emit('update:model-value', data);
};