@reltio/components 1.4.2080 → 1.4.2082
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/BasicTable/BasicTable.js +3 -2
- package/cjs/BasicTable/BasicTable.js +3 -2
- package/cjs/helpers/data/tableCompactCollapseHelper.data.d.ts +491 -0
- package/cjs/helpers/data/tableCompactCollapseHelper.data.js +1641 -0
- package/cjs/helpers/tableCompactCollapseHelpers.d.ts +4 -0
- package/cjs/helpers/tableCompactCollapseHelpers.js +187 -0
- package/cjs/helpers/tableCompactCollapseHelpers.test.d.ts +1 -0
- package/cjs/helpers/tableCompactCollapseHelpers.test.js +27 -0
- package/cjs/hooks/useBasicTableCellRenderer/useBasicTableCellRenderer.d.ts +3 -2
- package/cjs/hooks/useBasicTableCellRenderer/useBasicTableCellRenderer.js +3 -2
- package/cjs/hooks/useCollapsibleTableRows/dataHelpers.d.ts +2 -1
- package/cjs/hooks/useCollapsibleTableRows/dataHelpers.js +16 -7
- package/cjs/hooks/useCollapsibleTableRows/dataHelpers.test.js +6 -6
- package/cjs/hooks/useCollapsibleTableRows/useCollapsibleTableRows.d.ts +3 -2
- package/cjs/hooks/useCollapsibleTableRows/useCollapsibleTableRows.js +13 -5
- package/cjs/hooks/useCollapsibleTableRows/useCollapsibleTableRows.test.js +3 -4
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +3 -1
- package/helpers/data/tableCompactCollapseHelper.data.d.ts +491 -0
- package/helpers/data/tableCompactCollapseHelper.data.js +1633 -0
- package/helpers/tableCompactCollapseHelpers.d.ts +4 -0
- package/helpers/tableCompactCollapseHelpers.js +183 -0
- package/helpers/tableCompactCollapseHelpers.test.d.ts +1 -0
- package/helpers/tableCompactCollapseHelpers.test.js +25 -0
- package/hooks/useBasicTableCellRenderer/useBasicTableCellRenderer.d.ts +3 -2
- package/hooks/useBasicTableCellRenderer/useBasicTableCellRenderer.js +3 -2
- package/hooks/useCollapsibleTableRows/dataHelpers.d.ts +2 -1
- package/hooks/useCollapsibleTableRows/dataHelpers.js +16 -8
- package/hooks/useCollapsibleTableRows/dataHelpers.test.js +6 -6
- package/hooks/useCollapsibleTableRows/useCollapsibleTableRows.d.ts +3 -2
- package/hooks/useCollapsibleTableRows/useCollapsibleTableRows.js +14 -6
- package/hooks/useCollapsibleTableRows/useCollapsibleTableRows.test.js +3 -4
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RowValue } from '../types/basicTable';
|
|
2
|
+
declare const applyCompactValuesCountConstraint: (maxValuesCount: number) => (rowValue: RowValue) => RowValue;
|
|
3
|
+
declare const getHasHiddenAttributes: any;
|
|
4
|
+
export { applyCompactValuesCountConstraint, getHasHiddenAttributes };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { adjust, assoc, difference, identity, __, gt, length, pathOr, chain, pipe, values } from 'ramda';
|
|
24
|
+
var INDEX_PATH_SEPARATOR = ',';
|
|
25
|
+
var indexPathToStringKey = function (indexPath) { return indexPath === null || indexPath === void 0 ? void 0 : indexPath.join(INDEX_PATH_SEPARATOR); };
|
|
26
|
+
var stringKeyToIndexPath = function (stringKey) { return stringKey.split(INDEX_PATH_SEPARATOR).map(Number); };
|
|
27
|
+
var isIndexPathSmaller = function (maxIndexPath, indexPath) {
|
|
28
|
+
if (!indexPath || !maxIndexPath) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
var minLength = Math.min(maxIndexPath.length, indexPath.length);
|
|
32
|
+
for (var i = 0; i < minLength; i++) {
|
|
33
|
+
if (indexPath[i] < maxIndexPath[i]) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
else if (indexPath[i] > maxIndexPath[i]) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return indexPath.length < maxIndexPath.length;
|
|
41
|
+
};
|
|
42
|
+
var isIndexPathOnSameLevel = function (maxIndexPath, indexPath) {
|
|
43
|
+
if (!indexPath || !maxIndexPath) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
var maxIndexPathLength = maxIndexPath.length;
|
|
47
|
+
var isEqual = maxIndexPath.length === indexPath.length && maxIndexPath.every(function (value, index) { return value === indexPath[index]; });
|
|
48
|
+
var isLeftEqual = maxIndexPath.every(function (value, index) { return value === indexPath[index]; });
|
|
49
|
+
var isRightEqual = indexPath.slice(maxIndexPathLength).every(function (value) { return value === 0; });
|
|
50
|
+
return isEqual || (isLeftEqual && isRightEqual);
|
|
51
|
+
};
|
|
52
|
+
var getBaseIndexStartsAt = function (rowValue) {
|
|
53
|
+
for (var _i = 0, _a = Object.entries(rowValue); _i < _a.length; _i++) {
|
|
54
|
+
var _b = _a[_i], columnId = _b[0], subcells = _b[1];
|
|
55
|
+
if (columnId.startsWith('attributes.')) {
|
|
56
|
+
var columnAttributes = columnId.split('.').slice(1);
|
|
57
|
+
if (Array.isArray(subcells)) {
|
|
58
|
+
for (var _c = 0, subcells_1 = subcells; _c < subcells_1.length; _c++) {
|
|
59
|
+
var subcell = subcells_1[_c];
|
|
60
|
+
if (subcell.nestedKey) {
|
|
61
|
+
var cellAttributes = subcell.nestedKey.split('.').filter(function (part) { return !isFinite(part); });
|
|
62
|
+
var diff = difference(cellAttributes, columnAttributes);
|
|
63
|
+
return diff.length;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
};
|
|
71
|
+
var getMaxIndexPath = function (maxValuesCount, sortedSubcellValueGroups, baseIndexStartsAt) {
|
|
72
|
+
var maxCount = 0;
|
|
73
|
+
var baseCount = 0;
|
|
74
|
+
var previousLevel = 0;
|
|
75
|
+
var previousBaseIndex = 0;
|
|
76
|
+
var maxIndexPathValuesCount = Infinity;
|
|
77
|
+
var maxIndexPath = null;
|
|
78
|
+
for (var _i = 0, sortedSubcellValueGroups_1 = sortedSubcellValueGroups; _i < sortedSubcellValueGroups_1.length; _i++) {
|
|
79
|
+
var _a = sortedSubcellValueGroups_1[_i], indexPathKey = _a[0], visibleValuesCount = _a[1];
|
|
80
|
+
var currentIndexPath = stringKeyToIndexPath(indexPathKey);
|
|
81
|
+
var currentLevel = currentIndexPath.length;
|
|
82
|
+
var currentBaseIndex = currentIndexPath[baseIndexStartsAt] || 0;
|
|
83
|
+
var remainingCount = maxValuesCount - baseCount - maxCount;
|
|
84
|
+
if (currentBaseIndex !== previousBaseIndex) {
|
|
85
|
+
baseCount += maxCount;
|
|
86
|
+
previousBaseIndex = currentBaseIndex;
|
|
87
|
+
maxCount = 0;
|
|
88
|
+
}
|
|
89
|
+
if (currentLevel > previousLevel) {
|
|
90
|
+
maxCount = Math.max(maxCount, Math.min(visibleValuesCount, maxValuesCount - baseCount));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
maxCount += Math.min(visibleValuesCount, remainingCount);
|
|
94
|
+
}
|
|
95
|
+
if (maxCount + baseCount === maxValuesCount) {
|
|
96
|
+
maxIndexPath = currentIndexPath;
|
|
97
|
+
maxIndexPathValuesCount = currentLevel > previousLevel ? maxValuesCount - baseCount : remainingCount;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
previousLevel = currentLevel;
|
|
101
|
+
}
|
|
102
|
+
return { maxIndexPath: maxIndexPath, maxIndexPathValuesCount: maxIndexPathValuesCount };
|
|
103
|
+
};
|
|
104
|
+
var sortIndexPaths = function (indexPathA, indexPathB) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
var numbersA = stringKeyToIndexPath(indexPathA);
|
|
107
|
+
var numbersB = stringKeyToIndexPath(indexPathB);
|
|
108
|
+
for (var i = 0; i < Math.max(numbersA.length, numbersB.length); i++) {
|
|
109
|
+
var valA = (_a = numbersA[i]) !== null && _a !== void 0 ? _a : -1;
|
|
110
|
+
var valB = (_b = numbersB[i]) !== null && _b !== void 0 ? _b : -1;
|
|
111
|
+
if (valA !== valB)
|
|
112
|
+
return valA - valB;
|
|
113
|
+
}
|
|
114
|
+
return 0;
|
|
115
|
+
};
|
|
116
|
+
var getSubcellValuesGroup = function (rowValue) {
|
|
117
|
+
var subcellValueGroups = {};
|
|
118
|
+
Object.values(rowValue).forEach(function (subcells) {
|
|
119
|
+
return Array.isArray(subcells) &&
|
|
120
|
+
subcells.forEach(function (subcell, i) {
|
|
121
|
+
var indexPathKey = indexPathToStringKey(subcell.indexPath) || i;
|
|
122
|
+
subcellValueGroups[indexPathKey] = Math.max(subcellValueGroups[indexPathKey] || 0, subcell.values.length);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return Object.entries(subcellValueGroups).sort(function (_a, _b) {
|
|
126
|
+
var indexPathKeyA = _a[0];
|
|
127
|
+
var indexPathKeyB = _b[0];
|
|
128
|
+
return sortIndexPaths(indexPathKeyA, indexPathKeyB);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
var processSubcell = function (subcell, maxIndexPath, maxIndexPathValuesCount) {
|
|
132
|
+
var values = subcell.values, indexPath = subcell.indexPath, rest = __rest(subcell, ["values", "indexPath"]);
|
|
133
|
+
var isPathSmaller = isIndexPathSmaller(maxIndexPath, indexPath);
|
|
134
|
+
var isPathOnSameLevel = isIndexPathOnSameLevel(maxIndexPath, indexPath);
|
|
135
|
+
var allowedCount = 0;
|
|
136
|
+
if (isPathSmaller) {
|
|
137
|
+
allowedCount = values.length;
|
|
138
|
+
}
|
|
139
|
+
else if (isPathOnSameLevel) {
|
|
140
|
+
allowedCount = maxIndexPathValuesCount;
|
|
141
|
+
}
|
|
142
|
+
var visibleValues = values.slice(0, allowedCount);
|
|
143
|
+
var hiddenSubcellValues = values.slice(allowedCount);
|
|
144
|
+
var processedSubcell = __assign(__assign(__assign({}, rest), (indexPath ? { indexPath: indexPath } : {})), { values: visibleValues });
|
|
145
|
+
var shouldIncludeSubcell = isPathSmaller || isPathOnSameLevel;
|
|
146
|
+
return {
|
|
147
|
+
processedSubcell: shouldIncludeSubcell ? processedSubcell : null,
|
|
148
|
+
hiddenSubcellValues: hiddenSubcellValues
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
var processAllSubcells = function (subcells, maxIndexPath, maxIndexPathValuesCount, columnHiddenValues) {
|
|
152
|
+
var processedSubcells = subcells.map(function (subcell) {
|
|
153
|
+
var _a = processSubcell(subcell, maxIndexPath, maxIndexPathValuesCount), processedSubcell = _a.processedSubcell, hiddenSubcellValues = _a.hiddenSubcellValues;
|
|
154
|
+
if (hiddenSubcellValues.length) {
|
|
155
|
+
columnHiddenValues.push.apply(columnHiddenValues, hiddenSubcellValues);
|
|
156
|
+
}
|
|
157
|
+
return processedSubcell;
|
|
158
|
+
});
|
|
159
|
+
return processedSubcells.filter(identity);
|
|
160
|
+
};
|
|
161
|
+
var applyCompactValuesCountConstraintForEntity = function (maxValuesCount, rowValue) {
|
|
162
|
+
var sortedSubcellValueGroups = getSubcellValuesGroup(rowValue);
|
|
163
|
+
var baseIndexStartsAt = getBaseIndexStartsAt(rowValue);
|
|
164
|
+
var _a = getMaxIndexPath(maxValuesCount, sortedSubcellValueGroups, baseIndexStartsAt), maxIndexPath = _a.maxIndexPath, maxIndexPathValuesCount = _a.maxIndexPathValuesCount;
|
|
165
|
+
var rowValueWithConstraints = Object.entries(rowValue).reduce(function (acc, _a) {
|
|
166
|
+
var columnId = _a[0], subcells = _a[1];
|
|
167
|
+
var columnHiddenValues = [];
|
|
168
|
+
var processedSubcells = Array.isArray(subcells)
|
|
169
|
+
? processAllSubcells(subcells, maxIndexPath, maxIndexPathValuesCount, columnHiddenValues)
|
|
170
|
+
: subcells;
|
|
171
|
+
acc[columnId] = adjust(0, assoc('hiddenValues', columnHiddenValues), processedSubcells);
|
|
172
|
+
return acc;
|
|
173
|
+
}, {});
|
|
174
|
+
return rowValueWithConstraints;
|
|
175
|
+
};
|
|
176
|
+
var applyCompactValuesCountConstraint = function (maxValuesCount) { return function (rowValue) {
|
|
177
|
+
if (maxValuesCount === Infinity) {
|
|
178
|
+
return rowValue;
|
|
179
|
+
}
|
|
180
|
+
return applyCompactValuesCountConstraintForEntity(maxValuesCount, rowValue);
|
|
181
|
+
}; };
|
|
182
|
+
var getHasHiddenAttributes = pipe(values, chain(identity), chain(pathOr([], ['hiddenValues'])), length, gt(__, 0));
|
|
183
|
+
export { applyCompactValuesCountConstraint, getHasHiddenAttributes };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getRowValueData, getRowValueWithConstraintsDataForMVC1, getRowValueWithConstraintsDataForMVC2, getRowValueWithConstraintsDataForMVC3, getRowValueWithConstraintsDataForMVC6 } from './data/tableCompactCollapseHelper.data';
|
|
2
|
+
import { applyCompactValuesCountConstraint } from './tableCompactCollapseHelpers';
|
|
3
|
+
var rowValue = getRowValueData();
|
|
4
|
+
describe('applyCompactValuesCountConstraint tests', function () {
|
|
5
|
+
it('should not update row value if maxValuesCount is Infinity', function () {
|
|
6
|
+
var maxValuesCount = Infinity;
|
|
7
|
+
expect(applyCompactValuesCountConstraint(maxValuesCount)(rowValue)).toEqual(rowValue);
|
|
8
|
+
});
|
|
9
|
+
it('should correctly apply constraints for maxValuesCount 1', function () {
|
|
10
|
+
var maxValuesCount = 1;
|
|
11
|
+
expect(applyCompactValuesCountConstraint(maxValuesCount)(rowValue)).toEqual(getRowValueWithConstraintsDataForMVC1());
|
|
12
|
+
});
|
|
13
|
+
it('should correctly apply constraints for maxValuesCount 2', function () {
|
|
14
|
+
var maxValuesCount = 2;
|
|
15
|
+
expect(applyCompactValuesCountConstraint(maxValuesCount)(rowValue)).toEqual(getRowValueWithConstraintsDataForMVC2());
|
|
16
|
+
});
|
|
17
|
+
it('should correctly apply constraints for maxValuesCount 3', function () {
|
|
18
|
+
var maxValuesCount = 3;
|
|
19
|
+
expect(applyCompactValuesCountConstraint(maxValuesCount)(rowValue)).toEqual(getRowValueWithConstraintsDataForMVC3());
|
|
20
|
+
});
|
|
21
|
+
it('should correctly apply constraints for maxValuesCount 6', function () {
|
|
22
|
+
var maxValuesCount = 6;
|
|
23
|
+
expect(applyCompactValuesCountConstraint(maxValuesCount)(rowValue)).toEqual(getRowValueWithConstraintsDataForMVC6());
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -7,13 +7,14 @@ type Props = {
|
|
|
7
7
|
getRowCellHeight?: GetRowCellHeight;
|
|
8
8
|
defaultRowHeight?: number;
|
|
9
9
|
maxRowValuesCount?: number;
|
|
10
|
+
applyMaxValuesCountConstraint?: (maxValuesCount: number) => (rowValue: RowValue) => RowValue;
|
|
10
11
|
};
|
|
11
|
-
export declare const useBasicTableCellRenderer: ({ rowsData, columnsData, getIdFromRowValue, renderRowCell, getRowCellHeight, defaultRowHeight, maxRowValuesCount }: Props) => {
|
|
12
|
+
export declare const useBasicTableCellRenderer: ({ rowsData, columnsData, getIdFromRowValue, renderRowCell, getRowCellHeight, defaultRowHeight, maxRowValuesCount, applyMaxValuesCountConstraint }: Props) => {
|
|
12
13
|
getRowHeight: (rowId: RowId) => number;
|
|
13
14
|
collapseContextValue: {
|
|
14
15
|
maxRowValuesCount: number;
|
|
15
16
|
toggleRowCollapse: (rowIndex: number) => void;
|
|
16
|
-
getIsRowCollapsible: (rowValue: Record<string, unknown>) =>
|
|
17
|
+
getIsRowCollapsible: (rowValue: Record<string, unknown>) => any;
|
|
17
18
|
getIsRowCollapsed: (rowIndex: number) => boolean;
|
|
18
19
|
};
|
|
19
20
|
getHeightForSubRow: (rowId: RowId, columnIndex: number, subRowIndex: number) => any;
|
|
@@ -4,14 +4,15 @@ import { calculateRowHeight } from 'react-components/dist/Table/tableUtils';
|
|
|
4
4
|
import { defaultRenderRowCell, defaultGetRowCellHeight } from '../../helpers/basicTable';
|
|
5
5
|
import { useCollapsibleTableRows } from '../useCollapsibleTableRows';
|
|
6
6
|
export var useBasicTableCellRenderer = function (_a) {
|
|
7
|
-
var rowsData = _a.rowsData, columnsData = _a.columnsData, getIdFromRowValue = _a.getIdFromRowValue, _b = _a.renderRowCell, renderRowCell = _b === void 0 ? defaultRenderRowCell : _b, _c = _a.getRowCellHeight, getRowCellHeight = _c === void 0 ? defaultGetRowCellHeight : _c, _d = _a.defaultRowHeight, defaultRowHeight = _d === void 0 ? 48 : _d, _e = _a.maxRowValuesCount, maxRowValuesCount = _e === void 0 ? Infinity : _e;
|
|
7
|
+
var rowsData = _a.rowsData, columnsData = _a.columnsData, getIdFromRowValue = _a.getIdFromRowValue, _b = _a.renderRowCell, renderRowCell = _b === void 0 ? defaultRenderRowCell : _b, _c = _a.getRowCellHeight, getRowCellHeight = _c === void 0 ? defaultGetRowCellHeight : _c, _d = _a.defaultRowHeight, defaultRowHeight = _d === void 0 ? 48 : _d, _e = _a.maxRowValuesCount, maxRowValuesCount = _e === void 0 ? Infinity : _e, applyMaxValuesCountConstraint = _a.applyMaxValuesCountConstraint;
|
|
8
8
|
var _f = useCollapsibleTableRows({
|
|
9
9
|
rowsData: rowsData,
|
|
10
10
|
columnsData: columnsData,
|
|
11
11
|
renderRowCell: renderRowCell,
|
|
12
12
|
getRowCellHeight: getRowCellHeight,
|
|
13
13
|
maxRowValuesCount: maxRowValuesCount,
|
|
14
|
-
getIdFromRowValue: getIdFromRowValue
|
|
14
|
+
getIdFromRowValue: getIdFromRowValue,
|
|
15
|
+
applyMaxValuesCountConstraint: applyMaxValuesCountConstraint
|
|
15
16
|
}), tableRowsData = _f.tableRowsData, collapseContextValue = _f.collapseContextValue;
|
|
16
17
|
return useMemo(function () {
|
|
17
18
|
var rowHeightCache = tableRowsData.reduce(function (cache, rowData) {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export function getTableRowsData(rowValues: any, columnsData: any, renderRowCell: any, getRowCellHeight: any, getRowMaxValuesCount
|
|
1
|
+
export function getTableRowsData(rowValues: any, columnsData: any, renderRowCell: any, getRowCellHeight: any, getRowMaxValuesCount: any, getIdFromRowValue: (_: any, rowIndex: any) => any, applyMaxValuesCountConstraint: any): any;
|
|
2
2
|
export function getMaxRowValuesCount(columnsData: any, rowValue: any): any;
|
|
3
|
+
export function getIsRowCollapsibleFromMaxValuesCount(columnsData: any, rowValue: any, maxValuesCount: any, applyMaxValuesCountConstraint: any): any;
|
|
@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import { add, adjust, always, assoc, chain, evolve, isEmpty, isNil, map, mapObjIndexed, max, pipe, pluck, propEq, propOr, reduce, reject, slice, uniq, unless, values } from 'ramda';
|
|
12
|
+
import { __, add, adjust, always, assoc, chain, evolve, gt, identity, isEmpty, isNil, length, map, mapObjIndexed, max, pathOr, pipe, pluck, propEq, propOr, reduce, reject, slice, uniq, unless, values } from 'ramda';
|
|
13
13
|
import { wrapInArrayIfNeeded } from '@reltio/mdm-sdk';
|
|
14
14
|
import { DefaultCellValueRenderer } from '../../DefaultCellValueRenderer';
|
|
15
15
|
import { calcRowSpansForNestedKeys, flattenNestedColumnValues, getNestedKeyForNestedColumnCell, TOTAL_ROW_SPAN_KEY } from './nestedHelpers';
|
|
@@ -70,7 +70,7 @@ var areNestedValuesExceedingLimit = function (maxValuesCount) {
|
|
|
70
70
|
return indexPath && indexPath.some(function (index) { return index > maxValuesCount - 1; });
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
|
-
var
|
|
73
|
+
var getHiddenValues = function (rowValues, maxValuesCount) {
|
|
74
74
|
if (maxValuesCount === void 0) { maxValuesCount = Infinity; }
|
|
75
75
|
return rowValues.reduce(function (hiddenValues, _a) {
|
|
76
76
|
var _b = _a.values, values = _b === void 0 ? [] : _b, indexPath = _a.indexPath;
|
|
@@ -83,21 +83,22 @@ var getAllRowHiddenValues = function (rowValues, maxValuesCount) {
|
|
|
83
83
|
var adjustFirstWithHiddenValues = function (maxValuesCount) {
|
|
84
84
|
if (maxValuesCount === void 0) { maxValuesCount = Infinity; }
|
|
85
85
|
return function (rowValues) {
|
|
86
|
-
var hiddenValues =
|
|
87
|
-
return adjust(0, assoc('
|
|
86
|
+
var hiddenValues = getHiddenValues(rowValues, maxValuesCount);
|
|
87
|
+
return adjust(0, assoc('hiddenValues', hiddenValues), rowValues);
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
|
-
var
|
|
90
|
+
var applyDefaultValuesCountConstraint = function (maxValuesCount) {
|
|
91
91
|
return unless(function () { return maxValuesCount === Infinity; }, map(pipe(adjustFirstWithHiddenValues(maxValuesCount), reject(areNestedValuesExceedingLimit(maxValuesCount)), map(evolve({
|
|
92
92
|
values: slice(0, maxValuesCount)
|
|
93
93
|
})))));
|
|
94
94
|
};
|
|
95
95
|
var defaultGetIdFromRowValue = function (_, rowIndex) { return rowIndex; };
|
|
96
|
-
var getTableRowsData = function (rowValues, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue) {
|
|
96
|
+
var getTableRowsData = function (rowValues, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue, applyMaxValuesCountConstraint) {
|
|
97
97
|
if (getRowMaxValuesCount === void 0) { getRowMaxValuesCount = always(Infinity); }
|
|
98
98
|
if (getIdFromRowValue === void 0) { getIdFromRowValue = defaultGetIdFromRowValue; }
|
|
99
|
+
applyMaxValuesCountConstraint = applyMaxValuesCountConstraint || applyDefaultValuesCountConstraint;
|
|
99
100
|
return rowValues.map(function (rowValue, rowIndex) {
|
|
100
|
-
return pipe(buildRowValues(rowValue),
|
|
101
|
+
return pipe(buildRowValues(rowValue), applyMaxValuesCountConstraint(getRowMaxValuesCount(rowIndex)), calcRowSpans, calcHeights(columnsData, getRowCellHeight, rowIndex, rowValue), applyCellRenderer(columnsData, renderRowCell, rowIndex, rowValue), function (val) { return ({ data: val, id: getIdFromRowValue(rowValue, rowIndex) }); })(columnsData);
|
|
101
102
|
});
|
|
102
103
|
};
|
|
103
104
|
var calcMaxValuesCount = reduce(function (maxCount, cellValues) {
|
|
@@ -108,4 +109,11 @@ var calcMaxValuesCount = reduce(function (maxCount, cellValues) {
|
|
|
108
109
|
var getMaxRowValuesCount = function (columnsData, rowValue) {
|
|
109
110
|
return pipe(buildRowValues(rowValue), values, calcMaxValuesCount)(columnsData);
|
|
110
111
|
};
|
|
111
|
-
|
|
112
|
+
var getHasHiddenAttributes = pipe(values, chain(identity), chain(pathOr([], ['hiddenValues'])), length, gt(__, 0));
|
|
113
|
+
var getIsRowCollapsibleFromMaxValuesCount = function (columnsData, rowValue, maxValuesCount, applyMaxValuesCountConstraint) {
|
|
114
|
+
if (applyMaxValuesCountConstraint) {
|
|
115
|
+
return pipe(buildRowValues(rowValue), applyMaxValuesCountConstraint(maxValuesCount), getHasHiddenAttributes)(columnsData);
|
|
116
|
+
}
|
|
117
|
+
return getMaxRowValuesCount(columnsData, rowValue) > maxValuesCount;
|
|
118
|
+
};
|
|
119
|
+
export { getTableRowsData, getMaxRowValuesCount, getIsRowCollapsibleFromMaxValuesCount };
|
|
@@ -246,7 +246,7 @@ describe('dataHelpers', function () {
|
|
|
246
246
|
data: {
|
|
247
247
|
'n1.a': [
|
|
248
248
|
{
|
|
249
|
-
|
|
249
|
+
hiddenValues: [2, 3],
|
|
250
250
|
values: [1],
|
|
251
251
|
indexPath: [0],
|
|
252
252
|
nestedKey: 'n1.0',
|
|
@@ -254,17 +254,17 @@ describe('dataHelpers', function () {
|
|
|
254
254
|
}
|
|
255
255
|
],
|
|
256
256
|
'n1.n2.b': [
|
|
257
|
-
{ values: [],
|
|
257
|
+
{ values: [], hiddenValues: [4, 5, 6], indexPath: [0], nestedKey: 'n1.0', rowSpan: 1 }
|
|
258
258
|
],
|
|
259
|
-
c: [{
|
|
260
|
-
'n1.d': [{ values: [],
|
|
259
|
+
c: [{ hiddenValues: [8, 9, 10], values: [7], rowSpan: 1 }],
|
|
260
|
+
'n1.d': [{ values: [], hiddenValues: [], rowSpan: 1 }]
|
|
261
261
|
},
|
|
262
262
|
id: 0
|
|
263
263
|
}
|
|
264
264
|
]);
|
|
265
265
|
expect(getRowMaxValuesCount).toHaveBeenCalledWith(0);
|
|
266
266
|
});
|
|
267
|
-
it('should apply
|
|
267
|
+
it('should apply hiddenValues correctly if maxValuesCount more than 1', function () {
|
|
268
268
|
var rowValues = [
|
|
269
269
|
{
|
|
270
270
|
'n1.n2.a': [[[1, 2]], [[3, 4, 5]]]
|
|
@@ -282,7 +282,7 @@ describe('dataHelpers', function () {
|
|
|
282
282
|
'n1.n2.a': [
|
|
283
283
|
{
|
|
284
284
|
values: [1, 2],
|
|
285
|
-
|
|
285
|
+
hiddenValues: [5],
|
|
286
286
|
indexPath: [0, 0],
|
|
287
287
|
nestedKey: 'n1.0.n2.0',
|
|
288
288
|
rowSpan: 1
|
|
@@ -6,13 +6,14 @@ type Props = {
|
|
|
6
6
|
getRowCellHeight: GetRowCellHeight;
|
|
7
7
|
maxRowValuesCount: number;
|
|
8
8
|
getIdFromRowValue?: (rowValue: RowValue, rowIndex: number) => RowId;
|
|
9
|
+
applyMaxValuesCountConstraint?: (maxValuesCount: number) => (rowValue: RowValue) => RowValue;
|
|
9
10
|
};
|
|
10
|
-
export declare const useCollapsibleTableRows: ({ rowsData, columnsData, renderRowCell, getRowCellHeight, maxRowValuesCount, getIdFromRowValue }: Props) => {
|
|
11
|
+
export declare const useCollapsibleTableRows: ({ rowsData, columnsData, renderRowCell, getRowCellHeight, maxRowValuesCount, getIdFromRowValue, applyMaxValuesCountConstraint }: Props) => {
|
|
11
12
|
tableRowsData: TableRowsData;
|
|
12
13
|
collapseContextValue: {
|
|
13
14
|
maxRowValuesCount: number;
|
|
14
15
|
toggleRowCollapse: (rowIndex: number) => void;
|
|
15
|
-
getIsRowCollapsible: (rowValue: Record<string, unknown>) =>
|
|
16
|
+
getIsRowCollapsible: (rowValue: Record<string, unknown>) => any;
|
|
16
17
|
getIsRowCollapsed: (rowIndex: number) => boolean;
|
|
17
18
|
};
|
|
18
19
|
};
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { useCallback, useMemo, useState } from 'react';
|
|
2
2
|
import { equals, filter, remove } from 'ramda';
|
|
3
|
-
import { getTableRowsData,
|
|
3
|
+
import { getTableRowsData, getIsRowCollapsibleFromMaxValuesCount } from './dataHelpers';
|
|
4
4
|
import { useDidUpdateEffect } from '../useDidUpdateEffect';
|
|
5
5
|
import { usePrevious } from '../../hooks/usePrevious';
|
|
6
6
|
export var useCollapsibleTableRows = function (_a) {
|
|
7
|
-
var rowsData = _a.rowsData, columnsData = _a.columnsData, renderRowCell = _a.renderRowCell, getRowCellHeight = _a.getRowCellHeight, maxRowValuesCount = _a.maxRowValuesCount, getIdFromRowValue = _a.getIdFromRowValue;
|
|
7
|
+
var rowsData = _a.rowsData, columnsData = _a.columnsData, renderRowCell = _a.renderRowCell, getRowCellHeight = _a.getRowCellHeight, maxRowValuesCount = _a.maxRowValuesCount, getIdFromRowValue = _a.getIdFromRowValue, applyMaxValuesCountConstraint = _a.applyMaxValuesCountConstraint;
|
|
8
8
|
var _b = useState([]), expandedIndexes = _b[0], setExpandedIndexes = _b[1];
|
|
9
9
|
var getRowMaxValuesCount = useCallback(function (rowIndex) {
|
|
10
10
|
return expandedIndexes.includes(rowIndex) ? Infinity : maxRowValuesCount;
|
|
11
11
|
}, [expandedIndexes, maxRowValuesCount]);
|
|
12
12
|
var tableRowsData = useMemo(function () {
|
|
13
|
-
return getTableRowsData(rowsData, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue);
|
|
14
|
-
}, [
|
|
13
|
+
return getTableRowsData(rowsData, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue, applyMaxValuesCountConstraint);
|
|
14
|
+
}, [
|
|
15
|
+
rowsData,
|
|
16
|
+
columnsData,
|
|
17
|
+
renderRowCell,
|
|
18
|
+
getRowCellHeight,
|
|
19
|
+
getRowMaxValuesCount,
|
|
20
|
+
getIdFromRowValue,
|
|
21
|
+
applyMaxValuesCountConstraint
|
|
22
|
+
]);
|
|
15
23
|
var toggleRowCollapse = useCallback(function (rowIndex) {
|
|
16
24
|
setExpandedIndexes(function (expandedIndexes) {
|
|
17
25
|
var index = expandedIndexes.findIndex(equals(rowIndex));
|
|
@@ -19,8 +27,8 @@ export var useCollapsibleTableRows = function (_a) {
|
|
|
19
27
|
});
|
|
20
28
|
}, []);
|
|
21
29
|
var getIsRowCollapsible = useCallback(function (rowValue) {
|
|
22
|
-
return
|
|
23
|
-
}, [maxRowValuesCount, columnsData]);
|
|
30
|
+
return getIsRowCollapsibleFromMaxValuesCount(columnsData, rowValue, maxRowValuesCount, applyMaxValuesCountConstraint);
|
|
31
|
+
}, [maxRowValuesCount, columnsData, applyMaxValuesCountConstraint]);
|
|
24
32
|
var getIsRowCollapsed = useCallback(function (rowIndex) {
|
|
25
33
|
return !expandedIndexes.includes(rowIndex);
|
|
26
34
|
}, [expandedIndexes]);
|
|
@@ -44,11 +44,11 @@ describe('useCollapsibleTableRows tests', function () {
|
|
|
44
44
|
};
|
|
45
45
|
beforeAll(function () {
|
|
46
46
|
jest.spyOn(dataHelpers, 'getTableRowsData');
|
|
47
|
-
jest.spyOn(dataHelpers, '
|
|
47
|
+
jest.spyOn(dataHelpers, 'getIsRowCollapsibleFromMaxValuesCount');
|
|
48
48
|
});
|
|
49
49
|
beforeEach(function () {
|
|
50
50
|
dataHelpers.getTableRowsData.mockClear();
|
|
51
|
-
dataHelpers.
|
|
51
|
+
dataHelpers.getIsRowCollapsibleFromMaxValuesCount.mockClear();
|
|
52
52
|
});
|
|
53
53
|
it('should return collapsed table rows data by default', function () {
|
|
54
54
|
var result = getCollapsibleTableRows().result;
|
|
@@ -73,9 +73,8 @@ describe('useCollapsibleTableRows tests', function () {
|
|
|
73
73
|
});
|
|
74
74
|
it('should return correct getIsRowCollapsible function for context', function () {
|
|
75
75
|
var _a = getCollapsibleTableRows(), result = _a.result, rerender = _a.rerender;
|
|
76
|
-
dataHelpers.getMaxRowValuesCount.mockReturnValueOnce(3);
|
|
77
76
|
expect(result.current.collapseContextValue.getIsRowCollapsible(rowsData[0])).toBe(true);
|
|
78
|
-
expect(dataHelpers.
|
|
77
|
+
expect(dataHelpers.getIsRowCollapsibleFromMaxValuesCount).toHaveBeenCalledWith(columnsData, rowsData[0], 1, undefined);
|
|
79
78
|
rerender(__assign(__assign({}, initialProps), { maxRowValuesCount: 4 }));
|
|
80
79
|
expect(result.current.collapseContextValue.getIsRowCollapsible(rowsData[0])).toBe(false);
|
|
81
80
|
});
|
package/index.d.ts
CHANGED
|
@@ -277,6 +277,7 @@ export { showDefaultErrorMessage, showErrorMessage } from './helpers/errors';
|
|
|
277
277
|
export { getChecked, getValue, isControlOrCommandPressed } from './helpers/events';
|
|
278
278
|
export { mergeClasses } from './helpers/classes';
|
|
279
279
|
export { getAttributeSelectorItems } from './helpers/attributesSelector';
|
|
280
|
+
export { applyCompactValuesCountConstraint } from './helpers/tableCompactCollapseHelpers';
|
|
280
281
|
export type { AttributeFiltersComponentProps } from './AttributesFiltersBuilder';
|
|
281
282
|
export type { ChartData } from './types/charts';
|
|
282
283
|
export type { AddInlineAttributeEvent, DeleteInlineAttributeEvent, EditInlineAttributeEvent, IgnoreInlineAttributeEvent, PinInlineAttributeEvent } from './types/inlineAttributes';
|
package/index.js
CHANGED
|
@@ -282,6 +282,7 @@ export { showDefaultErrorMessage, showErrorMessage } from './helpers/errors';
|
|
|
282
282
|
export { getChecked, getValue, isControlOrCommandPressed } from './helpers/events';
|
|
283
283
|
export { mergeClasses } from './helpers/classes';
|
|
284
284
|
export { getAttributeSelectorItems } from './helpers/attributesSelector';
|
|
285
|
+
export { applyCompactValuesCountConstraint } from './helpers/tableCompactCollapseHelpers';
|
|
285
286
|
export * from './types/preferences';
|
|
286
287
|
export * from './types';
|
|
287
288
|
// constants
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reltio/components",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2082",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE FILE",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"@fluentui/react-context-selector": "^9.1.26",
|
|
12
12
|
"@googlemaps/markerclusterer": "^2.5.3",
|
|
13
13
|
"@react-sigma/core": "3.4.0",
|
|
14
|
-
"@reltio/mdm-sdk": "^1.4.
|
|
14
|
+
"@reltio/mdm-sdk": "^1.4.1925",
|
|
15
15
|
"@vis.gl/react-google-maps": "^1.3.0",
|
|
16
16
|
"d3-cloud": "^1.2.5",
|
|
17
17
|
"d3-geo": "^2.0.1",
|