Skip to content

Commit 8988581

Browse files
committed
1715 - extract formatKeysWithDigits into a separate file, also improve the object check
1 parent 1880ff3 commit 8988581

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

client/src/pages/platform/workflow-editor/components/Properties/Property.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {twMerge} from 'tailwind-merge';
3434
import {useDebouncedCallback} from 'use-debounce';
3535

3636
import useWorkflowEditorStore from '../../stores/useWorkflowEditorStore';
37+
import formatKeysWithDigits from '../../utils/formatKeysWithDigits';
3738
import replaceSpacesInKeys from '../../utils/replaceSpacesInObjectKeys';
3839
import ArrayProperty from './ArrayProperty';
3940
import ObjectProperty from './ObjectProperty';
@@ -199,24 +200,6 @@ const Property = ({
199200
return componentDefinitions.find((component) => component.name === componentName)?.icon || '📄';
200201
};
201202

202-
const formatKeysWithDigits = (obj: any) => {
203-
const formattedObj = {...obj};
204-
205-
Object.keys(formattedObj).forEach((key) => {
206-
if (key.match(/^\d/)) {
207-
formattedObj[`${PATH_DIGIT_PREFIX}${key}`] = formattedObj[key];
208-
209-
delete formattedObj[key];
210-
}
211-
212-
if (typeof formattedObj[key] === 'object' && formattedObj[key] !== null) {
213-
formattedObj[key] = formatKeysWithDigits(formattedObj[key]);
214-
}
215-
});
216-
217-
return formattedObj;
218-
};
219-
220203
const saveInputValue = useDebouncedCallback(() => {
221204
if (!currentComponent || !workflow || !name || !path || !updateWorkflowNodeParameterMutation) {
222205
return;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {PATH_DIGIT_PREFIX} from '@/shared/constants';
2+
import isObject from 'isobject';
3+
4+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5+
export default function formatKeysWithDigits(obj: any) {
6+
const formattedObj = {...obj};
7+
8+
Object.keys(formattedObj).forEach((key) => {
9+
if (key.match(/^\d/)) {
10+
formattedObj[`${PATH_DIGIT_PREFIX}${key}`] = formattedObj[key];
11+
12+
delete formattedObj[key];
13+
}
14+
15+
if (isObject(formattedObj[key]) && formattedObj[key] !== null) {
16+
formattedObj[key] = formatKeysWithDigits(formattedObj[key]);
17+
}
18+
});
19+
20+
return formattedObj;
21+
}

0 commit comments

Comments
 (0)