@contrail/documents 1.1.19 → 1.1.20

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.
@@ -36,7 +36,7 @@ export declare const HARD_CODED_TEXT: {
36
36
  'frame.colorCount': string;
37
37
  };
38
38
  export declare class DynamicTextUtil {
39
- static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, frame: {
39
+ static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: string, frame: {
40
40
  name: string;
41
41
  id?: string;
42
42
  }, componentModels: any[], ownerReferenceModel?: any): string;
@@ -49,7 +49,7 @@ const frameProperties = [
49
49
  'frame.colorCount',
50
50
  ];
51
51
  class DynamicTextUtil {
52
- static getDynamicTextValue(dynamicTextElement, property, frame, componentModels, ownerReferenceModel = null) {
52
+ static getDynamicTextValue(dynamicTextElement, property, propertyLevel, frame, componentModels, ownerReferenceModel = null) {
53
53
  var _a, _b, _c, _d;
54
54
  if (!dynamicTextElement.propertyBindings || !dynamicTextElement.propertyBindings.text) {
55
55
  return exports.CLICK_TO_CONFIGURE;
@@ -98,6 +98,22 @@ class DynamicTextUtil {
98
98
  property = null;
99
99
  }
100
100
  const frameMemberValues = [];
101
+ if (propertyLevel) {
102
+ componentModels = componentModels.filter((model) => {
103
+ var _a;
104
+ const entity = entityType === 'item' ? model === null || model === void 0 ? void 0 : model.item : model === null || model === void 0 ? void 0 : model.projectItem;
105
+ return (_a = entity === null || entity === void 0 ? void 0 : entity.roles) === null || _a === void 0 ? void 0 : _a.includes(propertyLevel);
106
+ });
107
+ const uniqueIds = new Set();
108
+ componentModels = componentModels.filter((model) => {
109
+ var _a, _b;
110
+ const id = entityType === 'item' ? (_a = model === null || model === void 0 ? void 0 : model.item) === null || _a === void 0 ? void 0 : _a.id : (_b = model === null || model === void 0 ? void 0 : model.projectItem) === null || _b === void 0 ? void 0 : _b.id;
111
+ if (!id || uniqueIds.has(id))
112
+ return false;
113
+ uniqueIds.add(id);
114
+ return true;
115
+ });
116
+ }
101
117
  componentModels.forEach((elementModel) => {
102
118
  frameMemberValues.push(util_1.ObjectUtil.getByPath(elementModel, bindingProperty));
103
119
  });
@@ -167,8 +183,8 @@ class DynamicTextUtil {
167
183
  }
168
184
  const formatter = new types_1.PropertyValueFormatter();
169
185
  if (displayFunction === DynamicTextDisplayFunction.AVERAGE) {
170
- memberValues = memberValues.filter(Number);
171
- text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0) / memberValues.length, property);
186
+ const memberNumValues = memberValues.filter(Number);
187
+ text = formatter.formatValueForProperty(memberNumValues.reduce((a, b) => a + b, 0) / memberValues.length, property);
172
188
  }
173
189
  else if (displayFunction === DynamicTextDisplayFunction.SUM) {
174
190
  memberValues = memberValues.filter(Number);
@@ -190,8 +206,13 @@ class DynamicTextUtil {
190
206
  text = formatter.formatValueForProperty(memberValues[memberValues.length - 1], property);
191
207
  }
192
208
  else if (displayFunction === DynamicTextDisplayFunction.MIN) {
193
- memberValues = memberValues.filter((e) => e !== null && e !== undefined);
194
- text = formatter.formatValueForProperty(Math.min(...memberValues), property);
209
+ const minValue = Math.min(...memberValues.filter((e) => e !== null && e !== undefined));
210
+ if (minValue > 0 && (memberValues.includes(null) || memberValues.includes(undefined))) {
211
+ text = '';
212
+ }
213
+ else {
214
+ text = formatter.formatValueForProperty(minValue, property);
215
+ }
195
216
  }
196
217
  else if (displayFunction === DynamicTextDisplayFunction.MAX) {
197
218
  memberValues = memberValues.filter((e) => e !== null && e !== undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.1.19",
3
+ "version": "1.1.20",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",