support data transformation for the additional field
This commit is contained in:
parent
03236f8ce3
commit
de5a426daa
@ -27,11 +27,11 @@ function getValue(field, data) {
|
|||||||
return value[lastField] ?? null;
|
return value[lastField] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatValue(t, mapping, rawValue) {
|
function formatValue(t, transformation, rawValue) {
|
||||||
let value = rawValue;
|
let value = rawValue;
|
||||||
|
|
||||||
// Remap the value.
|
// Remap the value.
|
||||||
const remaps = mapping?.remap ?? [];
|
const remaps = transformation?.remap ?? [];
|
||||||
for (let i = 0; i < remaps.length; i += 1) {
|
for (let i = 0; i < remaps.length; i += 1) {
|
||||||
const remap = remaps[i];
|
const remap = remaps[i];
|
||||||
if (remap?.any || remap?.value === value) {
|
if (remap?.any || remap?.value === value) {
|
||||||
@ -42,7 +42,7 @@ function formatValue(t, mapping, rawValue) {
|
|||||||
|
|
||||||
// Scale the value. Accepts either a number to multiply by or a string
|
// Scale the value. Accepts either a number to multiply by or a string
|
||||||
// like "12/345".
|
// like "12/345".
|
||||||
const scale = mapping?.scale;
|
const scale = transformation?.scale;
|
||||||
if (typeof scale === "number") {
|
if (typeof scale === "number") {
|
||||||
value *= scale;
|
value *= scale;
|
||||||
} else if (typeof scale === "string") {
|
} else if (typeof scale === "string") {
|
||||||
@ -53,7 +53,7 @@ function formatValue(t, mapping, rawValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Format the value using a known type.
|
// Format the value using a known type.
|
||||||
switch (mapping?.format) {
|
switch (transformation?.format) {
|
||||||
case "number":
|
case "number":
|
||||||
value = t("common.number", { value: parseInt(value, 10) });
|
value = t("common.number", { value: parseInt(value, 10) });
|
||||||
break;
|
break;
|
||||||
@ -72,17 +72,17 @@ function formatValue(t, mapping, rawValue) {
|
|||||||
case "date":
|
case "date":
|
||||||
value = t("common.date", {
|
value = t("common.date", {
|
||||||
value,
|
value,
|
||||||
lng: mapping?.locale,
|
lng: transformation?.locale,
|
||||||
dateStyle: mapping?.dateStyle ?? "long",
|
dateStyle: transformation?.dateStyle ?? "long",
|
||||||
timeStyle: mapping?.timeStyle,
|
timeStyle: transformation?.timeStyle,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "relativeDate":
|
case "relativeDate":
|
||||||
value = t("common.relativeDate", {
|
value = t("common.relativeDate", {
|
||||||
value,
|
value,
|
||||||
lng: mapping?.locale,
|
lng: transformation?.locale,
|
||||||
style: mapping?.style,
|
style: transformation?.style,
|
||||||
numeric: mapping?.numeric,
|
numeric: transformation?.numeric,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "text":
|
case "text":
|
||||||
@ -91,7 +91,7 @@ function formatValue(t, mapping, rawValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply fixed suffix.
|
// Apply fixed suffix.
|
||||||
const suffix = mapping?.suffix;
|
const suffix = transformation?.suffix;
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
value = `${value} ${suffix}`;
|
value = `${value} ${suffix}`;
|
||||||
}
|
}
|
||||||
@ -100,8 +100,8 @@ function formatValue(t, mapping, rawValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getColor(mapping, customData) {
|
function getColor(mapping, customData) {
|
||||||
const value = getValue(mapping.additionalField, customData);
|
const value = getValue(mapping.additionalField.field, customData);
|
||||||
const color = mapping.additionalFieldColor;
|
const { color } = mapping.additionalField;
|
||||||
|
|
||||||
switch (color) {
|
switch (color) {
|
||||||
case "auto":
|
case "auto":
|
||||||
@ -187,7 +187,7 @@ export default function Component({ service }) {
|
|||||||
</div>
|
</div>
|
||||||
{mapping.additionalField && (
|
{mapping.additionalField && (
|
||||||
<div className={`font-bold mr-2 ${getColor(mapping, customData)}`} >
|
<div className={`font-bold mr-2 ${getColor(mapping, customData)}`} >
|
||||||
{getValue(mapping.additionalField, customData)}
|
{formatValue(t, mapping.additionalField, getValue(mapping.additionalField.field, customData))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user