@contrail/documents 2.4.0-alpha.d86842b → 2.4.0-alpha.e27d364

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/CHANGELOG.md CHANGED
@@ -64,6 +64,12 @@ Also shipped on the 1.x line as 1.21.0.
64
64
  `n/a`. `calculateSize` no longer throws on an element that reaches it without a `size`, which on
65
65
  the server failed the read for the whole document.
66
66
 
67
+ - `min` and `max` over a date property rendered nothing at all. `Number` of a date string is `NaN`,
68
+ so every member was dropped; they now order by the instant each date names.
69
+ - `uniqueArray` sorted the rendered text rather than the value, so `11/20/2026` came after
70
+ `01/15/2027` and `100` before `9`. It now orders by value, falling back to text order for values
71
+ that are neither a date nor a number.
72
+
67
73
  ### Changed
68
74
 
69
75
  - `anchorFor` and the index measure through the same factory call, so a caller holding an element
@@ -60,6 +60,7 @@ export declare class DynamicTextUtil {
60
60
  width: number;
61
61
  height: number;
62
62
  };
63
+ private static rankValue;
63
64
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
64
65
  private static getItemCount;
65
66
  }
@@ -210,6 +210,9 @@ class DynamicTextUtil {
210
210
  catch (e) { }
211
211
  return size;
212
212
  }
213
+ static rankValue(value, property) {
214
+ return (property === null || property === void 0 ? void 0 : property.propertyType) === types_1.PropertyType.Date ? Date.parse(value) : Number(value);
215
+ }
213
216
  static getTextFromFrameMemberValues(displayFunction, property, memberValues) {
214
217
  let text = '';
215
218
  if (memberValues.length === 0) {
@@ -225,11 +228,16 @@ class DynamicTextUtil {
225
228
  text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0), property);
226
229
  }
227
230
  else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
228
- text = Array.from(new Set(memberValues
229
- .filter((e) => e !== null && e !== undefined && e !== '')
230
- .flat()
231
- .map((e) => formatter.formatValueForProperty(e, property))))
232
- .sort()
231
+ const byValue = new Map();
232
+ for (const value of memberValues.filter((e) => e !== null && e !== undefined && e !== '').flat()) {
233
+ const formatted = formatter.formatValueForProperty(value, property);
234
+ if (!byValue.has(formatted)) {
235
+ byValue.set(formatted, DynamicTextUtil.rankValue(value, property));
236
+ }
237
+ }
238
+ text = Array.from(byValue)
239
+ .sort(([leftText, leftRank], [rightText, rightRank]) => Number.isNaN(leftRank) || Number.isNaN(rightRank) ? leftText.localeCompare(rightText) : leftRank - rightRank)
240
+ .map(([formatted]) => formatted)
233
241
  .join(', ');
234
242
  }
235
243
  else if (!displayFunction ||
@@ -241,15 +249,17 @@ class DynamicTextUtil {
241
249
  }
242
250
  else if (displayFunction === DynamicTextDisplayFunction.MIN ||
243
251
  displayFunction === DynamicTextDisplayFunction.MAX) {
244
- const present = memberValues
252
+ const isDate = (property === null || property === void 0 ? void 0 : property.propertyType) === types_1.PropertyType.Date;
253
+ const ranked = memberValues
245
254
  .filter((e) => e !== null && e !== undefined && e !== '')
246
- .map(Number)
247
- .filter((e) => !Number.isNaN(e));
248
- if (!present.length) {
255
+ .map((value) => ({ value, rank: DynamicTextUtil.rankValue(value, property) }))
256
+ .filter(({ rank }) => !Number.isNaN(rank));
257
+ if (!ranked.length) {
249
258
  return '';
250
259
  }
251
- const extreme = displayFunction === DynamicTextDisplayFunction.MIN ? Math.min(...present) : Math.max(...present);
252
- text = formatter.formatValueForProperty(extreme, property);
260
+ const wantsLower = displayFunction === DynamicTextDisplayFunction.MIN;
261
+ const extreme = ranked.reduce((best, candidate) => (wantsLower ? candidate.rank < best.rank : candidate.rank > best.rank) ? candidate : best);
262
+ text = formatter.formatValueForProperty(isDate ? extreme.value : extreme.rank, property);
253
263
  }
254
264
  return text;
255
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.d86842b",
3
+ "version": "2.4.0-alpha.e27d364",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",