@gisce/ooui 2.27.1 → 2.28.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/ooui",
3
- "version": "2.27.1",
3
+ "version": "2.28.0-alpha.2",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
package/src/Label.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import Field from "./Field";
2
+ import { parseBoolAttribute } from "./helpers/nodeParser";
2
3
 
3
4
  type LabelType = "secondary" | "success" | "warning" | "danger" | "default";
4
5
  type LabelSize = 1 | 2 | 3 | 4 | 5 | undefined;
@@ -52,6 +53,10 @@ class Label extends Field {
52
53
  this._labelSize = value;
53
54
  }
54
55
 
56
+ get humanDate(): boolean {
57
+ return parseBoolAttribute(this._parsedWidgetProps?.human_date ?? false);
58
+ }
59
+
55
60
  /**
56
61
  * Id of the field that this label goes with. Null if it's an independent label
57
62
  */
@@ -278,15 +278,6 @@ const evaluateAttributes = ({
278
278
  fallbackMode?: boolean;
279
279
  }) => {
280
280
  let finalTagAttributes = {};
281
- let oldTagAttributes = {};
282
- if (tagAttributes.attrs) {
283
- oldTagAttributes = parseAttributes({
284
- attrs: tagAttributes.attrs,
285
- values,
286
- fields,
287
- widgetType,
288
- });
289
- }
290
281
 
291
282
  if (tagAttributes.json_attrs) {
292
283
  try {
@@ -298,13 +289,23 @@ const evaluateAttributes = ({
298
289
  });
299
290
  } catch (error) {
300
291
  if (fallbackMode && tagAttributes.attrs) {
301
- finalTagAttributes = oldTagAttributes;
292
+ finalTagAttributes = parseAttributes({
293
+ attrs: tagAttributes.attrs,
294
+ values,
295
+ fields,
296
+ widgetType,
297
+ });
302
298
  } else {
303
299
  throw error;
304
300
  }
305
301
  }
306
302
  } else if (tagAttributes.attrs) {
307
- finalTagAttributes = oldTagAttributes;
303
+ finalTagAttributes = parseAttributes({
304
+ attrs: tagAttributes.attrs,
305
+ values,
306
+ fields,
307
+ widgetType,
308
+ });
308
309
  }
309
310
 
310
311
  return {
@@ -91,4 +91,43 @@ describe("A Label", () => {
91
91
  });
92
92
  });
93
93
  });
94
+ describe("Human date", () => {
95
+ it("should have humanDate to false by default", () => {
96
+ const widgetFactory = new WidgetFactory();
97
+ const props = {
98
+ name: "field_label",
99
+ string: "Default",
100
+ widget_props: "{}",
101
+ };
102
+ const widget = widgetFactory.createWidget("label", props);
103
+ expect(widget.humanDate).toBe(false);
104
+ });
105
+ it("should parse human_date from widget props", () => {
106
+ const widgetFactory = new WidgetFactory();
107
+
108
+ expect(
109
+ widgetFactory.createWidget("label", {
110
+ name: "field_label",
111
+ string: "Default",
112
+ widget_props: "{'human_date': true}",
113
+ }).humanDate,
114
+ ).toBe(true);
115
+
116
+ expect(
117
+ widgetFactory.createWidget("label", {
118
+ name: "field_label",
119
+ string: "Default",
120
+ widget_props: "{'human_date': false}",
121
+ }).humanDate,
122
+ ).toBe(false);
123
+
124
+ expect(
125
+ widgetFactory.createWidget("label", {
126
+ name: "field_label",
127
+ string: "Default",
128
+ widget_props: "{'human_date': '1'}",
129
+ }).humanDate,
130
+ ).toBe(true);
131
+ });
132
+ });
94
133
  });