Skip to content

Commit

Permalink
Merge branch 'fix/only-use-attrs-if-json-attrs-not-present' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Jan 23, 2025
2 parents 2bb247c + cf537cc commit 0121f33
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
target: ['alpha', 'v2-develop']
steps:
- name: Call create sync pr
uses: gisce/[email protected].6
uses: gisce/[email protected].26
with:
repository: ${{ env.LIBRARY_NAME }}
targetBranch: ${{ matrix.target }}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/ooui",
"version": "2.27.0",
"version": "2.27.1",
"engines": {
"node": "20.5.0"
},
Expand Down
43 changes: 24 additions & 19 deletions src/helpers/attributeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,18 @@ const evaluateFieldComparison = ({
) {
result.modifiedExpectedValue = undefined;
} else {
result.modifiedValueInObject =
result.modifiedValueInObject === undefined
? false
: result.modifiedValueInObject;
result.modifiedValueInObject =
result.modifiedValueInObject === null
? false
: result.modifiedValueInObject;
if (result.modifiedValueInObject === undefined) {
result.modifiedValueInObject = false;
} else if (
Array.isArray(result.modifiedValueInObject) &&
result.modifiedValueInObject[0] !== undefined
) {
result.modifiedValueInObject = result.modifiedValueInObject[0];
}

if (result.modifiedValueInObject === null) {
result.modifiedValueInObject = false;
}
}

if (
Expand Down Expand Up @@ -274,15 +278,6 @@ const evaluateAttributes = ({
fallbackMode?: boolean;
}) => {
let finalTagAttributes = {};
let oldTagAttributes = {};
if (tagAttributes.attrs) {
oldTagAttributes = parseAttributes({
attrs: tagAttributes.attrs,
values,
fields,
widgetType,
});
}

if (tagAttributes.json_attrs) {
try {
Expand All @@ -294,13 +289,23 @@ const evaluateAttributes = ({
});
} catch (error) {
if (fallbackMode && tagAttributes.attrs) {
finalTagAttributes = oldTagAttributes;
finalTagAttributes = parseAttributes({
attrs: tagAttributes.attrs,
values,
fields,
widgetType,
});
} else {
throw error;
}
}
} else if (tagAttributes.attrs) {
finalTagAttributes = oldTagAttributes;
finalTagAttributes = parseAttributes({
attrs: tagAttributes.attrs,
values,
fields,
widgetType,
});
}

return {
Expand Down
14 changes: 14 additions & 0 deletions src/spec/attributeParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,20 @@ describe("An Attribute Parser", () => {
});
expect(evaluatedAttrs.invisible).toBeTruthy();
});
it("should properly use the id of a many2one value", () => {
const tagAttributes = {
json_attrs:
'{"invisible":{"condition":"AND","rules":[{"field":"autoconsum_id","operator":"=","value":10}]}}',
};
const values = { autoconsum_id: [10, "Autoconsum"] };
const evaluatedAttrs = evaluateAttributes({
tagAttributes,
values,
fields,
fallbackMode: false,
});
expect(evaluatedAttrs.invisible).toBeTruthy();
});
it("should properly parse a many2one attribute with undefined value", () => {
const tagAttributes = {
json_attrs:
Expand Down

0 comments on commit 0121f33

Please sign in to comment.