diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0d0a3a4..2eb6aec 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -106,7 +106,7 @@ jobs: target: ['alpha', 'v2-develop'] steps: - name: Call create sync pr - uses: gisce/create-sync-pr@v0.0.6 + uses: gisce/create-sync-pr@v0.0.26 with: repository: ${{ env.LIBRARY_NAME }} targetBranch: ${{ matrix.target }} diff --git a/package-lock.json b/package-lock.json index 52fd89f..650fda2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gisce/ooui", - "version": "2.27.0", + "version": "2.28.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@gisce/ooui", - "version": "2.27.0", + "version": "2.28.0", "dependencies": { "@gisce/conscheck": "1.0.9", "html-entities": "^2.3.3", diff --git a/package.json b/package.json index a604b80..ae6a7a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gisce/ooui", - "version": "2.27.0", + "version": "2.28.0", "engines": { "node": "20.5.0" }, diff --git a/src/Label.ts b/src/Label.ts index 665007c..b1fab19 100644 --- a/src/Label.ts +++ b/src/Label.ts @@ -1,4 +1,5 @@ import Field from "./Field"; +import { parseBoolAttribute } from "./helpers/nodeParser"; type LabelType = "secondary" | "success" | "warning" | "danger" | "default"; type LabelSize = 1 | 2 | 3 | 4 | 5 | undefined; @@ -52,6 +53,10 @@ class Label extends Field { this._labelSize = value; } + get humanDate(): boolean { + return parseBoolAttribute(this._parsedWidgetProps?.human_date ?? false); + } + /** * Id of the field that this label goes with. Null if it's an independent label */ diff --git a/src/helpers/attributeParser.ts b/src/helpers/attributeParser.ts index 691171a..daf396f 100644 --- a/src/helpers/attributeParser.ts +++ b/src/helpers/attributeParser.ts @@ -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 ( diff --git a/src/spec/Label.spec.ts b/src/spec/Label.spec.ts index 75f53c9..0016ef2 100644 --- a/src/spec/Label.spec.ts +++ b/src/spec/Label.spec.ts @@ -91,4 +91,43 @@ describe("A Label", () => { }); }); }); + describe("Human date", () => { + it("should have humanDate to false by default", () => { + const widgetFactory = new WidgetFactory(); + const props = { + name: "field_label", + string: "Default", + widget_props: "{}", + }; + const widget = widgetFactory.createWidget("label", props); + expect(widget.humanDate).toBe(false); + }); + it("should parse human_date from widget props", () => { + const widgetFactory = new WidgetFactory(); + + expect( + widgetFactory.createWidget("label", { + name: "field_label", + string: "Default", + widget_props: "{'human_date': true}", + }).humanDate, + ).toBe(true); + + expect( + widgetFactory.createWidget("label", { + name: "field_label", + string: "Default", + widget_props: "{'human_date': false}", + }).humanDate, + ).toBe(false); + + expect( + widgetFactory.createWidget("label", { + name: "field_label", + string: "Default", + widget_props: "{'human_date': '1'}", + }).humanDate, + ).toBe(true); + }); + }); }); diff --git a/src/spec/attributeParser.spec.ts b/src/spec/attributeParser.spec.ts index b6dc075..b9833d0 100644 --- a/src/spec/attributeParser.spec.ts +++ b/src/spec/attributeParser.spec.ts @@ -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: