Skip to content

Commit

Permalink
fix: get custom field values
Browse files Browse the repository at this point in the history
  • Loading branch information
hel-axelor committed May 2, 2024
1 parent 59aaa6d commit 3591984
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ const CustomFieldForm = ({
}, [fields, panels, readonly]);

const attrsValues = useMemo(
() => (object?.id !== modelId ? null : getAttrsValue(object)),
[modelId, object],
() => (object?.id != modelId ? null : getAttrsValue(object, fieldType)),
[modelId, object, fieldType],
);

const _additionalActions: Action[] = useMemo(
Expand Down
18 changes: 7 additions & 11 deletions packages/core/src/forms/studio/formula.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,16 @@ export const mapStudioFieldsWithFormula = (
}));
};

export const getAttrsValue = (object: any) => {
if (isEmpty(object)) {
export const getAttrsValue = (object: Object, fieldType: string) => {
if (
isEmpty(object) ||
!object.hasOwnProperty(fieldType) ||
typeof object[fieldType] !== 'string'
) {
return {};
}

let result = {};

Object.entries(object)
.filter(([key]) => key.toLowerCase().includes('attrs'))
.forEach(([_, value]: [string, string]) => {
result = {...result, ...JSON.parse(value)};
});

return result;
return JSON.parse(object[fieldType]);
};

export const createFormulaFunction = (formula: string) => {
Expand Down

0 comments on commit 3591984

Please sign in to comment.