refactor: refs #8833 streamline state color handling in Claim components
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Benjamin Esteve 2025-04-09 10:37:30 +02:00
parent ac7fab7ada
commit d8a5945bce
3 changed files with 10 additions and 29 deletions

View File

@ -28,14 +28,8 @@ const entityId = computed(() => {
return $props.id || route.params.id; return $props.id || route.params.id;
}); });
const STATE_COLOR = { function stateColor(entity) {
pending: 'warning', return entity?.claimState?.classColor || 'grey';
incomplete: 'info',
resolved: 'positive',
canceled: 'negative',
};
function stateColor(code) {
return STATE_COLOR[code];
} }
onMounted(async () => { onMounted(async () => {
@ -56,11 +50,7 @@ onMounted(async () => {
<template #body="{ entity }"> <template #body="{ entity }">
<VnLv v-if="entity.claimState" :label="t('claim.state')"> <VnLv v-if="entity.claimState" :label="t('claim.state')">
<template #value> <template #value>
<QBadge <QBadge :color="stateColor(entity)" text-color="black" dense>
:color="stateColor(entity.claimState.code)"
text-color="black"
dense
>
{{ entity.claimState.description }} {{ entity.claimState.description }}
</QBadge> </QBadge>
</template> </template>

View File

@ -108,15 +108,9 @@ const markerLabels = [
{ value: 5, label: t('claim.person') }, { value: 5, label: t('claim.person') },
]; ];
const STATE_COLOR = {
pending: 'warning',
incomplete: 'info',
resolved: 'positive',
canceled: 'negative',
};
function stateColor(code) { function stateColor(code) {
return STATE_COLOR[code]; const claimState = claimStates.value.find((state) => state.code === code);
return claimState?.classColor || 'grey';
} }
const developmentColumns = ref([ const developmentColumns = ref([
@ -188,7 +182,7 @@ function claimUrl(section) {
<template> <template>
<FetchData <FetchData
url="ClaimStates" url="ClaimStates"
:filter="{ fields: ['id', 'description'] }" :filter="{ fields: ['id', 'description', 'code', 'classColor'] }"
@on-fetch="(data) => (claimStates = data)" @on-fetch="(data) => (claimStates = data)"
auto-load auto-load
/> />

View File

@ -101,7 +101,10 @@ const columns = computed(() => [
name: 'stateCode', name: 'stateCode',
chip: { chip: {
condition: () => true, condition: () => true,
color: ({ stateCode }) => STATE_COLOR[stateCode] ?? 'bg-grey', color: ({ stateCode }) => {
const state = states.value?.find(({ code }) => code === stateCode);
return state ? `bg-${state.classColor}` : 'bg-grey';
},
}, },
columnFilter: { columnFilter: {
name: 'claimStateFk', name: 'claimStateFk',
@ -131,12 +134,6 @@ const columns = computed(() => [
], ],
}, },
]); ]);
const STATE_COLOR = {
pending: 'bg-warning',
loses: 'bg-negative',
resolved: 'bg-positive',
};
</script> </script>
<template> <template>