Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ firebase.json
lambda.js
_site/
.sass-cache/
public/*
34 changes: 27 additions & 7 deletions src/components/custom-object-details/custom-object-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
};
},
{}
);
};
Expand Down
Loading