pixelize-design-library 2.3.1-beta.5 → 2.3.1-beta.6
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.
|
@@ -131,6 +131,32 @@ function Table(_a) {
|
|
|
131
131
|
// Grouping is chosen by the user in Table Settings > Group and persisted to
|
|
132
132
|
// preferences (`json.groupBy`); there is no `groupBy` prop.
|
|
133
133
|
var _35 = (0, react_1.useState)(undefined), groupByState = _35[0], setGroupByState = _35[1];
|
|
134
|
+
// Grouped "Load more" accumulates pages here so loading more ADDS rows to the
|
|
135
|
+
// groups (server pagination replaces `data` each fetch). Reset on fresh loads
|
|
136
|
+
// (search / filter / sort / page-size). Only used in grouped + groupLoadMore mode.
|
|
137
|
+
var _36 = (0, react_1.useState)([]), accumulatedRows = _36[0], setAccumulatedRows = _36[1];
|
|
138
|
+
var pendingLoadMoreRef = (0, react_1.useRef)(false);
|
|
139
|
+
(0, react_1.useEffect)(function () {
|
|
140
|
+
if (!groupLoadMore)
|
|
141
|
+
return;
|
|
142
|
+
if (pendingLoadMoreRef.current) {
|
|
143
|
+
pendingLoadMoreRef.current = false;
|
|
144
|
+
setAccumulatedRows(function (prev) {
|
|
145
|
+
var seen = new Set(prev.map(function (r) { return r.id; }));
|
|
146
|
+
var merged = prev.slice();
|
|
147
|
+
for (var _i = 0, tableData_1 = tableData; _i < tableData_1.length; _i++) {
|
|
148
|
+
var r = tableData_1[_i];
|
|
149
|
+
if (!seen.has(r.id))
|
|
150
|
+
merged.push(r);
|
|
151
|
+
}
|
|
152
|
+
return merged;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
setAccumulatedRows(tableData);
|
|
157
|
+
}
|
|
158
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
159
|
+
}, [tableData, groupLoadMore]);
|
|
134
160
|
(0, react_1.useEffect)(function () {
|
|
135
161
|
if (tablePreferences === null || tablePreferences === void 0 ? void 0 : tablePreferences.density)
|
|
136
162
|
setDensityState(tablePreferences.density);
|
|
@@ -159,19 +185,22 @@ function Table(_a) {
|
|
|
159
185
|
var isGrouped = !!groupByState;
|
|
160
186
|
// Infinite scroll (server mode, not grouped): load more on scroll-near-bottom.
|
|
161
187
|
var canInfinite = infiniteScroll && !isGrouped;
|
|
162
|
-
// Grouped "Load more":
|
|
188
|
+
// Grouped "Load more": the accumulated pages back the grouped board so loading
|
|
189
|
+
// more grows the groups instead of replacing them.
|
|
190
|
+
var loadMoreBase = isGrouped && groupLoadMore ? accumulatedRows : tableData;
|
|
163
191
|
var hasMoreEffective = typeof hasMore === "boolean"
|
|
164
192
|
? hasMore
|
|
165
193
|
: isServerPagination
|
|
166
|
-
?
|
|
194
|
+
? loadMoreBase.length < totalRecords
|
|
167
195
|
: false;
|
|
168
196
|
var canGroupLoadMore = isGrouped && groupLoadMore && hasMoreEffective;
|
|
169
197
|
var groupPalette = (0, react_1.useMemo)(function () { return (0, table_1.buildTablePalette)(theme); }, [theme]);
|
|
170
198
|
var groupedSource = (0, react_1.useMemo)(function () {
|
|
171
199
|
if (!isGrouped)
|
|
172
200
|
return [];
|
|
173
|
-
|
|
174
|
-
|
|
201
|
+
var src = groupLoadMore ? accumulatedRows : tableData;
|
|
202
|
+
return (0, table_1.searchAndSortData)((0, table_1.SortMultiColumnData)(src, columnsSort), columnsSearch);
|
|
203
|
+
}, [isGrouped, groupLoadMore, accumulatedRows, tableData, columnsSort, columnsSearch]);
|
|
175
204
|
var renderGroups = (0, react_1.useMemo)(function () {
|
|
176
205
|
if (!isGrouped)
|
|
177
206
|
return undefined;
|
|
@@ -210,11 +239,14 @@ function Table(_a) {
|
|
|
210
239
|
if (isLoadingMore || isTableLoading || !hasMoreEffective)
|
|
211
240
|
return;
|
|
212
241
|
var chunk = loadMoreChunkSize !== null && loadMoreChunkSize !== void 0 ? loadMoreChunkSize : rowsPerPage;
|
|
213
|
-
|
|
214
|
-
|
|
242
|
+
// Next page is derived from how many rows we've already accumulated, so each
|
|
243
|
+
// click advances (fixes "always fromIndex 2") and the parent can replace `data`.
|
|
244
|
+
var nextPage = Math.floor(loadMoreBase.length / (chunk || 1)) + 1;
|
|
245
|
+
var lastRecord = loadMoreBase.length > 0 ? loadMoreBase[loadMoreBase.length - 1] : undefined;
|
|
246
|
+
pendingLoadMoreRef.current = true;
|
|
215
247
|
(_a = onPaginationRef.current) === null || _a === void 0 ? void 0 : _a.call(onPaginationRef, nextPage, chunk, lastRecord, "next");
|
|
216
248
|
};
|
|
217
|
-
var groupLoadMoreCaption = totalRecords > 0 ? "Showing ".concat(
|
|
249
|
+
var groupLoadMoreCaption = totalRecords > 0 ? "Showing ".concat(loadMoreBase.length, " of ").concat(totalRecords) : undefined;
|
|
218
250
|
var tablePaginationText = (0, react_1.useMemo)(function () { return isServerPagination
|
|
219
251
|
? "".concat(startRow + 1, " - ").concat(Math.min(startRow + rowsPerPage, totalRecords), " of ").concat(totalRecords)
|
|
220
252
|
: "".concat(startRow + 1, " - ").concat(endRow > tableData.length ? tableData.length : endRow, " of ").concat(tableData.length); }, [startRow, rowsPerPage, totalRecords, endRow, tableData.length]);
|