30 lines
615 B
JavaScript
30 lines
615 B
JavaScript
import { JSONPath as jsonpath } from "jsonpath-plus";
|
|
|
|
const hasValue = (value) =>
|
|
value !== null && value !== undefined && value !== "";
|
|
|
|
export const resolveCrmDisplayValue = ({
|
|
value,
|
|
locale,
|
|
translations,
|
|
fallbackValue
|
|
}) => {
|
|
if (!hasValue(value)) {
|
|
return fallbackValue;
|
|
}
|
|
|
|
if (locale !== "cy") {
|
|
return value;
|
|
}
|
|
|
|
const matches = jsonpath({
|
|
path: `$..[?(@ && @.value==${JSON.stringify(String(value))})].value_cy`,
|
|
json: translations,
|
|
eval: true
|
|
});
|
|
|
|
return matches[0] ?? value;
|
|
};
|
|
|
|
export default resolveCrmDisplayValue;
|