Skip to content

Commit

Permalink
Merge pull request #77 from gisce/hotfix/adjust_domain_value_parser
Browse files Browse the repository at this point in the history
Adjust domain value parser
  • Loading branch information
mguellsegarra authored Apr 26, 2023
2 parents 5883fe9 + 7322f46 commit 3669753
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
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": "0.18.0",
"version": "0.18.1",
"main": "./dist/ooui.umd.js",
"module": "./dist/ooui.es.js",
"types": "./dist/index.d.ts",
Expand Down
24 changes: 13 additions & 11 deletions src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,11 @@ class Form {

let domain: string | undefined = undefined;

if (
tagAttributes["domain"] &&
tagAttributes["domain"] !== "" &&
tagAttributes["domain"] !== "[]"
) {
if (checkIfDomainHasValue(tagAttributes["domain"])) {
domain = tagAttributes["domain"];
}

if (
this._fields[tagAttributes.name] &&
this._fields[tagAttributes.name].domain &&
this._fields[tagAttributes.name].domain !== "" &&
this._fields[tagAttributes.name].domain !== "[]"
) {
if (checkIfDomainHasValue(this._fields[tagAttributes.name]?.domain)) {
domain = this._fields[tagAttributes.name].domain;
}

Expand Down Expand Up @@ -265,4 +256,15 @@ class Form {
}
}

function checkIfDomainHasValue(domain: any) {
if (!domain) {
return false;
}
if (Array.isArray(domain) && domain.length > 0) {
return true;
} else if (typeof domain === "string" && domain !== "" && domain !== "[]") {
return true;
}
return false;
}
export default Form;
21 changes: 21 additions & 0 deletions src/spec/Form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3171,4 +3171,25 @@ describe("A Form", () => {
const field = form.findById("bank") as Field;
expect(field.domain).toBeDefined();
});

it("Should be able to parse domain in XML with domain as [] in fields", () => {
const arch = `<form>
<field name="llista_preu" domain="[('tarifes_atr_compatibles', '=', tarifa), ('type', '=', 'sale')]"/>
</form>`;
const fields = {
llista_preu: {
type: "many2one",
domain: [],
},
};
const form = new Form(fields);
form.parse(arch, {
values: {},
});
const field = form.findById("llista_preu") as Field;
expect(field.domain).toBeDefined();
expect(field.domain).toBe(
"[('tarifes_atr_compatibles', '=', tarifa), ('type', '=', 'sale')]"
);
});
});

0 comments on commit 3669753

Please sign in to comment.