@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.
Files changed (35) hide show
  1. package/BasicTable/BasicTable.js +3 -2
  2. package/cjs/BasicTable/BasicTable.js +3 -2
  3. package/cjs/helpers/data/tableCompactCollapseHelper.data.d.ts +491 -0
  4. package/cjs/helpers/data/tableCompactCollapseHelper.data.js +1641 -0
  5. package/cjs/helpers/tableCompactCollapseHelpers.d.ts +4 -0
  6. package/cjs/helpers/tableCompactCollapseHelpers.js +187 -0
  7. package/cjs/helpers/tableCompactCollapseHelpers.test.d.ts +1 -0
  8. package/cjs/helpers/tableCompactCollapseHelpers.test.js +27 -0
  9. package/cjs/hooks/useBasicTableCellRenderer/useBasicTableCellRenderer.d.ts +3 -2
  10. package/cjs/hooks/useBasicTableCellRenderer/useBasicTableCellRenderer.js +3 -2
  11. package/cjs/hooks/useCollapsibleTableRows/dataHelpers.d.ts +2 -1
  12. package/cjs/hooks/useCollapsibleTableRows/dataHelpers.js +16 -7
  13. package/cjs/hooks/useCollapsibleTableRows/dataHelpers.test.js +6 -6
  14. package/cjs/hooks/useCollapsibleTableRows/useCollapsibleTableRows.d.ts +3 -2
  15. package/cjs/hooks/useCollapsibleTableRows/useCollapsibleTableRows.js +13 -5
  16. package/cjs/hooks/useCollapsibleTableRows/useCollapsibleTableRows.test.js +3 -4
  17. package/cjs/index.d.ts +1 -0
  18. package/cjs/index.js +3 -1
  19. package/helpers/data/tableCompactCollapseHelper.data.d.ts +491 -0
  20. package/helpers/data/tableCompactCollapseHelper.data.js +1633 -0
  21. package/helpers/tableCompactCollapseHelpers.d.ts +4 -0
  22. package/helpers/tableCompactCollapseHelpers.js +183 -0
  23. package/helpers/tableCompactCollapseHelpers.test.d.ts +1 -0
  24. package/helpers/tableCompactCollapseHelpers.test.js +25 -0
  25. package/hooks/useBasicTableCellRenderer/useBasicTableCellRenderer.d.ts +3 -2
  26. package/hooks/useBasicTableCellRenderer/useBasicTableCellRenderer.js +3 -2
  27. package/hooks/useCollapsibleTableRows/dataHelpers.d.ts +2 -1
  28. package/hooks/useCollapsibleTableRows/dataHelpers.js +16 -8
  29. package/hooks/useCollapsibleTableRows/dataHelpers.test.js +6 -6
  30. package/hooks/useCollapsibleTableRows/useCollapsibleTableRows.d.ts +3 -2
  31. package/hooks/useCollapsibleTableRows/useCollapsibleTableRows.js +14 -6
  32. package/hooks/useCollapsibleTableRows/useCollapsibleTableRows.test.js +3 -4
  33. package/index.d.ts +1 -0
  34. package/index.js +1 -0
  35. 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,187 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.getHasHiddenAttributes = exports.applyCompactValuesCountConstraint = void 0;
26
+ var ramda_1 = require("ramda");
27
+ var INDEX_PATH_SEPARATOR = ',';
28
+ var indexPathToStringKey = function (indexPath) { return indexPath === null || indexPath === void 0 ? void 0 : indexPath.join(INDEX_PATH_SEPARATOR); };
29
+ var stringKeyToIndexPath = function (stringKey) { return stringKey.split(INDEX_PATH_SEPARATOR).map(Number); };
30
+ var isIndexPathSmaller = function (maxIndexPath, indexPath) {
31
+ if (!indexPath || !maxIndexPath) {
32
+ return true;
33
+ }
34
+ var minLength = Math.min(maxIndexPath.length, indexPath.length);
35
+ for (var i = 0; i < minLength; i++) {
36
+ if (indexPath[i] < maxIndexPath[i]) {
37
+ return true;
38
+ }
39
+ else if (indexPath[i] > maxIndexPath[i]) {
40
+ return false;
41
+ }
42
+ }
43
+ return indexPath.length < maxIndexPath.length;
44
+ };
45
+ var isIndexPathOnSameLevel = function (maxIndexPath, indexPath) {
46
+ if (!indexPath || !maxIndexPath) {
47
+ return false;
48
+ }
49
+ var maxIndexPathLength = maxIndexPath.length;
50
+ var isEqual = maxIndexPath.length === indexPath.length && maxIndexPath.every(function (value, index) { return value === indexPath[index]; });
51
+ var isLeftEqual = maxIndexPath.every(function (value, index) { return value === indexPath[index]; });
52
+ var isRightEqual = indexPath.slice(maxIndexPathLength).every(function (value) { return value === 0; });
53
+ return isEqual || (isLeftEqual && isRightEqual);
54
+ };
55
+ var getBaseIndexStartsAt = function (rowValue) {
56
+ for (var _i = 0, _a = Object.entries(rowValue); _i < _a.length; _i++) {
57
+ var _b = _a[_i], columnId = _b[0], subcells = _b[1];
58
+ if (columnId.startsWith('attributes.')) {
59
+ var columnAttributes = columnId.split('.').slice(1);
60
+ if (Array.isArray(subcells)) {
61
+ for (var _c = 0, subcells_1 = subcells; _c < subcells_1.length; _c++) {
62
+ var subcell = subcells_1[_c];
63
+ if (subcell.nestedKey) {
64
+ var cellAttributes = subcell.nestedKey.split('.').filter(function (part) { return !isFinite(part); });
65
+ var diff = (0, ramda_1.difference)(cellAttributes, columnAttributes);
66
+ return diff.length;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ return 0;
73
+ };
74
+ var getMaxIndexPath = function (maxValuesCount, sortedSubcellValueGroups, baseIndexStartsAt) {
75
+ var maxCount = 0;
76
+ var baseCount = 0;
77
+ var previousLevel = 0;
78
+ var previousBaseIndex = 0;
79
+ var maxIndexPathValuesCount = Infinity;
80
+ var maxIndexPath = null;
81
+ for (var _i = 0, sortedSubcellValueGroups_1 = sortedSubcellValueGroups; _i < sortedSubcellValueGroups_1.length; _i++) {
82
+ var _a = sortedSubcellValueGroups_1[_i], indexPathKey = _a[0], visibleValuesCount = _a[1];
83
+ var currentIndexPath = stringKeyToIndexPath(indexPathKey);
84
+ var currentLevel = currentIndexPath.length;
85
+ var currentBaseIndex = currentIndexPath[baseIndexStartsAt] || 0;
86
+ var remainingCount = maxValuesCount - baseCount - maxCount;
87
+ if (currentBaseIndex !== previousBaseIndex) {
88
+ baseCount += maxCount;
89
+ previousBaseIndex = currentBaseIndex;
90
+ maxCount = 0;
91
+ }
92
+ if (currentLevel > previousLevel) {
93
+ maxCount = Math.max(maxCount, Math.min(visibleValuesCount, maxValuesCount - baseCount));
94
+ }
95
+ else {
96
+ maxCount += Math.min(visibleValuesCount, remainingCount);
97
+ }
98
+ if (maxCount + baseCount === maxValuesCount) {
99
+ maxIndexPath = currentIndexPath;
100
+ maxIndexPathValuesCount = currentLevel > previousLevel ? maxValuesCount - baseCount : remainingCount;
101
+ break;
102
+ }
103
+ previousLevel = currentLevel;
104
+ }
105
+ return { maxIndexPath: maxIndexPath, maxIndexPathValuesCount: maxIndexPathValuesCount };
106
+ };
107
+ var sortIndexPaths = function (indexPathA, indexPathB) {
108
+ var _a, _b;
109
+ var numbersA = stringKeyToIndexPath(indexPathA);
110
+ var numbersB = stringKeyToIndexPath(indexPathB);
111
+ for (var i = 0; i < Math.max(numbersA.length, numbersB.length); i++) {
112
+ var valA = (_a = numbersA[i]) !== null && _a !== void 0 ? _a : -1;
113
+ var valB = (_b = numbersB[i]) !== null && _b !== void 0 ? _b : -1;
114
+ if (valA !== valB)
115
+ return valA - valB;
116
+ }
117
+ return 0;
118
+ };
119
+ var getSubcellValuesGroup = function (rowValue) {
120
+ var subcellValueGroups = {};
121
+ Object.values(rowValue).forEach(function (subcells) {
122
+ return Array.isArray(subcells) &&
123
+ subcells.forEach(function (subcell, i) {
124
+ var indexPathKey = indexPathToStringKey(subcell.indexPath) || i;
125
+ subcellValueGroups[indexPathKey] = Math.max(subcellValueGroups[indexPathKey] || 0, subcell.values.length);
126
+ });
127
+ });
128
+ return Object.entries(subcellValueGroups).sort(function (_a, _b) {
129
+ var indexPathKeyA = _a[0];
130
+ var indexPathKeyB = _b[0];
131
+ return sortIndexPaths(indexPathKeyA, indexPathKeyB);
132
+ });
133
+ };
134
+ var processSubcell = function (subcell, maxIndexPath, maxIndexPathValuesCount) {
135
+ var values = subcell.values, indexPath = subcell.indexPath, rest = __rest(subcell, ["values", "indexPath"]);
136
+ var isPathSmaller = isIndexPathSmaller(maxIndexPath, indexPath);
137
+ var isPathOnSameLevel = isIndexPathOnSameLevel(maxIndexPath, indexPath);
138
+ var allowedCount = 0;
139
+ if (isPathSmaller) {
140
+ allowedCount = values.length;
141
+ }
142
+ else if (isPathOnSameLevel) {
143
+ allowedCount = maxIndexPathValuesCount;
144
+ }
145
+ var visibleValues = values.slice(0, allowedCount);
146
+ var hiddenSubcellValues = values.slice(allowedCount);
147
+ var processedSubcell = __assign(__assign(__assign({}, rest), (indexPath ? { indexPath: indexPath } : {})), { values: visibleValues });
148
+ var shouldIncludeSubcell = isPathSmaller || isPathOnSameLevel;
149
+ return {
150
+ processedSubcell: shouldIncludeSubcell ? processedSubcell : null,
151
+ hiddenSubcellValues: hiddenSubcellValues
152
+ };
153
+ };
154
+ var processAllSubcells = function (subcells, maxIndexPath, maxIndexPathValuesCount, columnHiddenValues) {
155
+ var processedSubcells = subcells.map(function (subcell) {
156
+ var _a = processSubcell(subcell, maxIndexPath, maxIndexPathValuesCount), processedSubcell = _a.processedSubcell, hiddenSubcellValues = _a.hiddenSubcellValues;
157
+ if (hiddenSubcellValues.length) {
158
+ columnHiddenValues.push.apply(columnHiddenValues, hiddenSubcellValues);
159
+ }
160
+ return processedSubcell;
161
+ });
162
+ return processedSubcells.filter(ramda_1.identity);
163
+ };
164
+ var applyCompactValuesCountConstraintForEntity = function (maxValuesCount, rowValue) {
165
+ var sortedSubcellValueGroups = getSubcellValuesGroup(rowValue);
166
+ var baseIndexStartsAt = getBaseIndexStartsAt(rowValue);
167
+ var _a = getMaxIndexPath(maxValuesCount, sortedSubcellValueGroups, baseIndexStartsAt), maxIndexPath = _a.maxIndexPath, maxIndexPathValuesCount = _a.maxIndexPathValuesCount;
168
+ var rowValueWithConstraints = Object.entries(rowValue).reduce(function (acc, _a) {
169
+ var columnId = _a[0], subcells = _a[1];
170
+ var columnHiddenValues = [];
171
+ var processedSubcells = Array.isArray(subcells)
172
+ ? processAllSubcells(subcells, maxIndexPath, maxIndexPathValuesCount, columnHiddenValues)
173
+ : subcells;
174
+ acc[columnId] = (0, ramda_1.adjust)(0, (0, ramda_1.assoc)('hiddenValues', columnHiddenValues), processedSubcells);
175
+ return acc;
176
+ }, {});
177
+ return rowValueWithConstraints;
178
+ };
179
+ var applyCompactValuesCountConstraint = function (maxValuesCount) { return function (rowValue) {
180
+ if (maxValuesCount === Infinity) {
181
+ return rowValue;
182
+ }
183
+ return applyCompactValuesCountConstraintForEntity(maxValuesCount, rowValue);
184
+ }; };
185
+ exports.applyCompactValuesCountConstraint = applyCompactValuesCountConstraint;
186
+ var getHasHiddenAttributes = (0, ramda_1.pipe)(ramda_1.values, (0, ramda_1.chain)(ramda_1.identity), (0, ramda_1.chain)((0, ramda_1.pathOr)([], ['hiddenValues'])), ramda_1.length, (0, ramda_1.gt)(ramda_1.__, 0));
187
+ exports.getHasHiddenAttributes = getHasHiddenAttributes;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tableCompactCollapseHelper_data_1 = require("./data/tableCompactCollapseHelper.data");
4
+ var tableCompactCollapseHelpers_1 = require("./tableCompactCollapseHelpers");
5
+ var rowValue = (0, tableCompactCollapseHelper_data_1.getRowValueData)();
6
+ describe('applyCompactValuesCountConstraint tests', function () {
7
+ it('should not update row value if maxValuesCount is Infinity', function () {
8
+ var maxValuesCount = Infinity;
9
+ expect((0, tableCompactCollapseHelpers_1.applyCompactValuesCountConstraint)(maxValuesCount)(rowValue)).toEqual(rowValue);
10
+ });
11
+ it('should correctly apply constraints for maxValuesCount 1', function () {
12
+ var maxValuesCount = 1;
13
+ expect((0, tableCompactCollapseHelpers_1.applyCompactValuesCountConstraint)(maxValuesCount)(rowValue)).toEqual((0, tableCompactCollapseHelper_data_1.getRowValueWithConstraintsDataForMVC1)());
14
+ });
15
+ it('should correctly apply constraints for maxValuesCount 2', function () {
16
+ var maxValuesCount = 2;
17
+ expect((0, tableCompactCollapseHelpers_1.applyCompactValuesCountConstraint)(maxValuesCount)(rowValue)).toEqual((0, tableCompactCollapseHelper_data_1.getRowValueWithConstraintsDataForMVC2)());
18
+ });
19
+ it('should correctly apply constraints for maxValuesCount 3', function () {
20
+ var maxValuesCount = 3;
21
+ expect((0, tableCompactCollapseHelpers_1.applyCompactValuesCountConstraint)(maxValuesCount)(rowValue)).toEqual((0, tableCompactCollapseHelper_data_1.getRowValueWithConstraintsDataForMVC3)());
22
+ });
23
+ it('should correctly apply constraints for maxValuesCount 6', function () {
24
+ var maxValuesCount = 6;
25
+ expect((0, tableCompactCollapseHelpers_1.applyCompactValuesCountConstraint)(maxValuesCount)(rowValue)).toEqual((0, tableCompactCollapseHelper_data_1.getRowValueWithConstraintsDataForMVC6)());
26
+ });
27
+ });
@@ -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>) => boolean;
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;
@@ -7,14 +7,15 @@ var tableUtils_1 = require("react-components/dist/Table/tableUtils");
7
7
  var basicTable_1 = require("../../helpers/basicTable");
8
8
  var useCollapsibleTableRows_1 = require("../useCollapsibleTableRows");
9
9
  var useBasicTableCellRenderer = function (_a) {
10
- var rowsData = _a.rowsData, columnsData = _a.columnsData, getIdFromRowValue = _a.getIdFromRowValue, _b = _a.renderRowCell, renderRowCell = _b === void 0 ? basicTable_1.defaultRenderRowCell : _b, _c = _a.getRowCellHeight, getRowCellHeight = _c === void 0 ? basicTable_1.defaultGetRowCellHeight : _c, _d = _a.defaultRowHeight, defaultRowHeight = _d === void 0 ? 48 : _d, _e = _a.maxRowValuesCount, maxRowValuesCount = _e === void 0 ? Infinity : _e;
10
+ var rowsData = _a.rowsData, columnsData = _a.columnsData, getIdFromRowValue = _a.getIdFromRowValue, _b = _a.renderRowCell, renderRowCell = _b === void 0 ? basicTable_1.defaultRenderRowCell : _b, _c = _a.getRowCellHeight, getRowCellHeight = _c === void 0 ? basicTable_1.defaultGetRowCellHeight : _c, _d = _a.defaultRowHeight, defaultRowHeight = _d === void 0 ? 48 : _d, _e = _a.maxRowValuesCount, maxRowValuesCount = _e === void 0 ? Infinity : _e, applyMaxValuesCountConstraint = _a.applyMaxValuesCountConstraint;
11
11
  var _f = (0, useCollapsibleTableRows_1.useCollapsibleTableRows)({
12
12
  rowsData: rowsData,
13
13
  columnsData: columnsData,
14
14
  renderRowCell: renderRowCell,
15
15
  getRowCellHeight: getRowCellHeight,
16
16
  maxRowValuesCount: maxRowValuesCount,
17
- getIdFromRowValue: getIdFromRowValue
17
+ getIdFromRowValue: getIdFromRowValue,
18
+ applyMaxValuesCountConstraint: applyMaxValuesCountConstraint
18
19
  }), tableRowsData = _f.tableRowsData, collapseContextValue = _f.collapseContextValue;
19
20
  return (0, react_1.useMemo)(function () {
20
21
  var rowHeightCache = tableRowsData.reduce(function (cache, rowData) {
@@ -1,2 +1,3 @@
1
- export function getTableRowsData(rowValues: any, columnsData: any, renderRowCell: any, getRowCellHeight: any, getRowMaxValuesCount?: any, getIdFromRowValue?: (_: any, rowIndex: any) => any): any;
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;
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.getMaxRowValuesCount = exports.getTableRowsData = void 0;
14
+ exports.getIsRowCollapsibleFromMaxValuesCount = exports.getMaxRowValuesCount = exports.getTableRowsData = void 0;
15
15
  var ramda_1 = require("ramda");
16
16
  var mdm_sdk_1 = require("@reltio/mdm-sdk");
17
17
  var DefaultCellValueRenderer_1 = require("../../DefaultCellValueRenderer");
@@ -73,7 +73,7 @@ var areNestedValuesExceedingLimit = function (maxValuesCount) {
73
73
  return indexPath && indexPath.some(function (index) { return index > maxValuesCount - 1; });
74
74
  };
75
75
  };
76
- var getAllRowHiddenValues = function (rowValues, maxValuesCount) {
76
+ var getHiddenValues = function (rowValues, maxValuesCount) {
77
77
  if (maxValuesCount === void 0) { maxValuesCount = Infinity; }
78
78
  return rowValues.reduce(function (hiddenValues, _a) {
79
79
  var _b = _a.values, values = _b === void 0 ? [] : _b, indexPath = _a.indexPath;
@@ -86,21 +86,22 @@ var getAllRowHiddenValues = function (rowValues, maxValuesCount) {
86
86
  var adjustFirstWithHiddenValues = function (maxValuesCount) {
87
87
  if (maxValuesCount === void 0) { maxValuesCount = Infinity; }
88
88
  return function (rowValues) {
89
- var hiddenValues = getAllRowHiddenValues(rowValues, maxValuesCount);
90
- return (0, ramda_1.adjust)(0, (0, ramda_1.assoc)('allRowHiddenValues', hiddenValues), rowValues);
89
+ var hiddenValues = getHiddenValues(rowValues, maxValuesCount);
90
+ return (0, ramda_1.adjust)(0, (0, ramda_1.assoc)('hiddenValues', hiddenValues), rowValues);
91
91
  };
92
92
  };
93
- var applyValuesCountConstraint = function (maxValuesCount) {
93
+ var applyDefaultValuesCountConstraint = function (maxValuesCount) {
94
94
  return (0, ramda_1.unless)(function () { return maxValuesCount === Infinity; }, (0, ramda_1.map)((0, ramda_1.pipe)(adjustFirstWithHiddenValues(maxValuesCount), (0, ramda_1.reject)(areNestedValuesExceedingLimit(maxValuesCount)), (0, ramda_1.map)((0, ramda_1.evolve)({
95
95
  values: (0, ramda_1.slice)(0, maxValuesCount)
96
96
  })))));
97
97
  };
98
98
  var defaultGetIdFromRowValue = function (_, rowIndex) { return rowIndex; };
99
- var getTableRowsData = function (rowValues, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue) {
99
+ var getTableRowsData = function (rowValues, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue, applyMaxValuesCountConstraint) {
100
100
  if (getRowMaxValuesCount === void 0) { getRowMaxValuesCount = (0, ramda_1.always)(Infinity); }
101
101
  if (getIdFromRowValue === void 0) { getIdFromRowValue = defaultGetIdFromRowValue; }
102
+ applyMaxValuesCountConstraint = applyMaxValuesCountConstraint || applyDefaultValuesCountConstraint;
102
103
  return rowValues.map(function (rowValue, rowIndex) {
103
- return (0, ramda_1.pipe)(buildRowValues(rowValue), applyValuesCountConstraint(getRowMaxValuesCount(rowIndex)), calcRowSpans, calcHeights(columnsData, getRowCellHeight, rowIndex, rowValue), applyCellRenderer(columnsData, renderRowCell, rowIndex, rowValue), function (val) { return ({ data: val, id: getIdFromRowValue(rowValue, rowIndex) }); })(columnsData);
104
+ return (0, ramda_1.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);
104
105
  });
105
106
  };
106
107
  exports.getTableRowsData = getTableRowsData;
@@ -113,3 +114,11 @@ var getMaxRowValuesCount = function (columnsData, rowValue) {
113
114
  return (0, ramda_1.pipe)(buildRowValues(rowValue), ramda_1.values, calcMaxValuesCount)(columnsData);
114
115
  };
115
116
  exports.getMaxRowValuesCount = getMaxRowValuesCount;
117
+ var getHasHiddenAttributes = (0, ramda_1.pipe)(ramda_1.values, (0, ramda_1.chain)(ramda_1.identity), (0, ramda_1.chain)((0, ramda_1.pathOr)([], ['hiddenValues'])), ramda_1.length, (0, ramda_1.gt)(ramda_1.__, 0));
118
+ var getIsRowCollapsibleFromMaxValuesCount = function (columnsData, rowValue, maxValuesCount, applyMaxValuesCountConstraint) {
119
+ if (applyMaxValuesCountConstraint) {
120
+ return (0, ramda_1.pipe)(buildRowValues(rowValue), applyMaxValuesCountConstraint(maxValuesCount), getHasHiddenAttributes)(columnsData);
121
+ }
122
+ return getMaxRowValuesCount(columnsData, rowValue) > maxValuesCount;
123
+ };
124
+ exports.getIsRowCollapsibleFromMaxValuesCount = getIsRowCollapsibleFromMaxValuesCount;
@@ -251,7 +251,7 @@ describe('dataHelpers', function () {
251
251
  data: {
252
252
  'n1.a': [
253
253
  {
254
- allRowHiddenValues: [2, 3],
254
+ hiddenValues: [2, 3],
255
255
  values: [1],
256
256
  indexPath: [0],
257
257
  nestedKey: 'n1.0',
@@ -259,17 +259,17 @@ describe('dataHelpers', function () {
259
259
  }
260
260
  ],
261
261
  'n1.n2.b': [
262
- { values: [], allRowHiddenValues: [4, 5, 6], indexPath: [0], nestedKey: 'n1.0', rowSpan: 1 }
262
+ { values: [], hiddenValues: [4, 5, 6], indexPath: [0], nestedKey: 'n1.0', rowSpan: 1 }
263
263
  ],
264
- c: [{ allRowHiddenValues: [8, 9, 10], values: [7], rowSpan: 1 }],
265
- 'n1.d': [{ values: [], allRowHiddenValues: [], rowSpan: 1 }]
264
+ c: [{ hiddenValues: [8, 9, 10], values: [7], rowSpan: 1 }],
265
+ 'n1.d': [{ values: [], hiddenValues: [], rowSpan: 1 }]
266
266
  },
267
267
  id: 0
268
268
  }
269
269
  ]);
270
270
  expect(getRowMaxValuesCount).toHaveBeenCalledWith(0);
271
271
  });
272
- it('should apply allRowHiddenValues correctly if maxValuesCount more than 1', function () {
272
+ it('should apply hiddenValues correctly if maxValuesCount more than 1', function () {
273
273
  var rowValues = [
274
274
  {
275
275
  'n1.n2.a': [[[1, 2]], [[3, 4, 5]]]
@@ -287,7 +287,7 @@ describe('dataHelpers', function () {
287
287
  'n1.n2.a': [
288
288
  {
289
289
  values: [1, 2],
290
- allRowHiddenValues: [5],
290
+ hiddenValues: [5],
291
291
  indexPath: [0, 0],
292
292
  nestedKey: 'n1.0.n2.0',
293
293
  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>) => boolean;
16
+ getIsRowCollapsible: (rowValue: Record<string, unknown>) => any;
16
17
  getIsRowCollapsed: (rowIndex: number) => boolean;
17
18
  };
18
19
  };
@@ -7,14 +7,22 @@ var dataHelpers_1 = require("./dataHelpers");
7
7
  var useDidUpdateEffect_1 = require("../useDidUpdateEffect");
8
8
  var usePrevious_1 = require("../../hooks/usePrevious");
9
9
  var useCollapsibleTableRows = function (_a) {
10
- var rowsData = _a.rowsData, columnsData = _a.columnsData, renderRowCell = _a.renderRowCell, getRowCellHeight = _a.getRowCellHeight, maxRowValuesCount = _a.maxRowValuesCount, getIdFromRowValue = _a.getIdFromRowValue;
10
+ var rowsData = _a.rowsData, columnsData = _a.columnsData, renderRowCell = _a.renderRowCell, getRowCellHeight = _a.getRowCellHeight, maxRowValuesCount = _a.maxRowValuesCount, getIdFromRowValue = _a.getIdFromRowValue, applyMaxValuesCountConstraint = _a.applyMaxValuesCountConstraint;
11
11
  var _b = (0, react_1.useState)([]), expandedIndexes = _b[0], setExpandedIndexes = _b[1];
12
12
  var getRowMaxValuesCount = (0, react_1.useCallback)(function (rowIndex) {
13
13
  return expandedIndexes.includes(rowIndex) ? Infinity : maxRowValuesCount;
14
14
  }, [expandedIndexes, maxRowValuesCount]);
15
15
  var tableRowsData = (0, react_1.useMemo)(function () {
16
- return (0, dataHelpers_1.getTableRowsData)(rowsData, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue);
17
- }, [rowsData, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue]);
16
+ return (0, dataHelpers_1.getTableRowsData)(rowsData, columnsData, renderRowCell, getRowCellHeight, getRowMaxValuesCount, getIdFromRowValue, applyMaxValuesCountConstraint);
17
+ }, [
18
+ rowsData,
19
+ columnsData,
20
+ renderRowCell,
21
+ getRowCellHeight,
22
+ getRowMaxValuesCount,
23
+ getIdFromRowValue,
24
+ applyMaxValuesCountConstraint
25
+ ]);
18
26
  var toggleRowCollapse = (0, react_1.useCallback)(function (rowIndex) {
19
27
  setExpandedIndexes(function (expandedIndexes) {
20
28
  var index = expandedIndexes.findIndex((0, ramda_1.equals)(rowIndex));
@@ -22,8 +30,8 @@ var useCollapsibleTableRows = function (_a) {
22
30
  });
23
31
  }, []);
24
32
  var getIsRowCollapsible = (0, react_1.useCallback)(function (rowValue) {
25
- return (0, dataHelpers_1.getMaxRowValuesCount)(columnsData, rowValue) > maxRowValuesCount;
26
- }, [maxRowValuesCount, columnsData]);
33
+ return (0, dataHelpers_1.getIsRowCollapsibleFromMaxValuesCount)(columnsData, rowValue, maxRowValuesCount, applyMaxValuesCountConstraint);
34
+ }, [maxRowValuesCount, columnsData, applyMaxValuesCountConstraint]);
27
35
  var getIsRowCollapsed = (0, react_1.useCallback)(function (rowIndex) {
28
36
  return !expandedIndexes.includes(rowIndex);
29
37
  }, [expandedIndexes]);
@@ -69,11 +69,11 @@ describe('useCollapsibleTableRows tests', function () {
69
69
  };
70
70
  beforeAll(function () {
71
71
  jest.spyOn(dataHelpers, 'getTableRowsData');
72
- jest.spyOn(dataHelpers, 'getMaxRowValuesCount');
72
+ jest.spyOn(dataHelpers, 'getIsRowCollapsibleFromMaxValuesCount');
73
73
  });
74
74
  beforeEach(function () {
75
75
  dataHelpers.getTableRowsData.mockClear();
76
- dataHelpers.getMaxRowValuesCount.mockClear();
76
+ dataHelpers.getIsRowCollapsibleFromMaxValuesCount.mockClear();
77
77
  });
78
78
  it('should return collapsed table rows data by default', function () {
79
79
  var result = getCollapsibleTableRows().result;
@@ -98,9 +98,8 @@ describe('useCollapsibleTableRows tests', function () {
98
98
  });
99
99
  it('should return correct getIsRowCollapsible function for context', function () {
100
100
  var _a = getCollapsibleTableRows(), result = _a.result, rerender = _a.rerender;
101
- dataHelpers.getMaxRowValuesCount.mockReturnValueOnce(3);
102
101
  expect(result.current.collapseContextValue.getIsRowCollapsible(rowsData[0])).toBe(true);
103
- expect(dataHelpers.getMaxRowValuesCount).toHaveBeenCalledWith(columnsData, rowsData[0]);
102
+ expect(dataHelpers.getIsRowCollapsibleFromMaxValuesCount).toHaveBeenCalledWith(columnsData, rowsData[0], 1, undefined);
104
103
  rerender(__assign(__assign({}, initialProps), { maxRowValuesCount: 4 }));
105
104
  expect(result.current.collapseContextValue.getIsRowCollapsible(rowsData[0])).toBe(false);
106
105
  });
package/cjs/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/cjs/index.js CHANGED
@@ -20,7 +20,7 @@ exports.Popper = exports.MultipleInput = exports.ModeSwitcherSelect = exports.Mo
20
20
  exports.AsyncMountContext = exports.MdmModuleProvider = exports.withTableContext = exports.withFilterAtBottom = exports.withPercents = exports.withContext = exports.withDateRangeSelector = exports.withDragHandle = exports.withAsyncMount = exports.withTooltip = exports.LazyRenderer = exports.MetadataTypesSelector = exports.DateRangeSelector = exports.UpSetChart = exports.GaugeChart = exports.RelationEditor = exports.ReltioMap = exports.Marginator = exports.LightArrowTooltip = exports.ScrollableTabs = exports.VirtualGroupedList = exports.ViewMoreToggle = exports.VerticalHeadingsTable = exports.VerticalDivider = exports.AttributeTitle = exports.Spacer = exports.SimpleDropDownSelector = exports.SidePanelContentHeader = exports.SidePanel = exports.SidePanelEmptyState = exports.SideButtonsPanel = exports.SelectorWithOnlyOptionAutoSelect = exports.SelectionPopup = exports.WhiteSearchInput = exports.SearchInput = exports.ProfileResizablePanes = exports.ResizablePanes = exports.ReltioGridLayout = exports.RCTreeSwitchRenderer = exports.RCTreeLevelLines = exports.RCTree = exports.reactSortableTreeHelpers = exports.ReactSortableTree = exports.MultiSelect = exports.QueryBuilderRowsGroup = exports.QueryBuilderRow = exports.ProfileCard = exports.ProfileBand = exports.PotentialMatchReviewCard = exports.PopupWithArrow = void 0;
21
21
  exports.useAttributeValueConfigPermissions = exports.ConfigPermissionsContextProvider = exports.ConfigPermissionsContext = exports.useActionsHook = exports.ActionsHookProvider = exports.PageRequestsAbortingContext = exports.DependentLookupAutopopulationContext = exports.FeaturesContext = exports.LabelsContext = exports.UrlGeneratorsContext = exports.isHighlightedAttributeType = exports.isHighlightedErrorType = exports.ScrollType = exports.ScrollToElementProvider = exports.ScrollToElementContext = exports.SearchValueContext = exports.InterceptHandlersContext = exports.HighlightedValuesContext = exports.SnackbarContext = exports.SearchFiltersContext = exports.useReloadFacet = exports.ReloadFacetProvider = exports.useReloadAllFacets = exports.SandboxAPIContext = exports.EntityContext = exports.RelatedObjectUrisContext = exports.WorkflowTasksContext = exports.useEntityLoadingIndication = exports.EntityLoadingIndicationProvider = exports.EntityMarkerContext = exports.useAttributeExpanded = exports.ExpandedAttributesProvider = exports.useHighlightedCrosswalks = exports.useCrosswalkHighlight = exports.useCrosswalkFocus = exports.useCrosswalkColor = exports.CrosswalksDisplayProvider = exports.EntitiesMapContext = exports.IdContext = exports.ProfilePerspectiveViewContext = exports.usePerspectivesSettings = exports.PerspectivesSettingsContext = exports.PivotingAttributeContext = exports.UsersContext = exports.InitialCollaborationContextValue = exports.CollaborationContextProvider = exports.CollaborationContext = exports.BlockImageGalleryDialogContext = exports.PopupBoundariesContext = exports.HistoryDiffContext = void 0;
22
22
  exports.useKeyboardNavigation = exports.useDynamicRowCellHeight = exports.useClickableStyle = exports.BasicTableCellRenderer = exports.useBasicTableCellRenderer = exports.useHiddenAttributes = exports.useSavedSearchesRequest = exports.useRequestDCRReview = exports.useAutoFocus = exports.useExpandInvalidRelations = exports.useLayoutResetter = exports.useIsMountedRef = exports.useSnackbar = exports.useSavedStateForEntityType = exports.useReadableSearchState = exports.useEditableConnection = exports.useCustomScripts = exports.useMarkAsNotMatchRequest = exports.useMergeAllRequest = exports.usePagingSimulator = exports.useMatchesLoader = exports.useConfigPermissions = exports.useWhyDidYouUpdate = exports.useUsers = exports.useSavedState = exports.useSafePromise = exports.useRunOnceAfterValueInitialization = exports.useRelationsLoader = exports.useRelationTypeSelector = exports.usePrevious = exports.useDidUpdateEffect = exports.useCommentsEntitiesMap = exports.useCollaboration = exports.useAsyncMount = exports.useAPI = exports.useActions = exports.useMatchesColumnsData = exports.useScrollToAttributeError = exports.ThemeProvider = exports.ProfileTablesContext = exports.HiddenAttributesContext = exports.BasicTableContext = exports.BasicTableRowCollapseContext = exports.useDeleteUnmaskedAttributeForRelation = exports.useUnmaskedAttributeValue = exports.useUnmaskAttributeValue = exports.useMaskAttributeValue = exports.MaskedAttributesProvider = exports.useReloadData = exports.ReloadDataProvider = void 0;
23
- exports.mockComputedStyles = exports.FakeMouseEvent = exports.rerenderWrapper = exports.mockElementSizes = exports.fixClicksOnResizablePanes = exports.mockBasicTableSizing = exports.getMuiIconsByName = exports.getMuiIconByName = exports.deepFreeze = exports.awaitMockPromises = exports.TestStylesProvider = exports.TestPerspectivesSettingsProvider = exports.getAttributeSelectorItems = exports.mergeClasses = exports.isControlOrCommandPressed = exports.getValue = exports.getChecked = exports.showErrorMessage = exports.showDefaultErrorMessage = exports.enrichDataWithPercents = exports.defaultRenderRowCell = exports.defaultGetRowCellHeight = exports.columnFilterToMdmFilter = exports.buildColumnsSizeById = exports.buildColumnsFilter = exports.useDndBasicTableScrollModifier = exports.useDynamicYAxisWidth = exports.useFilterAutoFocus = exports.useSegmentationRequest = exports.resolveMarkers = exports.useMarkers = exports.useMaskedAttribute = void 0;
23
+ exports.mockComputedStyles = exports.FakeMouseEvent = exports.rerenderWrapper = exports.mockElementSizes = exports.fixClicksOnResizablePanes = exports.mockBasicTableSizing = exports.getMuiIconsByName = exports.getMuiIconByName = exports.deepFreeze = exports.awaitMockPromises = exports.TestStylesProvider = exports.TestPerspectivesSettingsProvider = exports.applyCompactValuesCountConstraint = exports.getAttributeSelectorItems = exports.mergeClasses = exports.isControlOrCommandPressed = exports.getValue = exports.getChecked = exports.showErrorMessage = exports.showDefaultErrorMessage = exports.enrichDataWithPercents = exports.defaultRenderRowCell = exports.defaultGetRowCellHeight = exports.columnFilterToMdmFilter = exports.buildColumnsSizeById = exports.buildColumnsFilter = exports.useDndBasicTableScrollModifier = exports.useDynamicYAxisWidth = exports.useFilterAutoFocus = exports.useSegmentationRequest = exports.resolveMarkers = exports.useMarkers = exports.useMaskedAttribute = void 0;
24
24
  // components
25
25
  var ActionButton_1 = require("./ActionButton");
26
26
  Object.defineProperty(exports, "ActionButton", { enumerable: true, get: function () { return ActionButton_1.ActionButton; } });
@@ -625,6 +625,8 @@ var classes_1 = require("./helpers/classes");
625
625
  Object.defineProperty(exports, "mergeClasses", { enumerable: true, get: function () { return classes_1.mergeClasses; } });
626
626
  var attributesSelector_1 = require("./helpers/attributesSelector");
627
627
  Object.defineProperty(exports, "getAttributeSelectorItems", { enumerable: true, get: function () { return attributesSelector_1.getAttributeSelectorItems; } });
628
+ var tableCompactCollapseHelpers_1 = require("./helpers/tableCompactCollapseHelpers");
629
+ Object.defineProperty(exports, "applyCompactValuesCountConstraint", { enumerable: true, get: function () { return tableCompactCollapseHelpers_1.applyCompactValuesCountConstraint; } });
628
630
  __exportStar(require("./types/preferences"), exports);
629
631
  __exportStar(require("./types"), exports);
630
632
  // constants