JSON parse normalize function
This commit is contained in:
@@ -302,6 +302,38 @@ const clientSummary = computed(() => {
|
|||||||
trr: p.trr || p.bank_account || null,
|
trr: p.trr || p.bank_account || null,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Normalise contract meta: handles JSON strings and PHP numeric-keyed wrappers.
|
||||||
|
// When a top-level value has no {title, value, type} shape but is itself a plain
|
||||||
|
// object, we flatten one level so the real meta entries become the top-level keys.
|
||||||
|
function normalizeMeta(meta) {
|
||||||
|
if (!meta) return {};
|
||||||
|
let obj = meta;
|
||||||
|
if (typeof obj === "string") {
|
||||||
|
try {
|
||||||
|
obj = JSON.parse(obj);
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof obj !== "object" || Array.isArray(obj)) return {};
|
||||||
|
const result = {};
|
||||||
|
for (const [key, val] of Object.entries(obj)) {
|
||||||
|
if (
|
||||||
|
val &&
|
||||||
|
typeof val === "object" &&
|
||||||
|
!Array.isArray(val) &&
|
||||||
|
!("value" in val) &&
|
||||||
|
!("title" in val)
|
||||||
|
) {
|
||||||
|
// Nested meta map — flatten it one level
|
||||||
|
Object.assign(result, val);
|
||||||
|
} else {
|
||||||
|
result[key] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -447,10 +479,10 @@ const clientSummary = computed(() => {
|
|||||||
{{ textTrancate(c.description, 50, false) }}
|
{{ textTrancate(c.description, 50, false) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<template v-if="c.meta && Object.keys(c.meta).length > 0">
|
<template v-if="Object.keys(normalizeMeta(c.meta)).length > 0">
|
||||||
<Separator class="my-1" />
|
<Separator class="my-1" />
|
||||||
<div
|
<div
|
||||||
v-if="c.meta && Object.keys(c.meta).length > 0"
|
v-if="Object.keys(normalizeMeta(c.meta)).length > 0"
|
||||||
class="flex flex-col gap-1"
|
class="flex flex-col gap-1"
|
||||||
>
|
>
|
||||||
<div class="flex items-center justify-between border-b p-2">
|
<div class="flex items-center justify-between border-b p-2">
|
||||||
@@ -459,7 +491,7 @@ const clientSummary = computed(() => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 gap-1">
|
<div class="grid grid-cols-2 gap-1">
|
||||||
<div
|
<div
|
||||||
v-for="(val, key) in c.meta"
|
v-for="(val, key) in normalizeMeta(c.meta)"
|
||||||
:key="key"
|
:key="key"
|
||||||
class="flex flex-col gap-2 px-2 py-2 bg-gray-50 dark:bg-gray-800/50 even:bg-gray-100 dark:even:bg-gray-700/50 rounded-lg"
|
class="flex flex-col gap-2 px-2 py-2 bg-gray-50 dark:bg-gray-800/50 even:bg-gray-100 dark:even:bg-gray-700/50 rounded-lg"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user