From df40ea5f3a58a4514b2c54e014a34f470d67fe61 Mon Sep 17 00:00:00 2001 From: James Luterek Date: Tue, 27 Jan 2026 13:25:32 -0500 Subject: [PATCH] Fix for snake case attribute keys. --- .gitignore | 1 + .../custom-object-details.tsx | 34 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 44fa69d..62d6b22 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ firebase.json lambda.js _site/ .sass-cache/ +public/* \ No newline at end of file diff --git a/src/components/custom-object-details/custom-object-details.tsx b/src/components/custom-object-details/custom-object-details.tsx index 9519a7c..e49b73c 100644 --- a/src/components/custom-object-details/custom-object-details.tsx +++ b/src/components/custom-object-details/custom-object-details.tsx @@ -16,7 +16,7 @@ import { useParams } from 'react-router-dom'; import LoadingSpinner from '@commercetools-uikit/loading-spinner'; import { ContentNotification } from '@commercetools-uikit/notifications'; import Spacings from '@commercetools-uikit/spacings'; -import { reduce, isPlainObject, get } from 'lodash'; +import { reduce, isPlainObject, camelCase } from 'lodash'; import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; import { useIsAuthorized } from '@commercetools-frontend/permissions'; import { PERMISSIONS, AttributeValue } from '../../constants'; @@ -39,15 +39,35 @@ type Props = { onClose: () => void; }; +// Find a value from the source object by matching camelCase keys +// This handles cases where the stored data uses different naming conventions +// (e.g., SCREAMING_SNAKE_CASE, snake_case) than the schema (camelCase) +const findValueByKey = (obj: any, targetKey: string): any => { + if (!obj || typeof obj !== 'object') return undefined; + + // First try direct key match + if (targetKey in obj) return obj[targetKey]; + + // Find key where camelCase version matches the target key + const matchingKey = Object.keys(obj).find( + (key) => camelCase(key) === targetKey + ); + + return matchingKey ? obj[matchingKey] : undefined; +}; + const getValueForAttributes = (value: any, empty: any): any => { return reduce( empty, - (result, val, key) => ({ - ...result, - [key]: isPlainObject(val) - ? getValueForAttributes(get(value, key), val) - : get(value, key) || val, - }), + (result, val, key) => { + const foundValue = findValueByKey(value, key); + return { + ...result, + [key]: isPlainObject(val) + ? getValueForAttributes(foundValue, val) + : foundValue ?? val, + }; + }, {} ); };