@contrail/document-generation 2.0.39 → 2.0.41

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.
@@ -5,5 +5,4 @@ export declare class DocumentDynamicTextElementUtil {
5
5
  static isDynamicText(element: any): any;
6
6
  static handleDynamicText(element: DocumentElement, dataGroup: DataGroup): any;
7
7
  private static getPropertyValuesForElements;
8
- private static getTextValueFromFrameMembers;
9
8
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentDynamicTextElementUtil = void 0;
4
- const types_1 = require("@contrail/types");
4
+ const documents_1 = require("@contrail/documents");
5
5
  const util_1 = require("@contrail/util");
6
6
  const document_text_element_util_1 = require("./document-text-element-util");
7
7
  const HARD_CODED_PROPS = {
@@ -37,16 +37,19 @@ class DocumentDynamicTextElementUtil {
37
37
  return propertyBindingsText;
38
38
  }
39
39
  type = this.typeMap[entityType];
40
- property = type.typeProperties.find((p) => p.slug === propertySlug);
41
- if (displayFunction === "label") {
40
+ property = type.typeProperties.find(p => p.slug === propertySlug);
41
+ if (displayFunction === documents_1.DynamicTextDisplayFunction.LABEL) {
42
42
  text = (property === null || property === void 0 ? void 0 : property.label) || HARD_CODED_PROPS[propertySlug] || `${type.label} name`;
43
43
  }
44
44
  else {
45
45
  let elementValues = this.getPropertyValuesForElements(dataGroup.data, propertyBindingsText);
46
- text = this.getTextValueFromFrameMembers(displayFunction, elementValues, property);
46
+ text = documents_1.DynamicTextUtil.getTextFromFrameMemberValues(displayFunction, elementValues, property);
47
47
  }
48
48
  }
49
- if (displayLabel && displayFunction !== "label") {
49
+ if (text === undefined || text === null) {
50
+ text = 'n/a';
51
+ }
52
+ if (displayLabel && displayFunction !== documents_1.DynamicTextDisplayFunction.LABEL) {
50
53
  text = `${(property === null || property === void 0 ? void 0 : property.label) || `${type === null || type === void 0 ? void 0 : type.label} name` || HARD_CODED_PROPS[propertySlug]}: ${text}`;
51
54
  }
52
55
  }
@@ -58,42 +61,11 @@ class DocumentDynamicTextElementUtil {
58
61
  }
59
62
  static getPropertyValuesForElements(elements, propertyKey) {
60
63
  const values = [];
61
- elements.forEach((el) => {
64
+ elements.forEach(el => {
62
65
  const propertyValue = util_1.ObjectUtil.getByPath(el, propertyKey);
63
66
  values.push(propertyValue);
64
67
  });
65
68
  return values;
66
69
  }
67
- static getTextValueFromFrameMembers(displayFunction, elementValues, property) {
68
- let text;
69
- const formatter = new types_1.PropertyValueFormatter();
70
- if (displayFunction === "average") {
71
- elementValues = elementValues.filter((e) => e !== null);
72
- text = formatter.formatValue(elementValues.reduce((a, b) => a + b, 0) / elementValues.length, property.propertyType);
73
- }
74
- else if (displayFunction === "sum") {
75
- elementValues = elementValues.filter((e) => e !== null);
76
- text = formatter.formatValue(elementValues.reduce((a, b) => a + b, 0), property.propertyType);
77
- }
78
- else if (displayFunction === "uniqueArray") {
79
- text = Array.from(new Set(elementValues.filter((e) => e !== null))).join(', ');
80
- }
81
- else if (!displayFunction ||
82
- ["first", "value"].includes(displayFunction)) {
83
- text = elementValues[0];
84
- }
85
- else if (displayFunction === "last") {
86
- text = elementValues[elementValues.length - 1];
87
- }
88
- else if (displayFunction === "min") {
89
- elementValues = elementValues.filter((e) => e !== null);
90
- text = formatter.formatValue(Math.min(...elementValues), property.propertyType);
91
- }
92
- else if (displayFunction === "max") {
93
- elementValues = elementValues.filter((e) => e !== null);
94
- text = formatter.formatValue(Math.max(...elementValues), property.propertyType);
95
- }
96
- return text;
97
- }
98
70
  }
99
71
  exports.DocumentDynamicTextElementUtil = DocumentDynamicTextElementUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-generation",
3
- "version": "2.0.39",
3
+ "version": "2.0.41",
4
4
  "description": "Utilities for automatic generation of documents.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@contrail/data-grouping": "^1.0.24",
46
- "@contrail/documents": "^1.0.99",
46
+ "@contrail/documents": "^1.0.101",
47
47
  "@contrail/types": "^3.0.27",
48
48
  "@contrail/util": "^1.0.27"
49
49
  }