@reltio/components 1.4.2084 → 1.4.2085
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.
|
@@ -226,6 +226,47 @@ describe('dataHelpers', function () {
|
|
|
226
226
|
}
|
|
227
227
|
]);
|
|
228
228
|
});
|
|
229
|
+
it('should calculate correct rowspan if there are two or more columns having same nesting level', function () {
|
|
230
|
+
var rowValues = [
|
|
231
|
+
{
|
|
232
|
+
'n1.a.b': [[0], [1]],
|
|
233
|
+
'n1.x.y': [[2, 3], [4, 5], [6]],
|
|
234
|
+
'n1.x.y.z': [[[7], [8]], [[9], [10]], []]
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
var columnsData = [
|
|
238
|
+
{ id: 'n1.a.b', nestedPath: ['a'], label: 'columnA' },
|
|
239
|
+
{ id: 'n1.x.y', nestedPath: ['x'], label: 'columnB' },
|
|
240
|
+
{ id: 'n1.x.y.z', nestedPath: ['x', 'y'], label: 'columnC' }
|
|
241
|
+
];
|
|
242
|
+
var renderRowCell = function (_a) {
|
|
243
|
+
var cell = _a.cell;
|
|
244
|
+
return cell.values;
|
|
245
|
+
};
|
|
246
|
+
expect((0, dataHelpers_1.getTableRowsData)(rowValues, columnsData, renderRowCell)).toEqual([
|
|
247
|
+
{
|
|
248
|
+
data: {
|
|
249
|
+
'n1.a.b': [
|
|
250
|
+
{ values: [0], indexPath: [0], nestedKey: 'a.0', rowSpan: 2 },
|
|
251
|
+
{ values: [1], indexPath: [1], nestedKey: 'a.1', rowSpan: 3 }
|
|
252
|
+
],
|
|
253
|
+
'n1.x.y': [
|
|
254
|
+
{ values: [2, 3], indexPath: [0], nestedKey: 'x.0', rowSpan: 2 },
|
|
255
|
+
{ values: [4, 5], indexPath: [1], nestedKey: 'x.1', rowSpan: 2 },
|
|
256
|
+
{ values: [6], indexPath: [2], nestedKey: 'x.2', rowSpan: 1 }
|
|
257
|
+
],
|
|
258
|
+
'n1.x.y.z': [
|
|
259
|
+
{ values: [7], indexPath: [0, 0], nestedKey: 'x.0.y.0', rowSpan: 1 },
|
|
260
|
+
{ values: [8], indexPath: [0, 1], nestedKey: 'x.0.y.1', rowSpan: 1 },
|
|
261
|
+
{ values: [9], indexPath: [1, 0], nestedKey: 'x.1.y.0', rowSpan: 1 },
|
|
262
|
+
{ values: [10], indexPath: [1, 1], nestedKey: 'x.1.y.1', rowSpan: 1 },
|
|
263
|
+
{ values: [], indexPath: [2], nestedKey: 'x.2', rowSpan: 1 }
|
|
264
|
+
]
|
|
265
|
+
},
|
|
266
|
+
id: 0
|
|
267
|
+
}
|
|
268
|
+
]);
|
|
269
|
+
});
|
|
229
270
|
it('should apply max values count constraint if getRowMaxValuesCount is provided', function () {
|
|
230
271
|
var rowValues = [
|
|
231
272
|
{
|
|
@@ -30,6 +30,25 @@ exports.getSiblingSubRowsKeyBySubRowKey = getSiblingSubRowsKeyBySubRowKey;
|
|
|
30
30
|
var getParentRowKeyBySiblingsSubRowsKey = (0, ramda_1.pipe)((0, ramda_1.split)(NESTED_KEY_DELIMITER), (0, ramda_1.dropLast)(1), (0, ramda_1.join)(NESTED_KEY_DELIMITER), (0, ramda_1.unless)(ramda_1.length, (0, ramda_1.always)(TOTAL_ROW_SPAN_KEY)));
|
|
31
31
|
exports.getParentRowKeyBySiblingsSubRowsKey = getParentRowKeyBySiblingsSubRowsKey;
|
|
32
32
|
var getParentRowKeyBySubRowKey = (0, ramda_1.pipe)(getSiblingSubRowsKeyBySubRowKey, getParentRowKeyBySiblingsSubRowsKey);
|
|
33
|
+
var getSameNestingDepthNestedKeys = function (rowSpanData, keyToBeMatched) {
|
|
34
|
+
var parentKeyToBeMatched = getSiblingSubRowsKeyBySubRowKey(keyToBeMatched);
|
|
35
|
+
return Object.keys(rowSpanData).filter(function (currentKey) {
|
|
36
|
+
var currentParentKey = getParentRowKeyBySubRowKey(currentKey);
|
|
37
|
+
return (currentParentKey === parentKeyToBeMatched ||
|
|
38
|
+
(currentParentKey === TOTAL_ROW_SPAN_KEY && parentKeyToBeMatched === ''));
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var getRequiredRowSpan = function (rowSpanData, sameLevelNestedKeys, subRowKey, cellsWithExtraSpanAvailable) {
|
|
42
|
+
var subcellIndex = subRowKey.split(NESTED_KEY_DELIMITER).pop();
|
|
43
|
+
var minSpan = sameLevelNestedKeys
|
|
44
|
+
.filter(function (key) { return key.split(NESTED_KEY_DELIMITER).pop() === subcellIndex; })
|
|
45
|
+
.reduce(function (minSpan, key) {
|
|
46
|
+
return cellsWithExtraSpanAvailable.includes(getSiblingSubRowsKeyBySubRowKey(key))
|
|
47
|
+
? minSpan
|
|
48
|
+
: Math.min(minSpan, rowSpanData[key]);
|
|
49
|
+
}, Infinity);
|
|
50
|
+
return minSpan === Infinity ? rowSpanData[subRowKey] : Math.max(rowSpanData[subRowKey], minSpan);
|
|
51
|
+
};
|
|
33
52
|
var countParentSpanByAllSubRows = function (rowSpanData, siblingSubRowsKey) {
|
|
34
53
|
return (0, ramda_1.pipe)((0, ramda_1.pickBy)(function (_val, key) { return getSiblingSubRowsKeyBySubRowKey(key) === siblingSubRowsKey; }), ramda_1.values, ramda_1.sum)(rowSpanData);
|
|
35
54
|
};
|
|
@@ -49,23 +68,52 @@ var addNestedKey = function (rowSpanData, nestedKey) {
|
|
|
49
68
|
var _a;
|
|
50
69
|
return calcParentRowSpan(__assign(__assign({}, rowSpanData), (_a = {}, _a[nestedKey] = 1, _a)), nestedKey);
|
|
51
70
|
};
|
|
52
|
-
var
|
|
71
|
+
var validateRowSpans = function (rowSpanData) { return function (groups) {
|
|
72
|
+
var cellsWithExtraSpanAvailable = [];
|
|
73
|
+
for (var _i = 0, groups_1 = groups; _i < groups_1.length; _i++) {
|
|
74
|
+
var group = groups_1[_i];
|
|
75
|
+
var siblingSubRowsKey = group[0];
|
|
76
|
+
var parentKey = getParentRowKeyBySiblingsSubRowsKey(siblingSubRowsKey);
|
|
77
|
+
var currentParentSpan = (0, ramda_1.propOr)(0, parentKey, rowSpanData);
|
|
78
|
+
var actualParentSpan = countParentSpanByAllSubRows(rowSpanData, siblingSubRowsKey);
|
|
79
|
+
if (currentParentSpan > actualParentSpan) {
|
|
80
|
+
cellsWithExtraSpanAvailable.push(siblingSubRowsKey);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return groups.reduce(function (rowSpanData, group) { return validateParentRowSpan(rowSpanData, group, cellsWithExtraSpanAvailable); }, rowSpanData);
|
|
84
|
+
}; };
|
|
85
|
+
var validateParentRowSpan = function (rowSpanData, _a, cellsWithExtraSpanAvailable) {
|
|
53
86
|
var siblingSubRowsKey = _a[0], subRowsKeys = _a[1];
|
|
54
87
|
var parentKey = getParentRowKeyBySiblingsSubRowsKey(siblingSubRowsKey);
|
|
55
88
|
var currentParentSpan = (0, ramda_1.propOr)(0, parentKey, rowSpanData);
|
|
56
89
|
var actualParentSpan = countParentSpanByAllSubRows(rowSpanData, siblingSubRowsKey);
|
|
57
90
|
var spanDiff = currentParentSpan - actualParentSpan;
|
|
58
91
|
if (spanDiff > 0) {
|
|
92
|
+
var sameDepthNestedKeys_1 = getSameNestingDepthNestedKeys(rowSpanData, siblingSubRowsKey);
|
|
93
|
+
var sumOfRequiredRowSpans_1 = 0;
|
|
94
|
+
var correctedRowSpanData = subRowsKeys.reduce(function (acc, subRowKey) {
|
|
95
|
+
var requiredRowSpan = getRequiredRowSpan(rowSpanData, sameDepthNestedKeys_1, subRowKey, cellsWithExtraSpanAvailable);
|
|
96
|
+
acc[subRowKey] = requiredRowSpan;
|
|
97
|
+
sumOfRequiredRowSpans_1 += requiredRowSpan;
|
|
98
|
+
return acc;
|
|
99
|
+
}, {});
|
|
100
|
+
var newRowSpanData = __assign({}, rowSpanData);
|
|
101
|
+
if (currentParentSpan >= sumOfRequiredRowSpans_1) {
|
|
102
|
+
spanDiff = currentParentSpan - sumOfRequiredRowSpans_1;
|
|
103
|
+
newRowSpanData = __assign(__assign({}, rowSpanData), correctedRowSpanData);
|
|
104
|
+
if (spanDiff === 0)
|
|
105
|
+
return newRowSpanData;
|
|
106
|
+
}
|
|
59
107
|
var lowestSubRowKey = "".concat(siblingSubRowsKey).concat(NESTED_KEY_DELIMITER).concat(subRowsKeys.length - 1);
|
|
60
|
-
var lowestSubRowSpan =
|
|
61
|
-
return (0, ramda_1.assoc)(lowestSubRowKey, lowestSubRowSpan + spanDiff,
|
|
108
|
+
var lowestSubRowSpan = newRowSpanData[lowestSubRowKey];
|
|
109
|
+
return (0, ramda_1.assoc)(lowestSubRowKey, lowestSubRowSpan + spanDiff, newRowSpanData);
|
|
62
110
|
}
|
|
63
111
|
else {
|
|
64
112
|
return rowSpanData;
|
|
65
113
|
}
|
|
66
114
|
};
|
|
67
115
|
var validateRowSpanData = function (rowSpanData) {
|
|
68
|
-
return (0, ramda_1.pipe)((0, ramda_1.omit)([TOTAL_ROW_SPAN_KEY]), ramda_1.keys, (0, ramda_1.sortBy)(ramda_1.identity), (0, ramda_1.groupBy)(getSiblingSubRowsKeyBySubRowKey), ramda_1.toPairs, (
|
|
116
|
+
return (0, ramda_1.pipe)((0, ramda_1.omit)([TOTAL_ROW_SPAN_KEY]), ramda_1.keys, (0, ramda_1.sortBy)(ramda_1.identity), (0, ramda_1.groupBy)(getSiblingSubRowsKeyBySubRowKey), ramda_1.toPairs, validateRowSpans(rowSpanData))(rowSpanData);
|
|
69
117
|
};
|
|
70
118
|
exports.validateRowSpanData = validateRowSpanData;
|
|
71
119
|
var calcRowSpansForNestedKeys = (0, ramda_1.pipe)((0, ramda_1.sortBy)(ramda_1.identity), (0, ramda_1.reduce)(addNestedKey, {}), validateRowSpanData);
|
|
@@ -221,6 +221,47 @@ describe('dataHelpers', function () {
|
|
|
221
221
|
}
|
|
222
222
|
]);
|
|
223
223
|
});
|
|
224
|
+
it('should calculate correct rowspan if there are two or more columns having same nesting level', function () {
|
|
225
|
+
var rowValues = [
|
|
226
|
+
{
|
|
227
|
+
'n1.a.b': [[0], [1]],
|
|
228
|
+
'n1.x.y': [[2, 3], [4, 5], [6]],
|
|
229
|
+
'n1.x.y.z': [[[7], [8]], [[9], [10]], []]
|
|
230
|
+
}
|
|
231
|
+
];
|
|
232
|
+
var columnsData = [
|
|
233
|
+
{ id: 'n1.a.b', nestedPath: ['a'], label: 'columnA' },
|
|
234
|
+
{ id: 'n1.x.y', nestedPath: ['x'], label: 'columnB' },
|
|
235
|
+
{ id: 'n1.x.y.z', nestedPath: ['x', 'y'], label: 'columnC' }
|
|
236
|
+
];
|
|
237
|
+
var renderRowCell = function (_a) {
|
|
238
|
+
var cell = _a.cell;
|
|
239
|
+
return cell.values;
|
|
240
|
+
};
|
|
241
|
+
expect(getTableRowsData(rowValues, columnsData, renderRowCell)).toEqual([
|
|
242
|
+
{
|
|
243
|
+
data: {
|
|
244
|
+
'n1.a.b': [
|
|
245
|
+
{ values: [0], indexPath: [0], nestedKey: 'a.0', rowSpan: 2 },
|
|
246
|
+
{ values: [1], indexPath: [1], nestedKey: 'a.1', rowSpan: 3 }
|
|
247
|
+
],
|
|
248
|
+
'n1.x.y': [
|
|
249
|
+
{ values: [2, 3], indexPath: [0], nestedKey: 'x.0', rowSpan: 2 },
|
|
250
|
+
{ values: [4, 5], indexPath: [1], nestedKey: 'x.1', rowSpan: 2 },
|
|
251
|
+
{ values: [6], indexPath: [2], nestedKey: 'x.2', rowSpan: 1 }
|
|
252
|
+
],
|
|
253
|
+
'n1.x.y.z': [
|
|
254
|
+
{ values: [7], indexPath: [0, 0], nestedKey: 'x.0.y.0', rowSpan: 1 },
|
|
255
|
+
{ values: [8], indexPath: [0, 1], nestedKey: 'x.0.y.1', rowSpan: 1 },
|
|
256
|
+
{ values: [9], indexPath: [1, 0], nestedKey: 'x.1.y.0', rowSpan: 1 },
|
|
257
|
+
{ values: [10], indexPath: [1, 1], nestedKey: 'x.1.y.1', rowSpan: 1 },
|
|
258
|
+
{ values: [], indexPath: [2], nestedKey: 'x.2', rowSpan: 1 }
|
|
259
|
+
]
|
|
260
|
+
},
|
|
261
|
+
id: 0
|
|
262
|
+
}
|
|
263
|
+
]);
|
|
264
|
+
});
|
|
224
265
|
it('should apply max values count constraint if getRowMaxValuesCount is provided', function () {
|
|
225
266
|
var rowValues = [
|
|
226
267
|
{
|
|
@@ -24,6 +24,25 @@ var NESTED_KEY_DELIMITER = '.';
|
|
|
24
24
|
var getSiblingSubRowsKeyBySubRowKey = pipe(split(NESTED_KEY_DELIMITER), dropLast(1), join(NESTED_KEY_DELIMITER));
|
|
25
25
|
var getParentRowKeyBySiblingsSubRowsKey = pipe(split(NESTED_KEY_DELIMITER), dropLast(1), join(NESTED_KEY_DELIMITER), unless(length, always(TOTAL_ROW_SPAN_KEY)));
|
|
26
26
|
var getParentRowKeyBySubRowKey = pipe(getSiblingSubRowsKeyBySubRowKey, getParentRowKeyBySiblingsSubRowsKey);
|
|
27
|
+
var getSameNestingDepthNestedKeys = function (rowSpanData, keyToBeMatched) {
|
|
28
|
+
var parentKeyToBeMatched = getSiblingSubRowsKeyBySubRowKey(keyToBeMatched);
|
|
29
|
+
return Object.keys(rowSpanData).filter(function (currentKey) {
|
|
30
|
+
var currentParentKey = getParentRowKeyBySubRowKey(currentKey);
|
|
31
|
+
return (currentParentKey === parentKeyToBeMatched ||
|
|
32
|
+
(currentParentKey === TOTAL_ROW_SPAN_KEY && parentKeyToBeMatched === ''));
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var getRequiredRowSpan = function (rowSpanData, sameLevelNestedKeys, subRowKey, cellsWithExtraSpanAvailable) {
|
|
36
|
+
var subcellIndex = subRowKey.split(NESTED_KEY_DELIMITER).pop();
|
|
37
|
+
var minSpan = sameLevelNestedKeys
|
|
38
|
+
.filter(function (key) { return key.split(NESTED_KEY_DELIMITER).pop() === subcellIndex; })
|
|
39
|
+
.reduce(function (minSpan, key) {
|
|
40
|
+
return cellsWithExtraSpanAvailable.includes(getSiblingSubRowsKeyBySubRowKey(key))
|
|
41
|
+
? minSpan
|
|
42
|
+
: Math.min(minSpan, rowSpanData[key]);
|
|
43
|
+
}, Infinity);
|
|
44
|
+
return minSpan === Infinity ? rowSpanData[subRowKey] : Math.max(rowSpanData[subRowKey], minSpan);
|
|
45
|
+
};
|
|
27
46
|
var countParentSpanByAllSubRows = function (rowSpanData, siblingSubRowsKey) {
|
|
28
47
|
return pipe(pickBy(function (_val, key) { return getSiblingSubRowsKeyBySubRowKey(key) === siblingSubRowsKey; }), values, sum)(rowSpanData);
|
|
29
48
|
};
|
|
@@ -43,23 +62,52 @@ var addNestedKey = function (rowSpanData, nestedKey) {
|
|
|
43
62
|
var _a;
|
|
44
63
|
return calcParentRowSpan(__assign(__assign({}, rowSpanData), (_a = {}, _a[nestedKey] = 1, _a)), nestedKey);
|
|
45
64
|
};
|
|
46
|
-
var
|
|
65
|
+
var validateRowSpans = function (rowSpanData) { return function (groups) {
|
|
66
|
+
var cellsWithExtraSpanAvailable = [];
|
|
67
|
+
for (var _i = 0, groups_1 = groups; _i < groups_1.length; _i++) {
|
|
68
|
+
var group = groups_1[_i];
|
|
69
|
+
var siblingSubRowsKey = group[0];
|
|
70
|
+
var parentKey = getParentRowKeyBySiblingsSubRowsKey(siblingSubRowsKey);
|
|
71
|
+
var currentParentSpan = propOr(0, parentKey, rowSpanData);
|
|
72
|
+
var actualParentSpan = countParentSpanByAllSubRows(rowSpanData, siblingSubRowsKey);
|
|
73
|
+
if (currentParentSpan > actualParentSpan) {
|
|
74
|
+
cellsWithExtraSpanAvailable.push(siblingSubRowsKey);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return groups.reduce(function (rowSpanData, group) { return validateParentRowSpan(rowSpanData, group, cellsWithExtraSpanAvailable); }, rowSpanData);
|
|
78
|
+
}; };
|
|
79
|
+
var validateParentRowSpan = function (rowSpanData, _a, cellsWithExtraSpanAvailable) {
|
|
47
80
|
var siblingSubRowsKey = _a[0], subRowsKeys = _a[1];
|
|
48
81
|
var parentKey = getParentRowKeyBySiblingsSubRowsKey(siblingSubRowsKey);
|
|
49
82
|
var currentParentSpan = propOr(0, parentKey, rowSpanData);
|
|
50
83
|
var actualParentSpan = countParentSpanByAllSubRows(rowSpanData, siblingSubRowsKey);
|
|
51
84
|
var spanDiff = currentParentSpan - actualParentSpan;
|
|
52
85
|
if (spanDiff > 0) {
|
|
86
|
+
var sameDepthNestedKeys_1 = getSameNestingDepthNestedKeys(rowSpanData, siblingSubRowsKey);
|
|
87
|
+
var sumOfRequiredRowSpans_1 = 0;
|
|
88
|
+
var correctedRowSpanData = subRowsKeys.reduce(function (acc, subRowKey) {
|
|
89
|
+
var requiredRowSpan = getRequiredRowSpan(rowSpanData, sameDepthNestedKeys_1, subRowKey, cellsWithExtraSpanAvailable);
|
|
90
|
+
acc[subRowKey] = requiredRowSpan;
|
|
91
|
+
sumOfRequiredRowSpans_1 += requiredRowSpan;
|
|
92
|
+
return acc;
|
|
93
|
+
}, {});
|
|
94
|
+
var newRowSpanData = __assign({}, rowSpanData);
|
|
95
|
+
if (currentParentSpan >= sumOfRequiredRowSpans_1) {
|
|
96
|
+
spanDiff = currentParentSpan - sumOfRequiredRowSpans_1;
|
|
97
|
+
newRowSpanData = __assign(__assign({}, rowSpanData), correctedRowSpanData);
|
|
98
|
+
if (spanDiff === 0)
|
|
99
|
+
return newRowSpanData;
|
|
100
|
+
}
|
|
53
101
|
var lowestSubRowKey = "".concat(siblingSubRowsKey).concat(NESTED_KEY_DELIMITER).concat(subRowsKeys.length - 1);
|
|
54
|
-
var lowestSubRowSpan =
|
|
55
|
-
return assoc(lowestSubRowKey, lowestSubRowSpan + spanDiff,
|
|
102
|
+
var lowestSubRowSpan = newRowSpanData[lowestSubRowKey];
|
|
103
|
+
return assoc(lowestSubRowKey, lowestSubRowSpan + spanDiff, newRowSpanData);
|
|
56
104
|
}
|
|
57
105
|
else {
|
|
58
106
|
return rowSpanData;
|
|
59
107
|
}
|
|
60
108
|
};
|
|
61
109
|
var validateRowSpanData = function (rowSpanData) {
|
|
62
|
-
return pipe(omit([TOTAL_ROW_SPAN_KEY]), keys, sortBy(identity), groupBy(getSiblingSubRowsKeyBySubRowKey), toPairs,
|
|
110
|
+
return pipe(omit([TOTAL_ROW_SPAN_KEY]), keys, sortBy(identity), groupBy(getSiblingSubRowsKeyBySubRowKey), toPairs, validateRowSpans(rowSpanData))(rowSpanData);
|
|
63
111
|
};
|
|
64
112
|
var calcRowSpansForNestedKeys = pipe(sortBy(identity), reduce(addNestedKey, {}), validateRowSpanData);
|
|
65
113
|
var chainWithIndex = addIndex(chain);
|