@@ -0,0 +1,29 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user