@refinitiv-ui/efx-grid 6.0.146 → 6.0.148

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.
@@ -58,7 +58,7 @@ declare class SegmentCollection extends EventDispatcher {
58
58
 
59
59
  public fillSegments(rids: (string)[]|null): boolean;
60
60
 
61
- public calcSegmentOrder(rids: (string)[]|null): void;
61
+ public calcSegmentOrder(rids: (string)[]|null, useCache?: boolean|null): void;
62
62
 
63
63
  public logStructure(): string;
64
64
 
@@ -14,6 +14,7 @@ let SegmentCollection = function() {
14
14
  this._removalList = [];
15
15
 
16
16
  this._shared = {
17
+ segments: this._segments,
17
18
  childToSegment: {}, // child Id to segment Id
18
19
  dirtyCollapsingState: false,
19
20
  defaultCollapsing: false
@@ -74,10 +75,6 @@ SegmentCollection.prototype.dispose = function() {
74
75
  */
75
76
  SegmentCollection.prototype.addSegment = function(rid, childRids) {
76
77
  if(rid && !this._segments[rid]) {
77
- if(this.getParentRowId(rid)) {
78
- console.log("child of a segment cannot be set as a segment separator");
79
- return false;
80
- }
81
78
  let segment = this._segments[rid] = new Segment(rid, this._shared);
82
79
  segment.addEventListener("subSegmentAdded", this._onSubSegmentAdded);
83
80
  segment.addEventListener("subSegmentRemoved", this._onSubSegmentRemoved);
@@ -124,33 +121,41 @@ SegmentCollection.prototype.getParentRowId = function(rid) {
124
121
  */
125
122
  SegmentCollection.prototype.removeSegment = function(rid) {
126
123
  let segment = this._segments[rid];
127
- if(segment) {
128
- if(this._segmentCount <= 1) {
129
- return this.removeAllSegments();
130
- }
131
- if(segment.isSubSegment()) {
132
- this._removalList.push(segment.getId());
133
- }
134
- let subSegIds = segment.getSubSegmentIds();
135
- if(subSegIds) {
136
- let len = subSegIds.length;
137
- for(let i = 0; i < len; ++i) {
138
- let subSegId = subSegIds[i];
139
- if(this._segments[subSegId]) {
140
- this._removalList.push(subSegId);
141
- delete this._segments[subSegId]; // Slow
142
- --this._segmentCount;
143
- }
124
+ if(!segment) {
125
+ return false;
126
+ }
127
+
128
+ if(this._segmentCount <= 1) {
129
+ return this.removeAllSegments();
130
+ }
131
+ let subSegment = segment.isSubSegment();
132
+ if(subSegment) {
133
+ this._removalList.push(segment.getId());
134
+ }
135
+ let subSegIds = segment.getSubSegmentIds();
136
+ if(subSegIds) {
137
+ let len = subSegIds.length;
138
+ for(let i = 0; i < len; ++i) {
139
+ let subSegId = subSegIds[i];
140
+ if(this._segments[subSegId]) {
141
+ this._removalList.push(subSegId);
142
+ delete this._segments[subSegId]; // Slow
143
+ --this._segmentCount;
144
144
  }
145
145
  }
146
- segment.removeAllChildren(); // This is important for updating childToSegment
147
- segment.dispose();
148
-
149
- delete this._segments[rid]; // Slow
150
- --this._segmentCount;
151
- return true;
152
146
  }
153
- return false;
147
+ if(!subSegment) {
148
+ let parentSeg = segment.getParent();
149
+ if(parentSeg) { // Move existing children to its parent
150
+ parentSeg.addChildren(segment.getChildIds()); // WARNING: passing private member
151
+ }
152
+ }
153
+ segment.removeAllChildren(); // This is important for updating childToSegment
154
+ segment.dispose();
155
+
156
+ delete this._segments[rid]; // Slow
157
+ --this._segmentCount;
158
+ return true;
154
159
  };
155
160
  /** @public
156
161
  * @return {boolean} Returns true if there is any change. Otherwise, returns false
@@ -163,6 +168,7 @@ SegmentCollection.prototype.removeAllSegments = function() {
163
168
  this._segments = {};
164
169
  this._segmentCount = 0;
165
170
  this._segmentList = null;
171
+ this._shared.segments = this._segments;
166
172
  this._shared.childToSegment = {};
167
173
 
168
174
  this._classification = this._classifierChanged = false;
@@ -288,7 +294,7 @@ SegmentCollection.prototype.getCollapsedRows = function() {
288
294
  collapsedRids = {};
289
295
  for(let rid in segmentSeparators) {
290
296
  let segment = segmentSeparators[rid];
291
- if(!segment.isSubSegment()) {
297
+ if(segment.isRootSegment()) {
292
298
  if(segment.getCollapsingStates(collapsedRids)) {
293
299
  ++count;
294
300
  }
@@ -300,6 +306,31 @@ SegmentCollection.prototype.getCollapsedRows = function() {
300
306
  return this._collapsedRids;
301
307
  };
302
308
 
309
+ /** Invalidate segment order cache, if the given row id is a segment separator
310
+ * @private
311
+ * @param {string|Array.<string>} segmentIds
312
+ * @returns {boolean} Returns true if there is any change
313
+ */
314
+ SegmentCollection.prototype._invalidateSegmentOrder = function(segmentIds) {
315
+ if(this._segmentList) {
316
+ if(typeof segmentIds === "string") {
317
+ if(this._segments[segmentIds]) {
318
+ this._segmentList = null;
319
+ return true;
320
+ }
321
+ } else if(Array.isArray(segmentIds)) {
322
+ let len = segmentIds.length;
323
+ for(let i = 0; i < len; ++i) {
324
+ let segmentId = segmentIds[i];
325
+ if(this._segments[segmentId]) {
326
+ this._segmentList = null;
327
+ return true;
328
+ }
329
+ }
330
+ }
331
+ }
332
+ return false;
333
+ };
303
334
  /** @public
304
335
  * @param {string} segmentId
305
336
  * @param {string} rid
@@ -309,6 +340,8 @@ SegmentCollection.prototype.getCollapsedRows = function() {
309
340
  SegmentCollection.prototype.addSegmentChild = function(segmentId, rid, dataId) {
310
341
  let segment = this._segments[segmentId];
311
342
  if(segment && !segment.isSubSegment()) {
343
+ // If a segment becomes a child of other segment, then the segment order needs to be recalculated
344
+ this._invalidateSegmentOrder(rid);
312
345
  return segment.addChild(rid, dataId);
313
346
  }
314
347
  return false;
@@ -322,11 +355,14 @@ SegmentCollection.prototype.addSegmentChild = function(segmentId, rid, dataId) {
322
355
  SegmentCollection.prototype.addSegmentChildren = function(segmentId, rids, dataIds) {
323
356
  let segment = this._segments[segmentId];
324
357
  if(segment && !segment.isSubSegment()) {
358
+ // If a segment becomes a child of other segment, then the segment order needs to be recalculated
359
+ this._invalidateSegmentOrder(rids);
325
360
  return segment.addChildren(rids, dataIds);
326
361
  }
327
362
  return false;
328
363
  };
329
- /** @public
364
+ /** This only works for immediate children of the specified segment
365
+ * @public
330
366
  * @param {string} segmentId
331
367
  * @param {string} rid
332
368
  * @return {boolean} Returns true if there is any change. Otherwise, returns false
@@ -346,6 +382,7 @@ SegmentCollection.prototype.containsSegmentChild = function(segmentId, rid) {
346
382
  SegmentCollection.prototype.removeSegmentChild = function(segmentId, rid) {
347
383
  let segment = this._segments[segmentId];
348
384
  if(segment) {
385
+ this._invalidateSegmentOrder(rid);
349
386
  return segment.removeChild(rid);
350
387
  }
351
388
  return false;
@@ -358,6 +395,7 @@ SegmentCollection.prototype.removeSegmentChild = function(segmentId, rid) {
358
395
  SegmentCollection.prototype.removeSegmentChildren = function(segmentId, rids) {
359
396
  let segment = this._segments[segmentId];
360
397
  if(segment) {
398
+ this._invalidateSegmentOrder(rids);
361
399
  return segment.removeChildren(rids);
362
400
  }
363
401
  return false;
@@ -377,6 +415,7 @@ SegmentCollection.prototype.removeAllSegmentChildren = function() {
377
415
  }
378
416
 
379
417
  if(dirty) {
418
+ this._segmentList = null; // WARNING: not optimized
380
419
  this.classify(null);
381
420
  }
382
421
 
@@ -435,10 +474,14 @@ SegmentCollection.prototype.fillSegments = function(rids) {
435
474
  };
436
475
  /** @public
437
476
  * @param {Array.<string>} rids
477
+ * @param {boolean=} useCache=false If this is true, skip the calculation when there is already a cache for segment order
438
478
  */
439
- SegmentCollection.prototype.calcSegmentOrder = function(rids) {
479
+ SegmentCollection.prototype.calcSegmentOrder = function(rids, useCache) {
440
480
  let segmentList = this._segmentList;
441
481
  if(segmentList) {
482
+ if(useCache) {
483
+ return; // Use previous cache for segment order
484
+ }
442
485
  segmentList.length = 0;
443
486
  } else {
444
487
  segmentList = this._segmentList = [];
@@ -452,9 +495,10 @@ SegmentCollection.prototype.calcSegmentOrder = function(rids) {
452
495
  let rid = rids[i];
453
496
  let segment = segmentSeparators[rid];
454
497
  if(segment) {
455
- if(!segment.isSubSegment()) {
498
+ if(segment.isRootSegment()) {
456
499
  this._segmentList.push(segment);
457
500
  segment.setOrder(++order); // WARNING: Segments and sub segments start with 1
501
+ segment.updateTreeStructure(0);
458
502
  }
459
503
  if(--segmentCount <= 0) {
460
504
  break;
@@ -478,7 +522,7 @@ SegmentCollection.prototype.getSegmentValues = function(rids, partial) {
478
522
  let prevSegment = null;
479
523
  let segmentValues = new Array(rowCount);
480
524
  let segmentVal = 0;
481
- let highestVal = -10;
525
+ let highestVal = 0;
482
526
  let offset = 0;
483
527
  for(let r = 0; r < rowCount; ++r) {
484
528
  let rid = rids[r];
@@ -486,7 +530,7 @@ SegmentCollection.prototype.getSegmentValues = function(rids, partial) {
486
530
  if(curSegment) { // segment separator
487
531
  segmentVal = curSegment.getOrder() * 100;
488
532
  offset = 0;
489
- if(!curSegment.isSubSegment()) {
533
+ if(curSegment.isRootSegment()) {
490
534
  if(prevSegment !== curSegment) {
491
535
  prevSegment = curSegment;
492
536
  highestVal = curSegment.getLastOrder() * 100;
@@ -498,12 +542,14 @@ SegmentCollection.prototype.getSegmentValues = function(rids, partial) {
498
542
  curSegment = segmentSeparators[parentId];
499
543
  segmentVal = curSegment.getOrder() * 100;
500
544
  offset = 1;
501
- if(partial) {
545
+ if(partial) { // This fixes the out of order sub segment
502
546
  highestVal = curSegment.getLastOrder() * 100;
503
547
  }
504
548
  } else { // row outside of segments
505
549
  if(highestVal) {
506
- segmentVal = highestVal;
550
+ if(segmentVal < highestVal) {
551
+ segmentVal = highestVal;
552
+ }
507
553
  offset = 10;
508
554
  } else {
509
555
  segmentVal = offset = 0;
@@ -527,7 +573,10 @@ SegmentCollection.prototype.logStructure = function() {
527
573
  let segmentCount = segmentList.length;
528
574
  let lines = [];
529
575
  for(let i = 0; i < segmentCount; ++i) {
530
- segmentList[i].log(lines);
576
+ let segment = segmentList[i];
577
+ if(segment.isRootSegment()) {
578
+ segment.log(lines);
579
+ }
531
580
  }
532
581
 
533
582
  return lines.join("\n");
@@ -537,10 +586,14 @@ SegmentCollection.prototype.logStructure = function() {
537
586
  */
538
587
  SegmentCollection.prototype.logRowIdMap = function() {
539
588
  let lines = [];
589
+ let segmentSeparators = this._segments;
540
590
  let childToSegmentId = this._shared.childToSegment;
541
591
  for(let rid in childToSegmentId) {
542
592
  let segmentId = childToSegmentId[rid];
543
- lines.push(rid + " > " + segmentId);
593
+ let segment = segmentSeparators[segmentId];
594
+ if(!segment || !segment.isSubSegment()) {
595
+ lines.push(rid + " > " + segmentId);
596
+ }
544
597
  }
545
598
 
546
599
  return lines.join("\n");
@@ -622,7 +622,7 @@ Core.prototype._hasPendingRowChange = false;
622
622
  * @return {string}
623
623
  */
624
624
  Core.getVersion = function () {
625
- return "5.1.137";
625
+ return "5.1.139";
626
626
  };
627
627
  /** {@link ElementWrapper#dispose}
628
628
  * @override
package/lib/grid/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import {Grid} from "./lib/efx-grid.js";
2
2
  export {Grid}
3
- window.EFX_GRID = { version: "6.0.146" };
3
+ window.EFX_GRID = { version: "6.0.148" };
@@ -82,7 +82,7 @@ declare class DataTable extends DataCache {
82
82
 
83
83
  public setSegmentSeparators(rids: (string)[]|null, enabled?: boolean|null): boolean;
84
84
 
85
- public setSegmentSeparator(rid: string, enabled?: boolean|null): boolean;
85
+ public setSegmentSeparator(rid: string, options?: any): boolean;
86
86
 
87
87
  public unsetAllSegmentSeparators(): boolean;
88
88
 
@@ -248,7 +248,7 @@ declare class DataView extends EventDispatcher {
248
248
 
249
249
  public setSegmentSeparators(rowIds: (string)[]|null, enabled?: boolean|null): boolean;
250
250
 
251
- public setSegmentSeparator(rowRef: string|number|null, enabled?: boolean|null): boolean;
251
+ public setSegmentSeparator(rowRef: string|number|null, options?: any): boolean;
252
252
 
253
253
  public unsetAllSegmentSeparators(): boolean;
254
254
 
@@ -11,6 +11,8 @@ declare class Segment extends EventDispatcher {
11
11
 
12
12
  public getParentId(): string;
13
13
 
14
+ public getParent(): Segment|null;
15
+
14
16
  public getSubSegmentIds(out_ary?: (string)[]|null): (string)[]|null;
15
17
 
16
18
  public addChild(rid: string, dataId?: string|null): boolean;
@@ -19,6 +21,8 @@ declare class Segment extends EventDispatcher {
19
21
 
20
22
  public containsChild(rid: string): boolean;
21
23
 
24
+ public getChildIndex(rid: string): number;
25
+
22
26
  public removeChild(rid: string): boolean;
23
27
 
24
28
  public removeChildren(rids: (string)[]|null): boolean;
@@ -31,6 +35,8 @@ declare class Segment extends EventDispatcher {
31
35
 
32
36
  public getChildCount(): number;
33
37
 
38
+ public markCollapsingStateDirty(): void;
39
+
34
40
  public getClassification(): (string)[]|null;
35
41
 
36
42
  public setClassification(fields: string|(string)[]|null): boolean;
@@ -41,10 +47,16 @@ declare class Segment extends EventDispatcher {
41
47
 
42
48
  public isSubSegment(): boolean;
43
49
 
50
+ public isRootSegment(): boolean;
51
+
44
52
  public getFirstAncestor(): Segment|null;
45
53
 
46
54
  public getAllSubSegments(out_ary?: (Segment)[]|null): (Segment)[]|null;
47
55
 
56
+ public updateTreeStructure(counter: number): number;
57
+
58
+ public calcSubSegmentOrder(counter: number): number;
59
+
48
60
  public getSegmentLevel(): number;
49
61
 
50
62
  public setRowData(rows?: any, clsSource?: any): void;
@@ -65,7 +77,9 @@ declare class Segment extends EventDispatcher {
65
77
 
66
78
  public setOrder(val: number): void;
67
79
 
68
- public log(lines?: (string)[]|null): (string)[];
80
+ public setLastOrder(val: number): number;
81
+
82
+ public log(lines?: (string)[]|null, tabLevel?: number|null): (string)[];
69
83
 
70
84
  }
71
85
 
@@ -58,7 +58,7 @@ declare class SegmentCollection extends EventDispatcher {
58
58
 
59
59
  public fillSegments(rids: (string)[]|null): boolean;
60
60
 
61
- public calcSegmentOrder(rids: (string)[]|null): void;
61
+ public calcSegmentOrder(rids: (string)[]|null, useCache?: boolean|null): void;
62
62
 
63
63
  public logStructure(): string;
64
64
 
package/package.json CHANGED
@@ -69,5 +69,5 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
- "version": "6.0.146"
72
+ "version": "6.0.148"
73
73
  }