@gisce/ooui 2.29.0 → 2.30.0-alpha.1

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.29.0",
3
+ "version": "2.30.0-alpha.1",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
package/src/Indicator.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import Selection from "./Selection";
2
+ import { replaceEntities } from "./helpers/attributeParser";
2
3
 
3
4
  class Indicator extends Selection {
4
5
  _nolabel: boolean = true;
@@ -30,6 +31,11 @@ class Indicator extends Selection {
30
31
  this._suffix = value;
31
32
  }
32
33
 
34
+ _color: string | undefined = undefined;
35
+ get color(): string | undefined {
36
+ return this._color;
37
+ }
38
+
33
39
  /**
34
40
  * Action id
35
41
  */
@@ -58,8 +64,9 @@ class Indicator extends Selection {
58
64
  this._suffix = "";
59
65
  if (this._parsedWidgetProps) {
60
66
  this._card = this._parsedWidgetProps.card || false;
61
- this._icon = this._parsedWidgetProps.icon || "";
67
+ this._icon = replaceEntities(this._parsedWidgetProps.icon) || "";
62
68
  this._suffix = this._parsedWidgetProps.suffix || "";
69
+ this._color = replaceEntities(this._parsedWidgetProps.color) || "";
63
70
  }
64
71
  if (props) {
65
72
  if (props.action_id) {
@@ -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 {
@@ -43,4 +43,20 @@ describe("An Indicator", () => {
43
43
  const widget = widgetFactory.createWidget("indicator", props);
44
44
  expect(widget.card).toBe(false);
45
45
  });
46
+ it("should allow conditions in icon widget props", () => {
47
+ const widgetFactory = new WidgetFactory();
48
+ const props = {
49
+ widget_props: "{'icon': 'alert-triange:value>10;wallet:value==0'}",
50
+ };
51
+ const widget = widgetFactory.createWidget("indicator", props);
52
+ expect(widget.icon).toBe("alert-triange:value>10;wallet:value==0");
53
+ });
54
+ it("should allow color in widget props", () => {
55
+ const widgetFactory = new WidgetFactory();
56
+ const props = {
57
+ widget_props: "{'color': 'red'}",
58
+ };
59
+ const widget = widgetFactory.createWidget("indicator", props);
60
+ expect(widget.color).toBe("red");
61
+ });
46
62
  });