pixelize-design-library 2.3.1-beta.7 → 2.3.1-beta.9
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/dist/Components/Table/Table.js +53 -21
- package/dist/Components/Table/hooks/useTable.d.ts +1 -1
- package/dist/Components/Table/hooks/useTable.js +3 -2
- package/dist/Components/Table/settings/TableSettings.d.ts +2 -3
- package/dist/Components/Table/settings/TableSettings.js +3 -4
- package/package.json +1 -1
|
@@ -145,24 +145,46 @@ function Table(_a) {
|
|
|
145
145
|
// (search / filter / sort / page-size). Only used in grouped + groupLoadMore mode.
|
|
146
146
|
var _36 = (0, react_1.useState)([]), accumulatedRows = _36[0], setAccumulatedRows = _36[1];
|
|
147
147
|
var pendingLoadMoreRef = (0, react_1.useRef)(false);
|
|
148
|
+
// Pages loaded so far (1 = the initial page). The next page is derived from this
|
|
149
|
+
// counter — NOT from the deduped row count — so overlapping rows across pages
|
|
150
|
+
// (e.g. pinned rows that repeat on every page) don't stall the page index.
|
|
151
|
+
var loadedPagesRef = (0, react_1.useRef)(1);
|
|
148
152
|
(0, react_1.useEffect)(function () {
|
|
149
153
|
if (!groupLoadMore)
|
|
150
154
|
return;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
// eslint-disable-next-line no-console
|
|
156
|
+
console.log("[Table][loadMore] data change", {
|
|
157
|
+
incoming: tableData.length,
|
|
158
|
+
incomingIds: tableData.slice(0, 50).map(function (r) { return r.id; }),
|
|
159
|
+
accumulated: accumulatedRows.length,
|
|
160
|
+
newRows: tableData.filter(function (r) { return !new Set(accumulatedRows.map(function (a) { return a.id; })).has(r.id); }).length,
|
|
161
|
+
pending: pendingLoadMoreRef.current,
|
|
162
|
+
loadedPages: loadedPagesRef.current,
|
|
163
|
+
});
|
|
159
164
|
setAccumulatedRows(function (prev) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
if (prev.length === 0) {
|
|
166
|
+
loadedPagesRef.current = 1;
|
|
167
|
+
return tableData.slice();
|
|
168
|
+
}
|
|
169
|
+
var accIds = new Set(prev.map(function (r) { return r.id; }));
|
|
170
|
+
if (pendingLoadMoreRef.current) {
|
|
171
|
+
// A "Load more" is in flight. The parent may re-emit the SAME page (new
|
|
172
|
+
// array reference) on intermediate re-renders before the next page arrives,
|
|
173
|
+
// so only append + consume the flag once genuinely new rows show up.
|
|
174
|
+
var newRows = tableData.filter(function (r) { return !accIds.has(r.id); });
|
|
175
|
+
if (newRows.length === 0)
|
|
176
|
+
return prev; // same page re-emitted — keep waiting
|
|
177
|
+
pendingLoadMoreRef.current = false;
|
|
178
|
+
return __spreadArray(__spreadArray([], prev, true), newRows, true);
|
|
179
|
+
}
|
|
180
|
+
// Not a load-more: a re-emit of already-loaded rows keeps the accumulation
|
|
181
|
+
// (the parent re-renders the current page often). Genuinely new rows
|
|
182
|
+
// (search / filter / sort / page-size / reload) reset it.
|
|
183
|
+
var allKnown = tableData.length > 0 && tableData.every(function (r) { return accIds.has(r.id); });
|
|
184
|
+
if (allKnown)
|
|
185
|
+
return prev;
|
|
186
|
+
loadedPagesRef.current = 1; // fresh data set
|
|
187
|
+
return tableData.slice();
|
|
166
188
|
});
|
|
167
189
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
168
190
|
}, [tableData, groupLoadMore]);
|
|
@@ -180,9 +202,11 @@ function Table(_a) {
|
|
|
180
202
|
setDensityState(d);
|
|
181
203
|
savePreferences === null || savePreferences === void 0 ? void 0 : savePreferences(__assign(__assign({}, tablePreferences), { columns: columnsList, groupBy: groupByState !== null && groupByState !== void 0 ? groupByState : null, density: d }));
|
|
182
204
|
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
205
|
+
// Settings "Save": persist columns + group (+ current density) in ONE write so
|
|
206
|
+
// they don't clobber each other, and apply them locally.
|
|
207
|
+
var handleSettingsSave = function (cols, group) {
|
|
208
|
+
setGroupByState(group);
|
|
209
|
+
handleColumnPreferences(cols, { density: densityState, groupBy: group !== null && group !== void 0 ? group : null });
|
|
186
210
|
};
|
|
187
211
|
var _filteredData = (0, react_1.useMemo)(function () {
|
|
188
212
|
return (0, table_1.searchAndSortData)(filteredData, columnsSearch);
|
|
@@ -248,11 +272,19 @@ function Table(_a) {
|
|
|
248
272
|
if (isLoadingMore || isTableLoading || !hasMoreEffective)
|
|
249
273
|
return;
|
|
250
274
|
var chunk = loadMoreChunkSize !== null && loadMoreChunkSize !== void 0 ? loadMoreChunkSize : rowsPerPage;
|
|
251
|
-
//
|
|
252
|
-
//
|
|
253
|
-
var nextPage =
|
|
275
|
+
// Advance by page COUNT (not by deduped row count) so overlapping/pinned rows
|
|
276
|
+
// across pages don't keep us stuck on the same page.
|
|
277
|
+
var nextPage = loadedPagesRef.current + 1;
|
|
278
|
+
loadedPagesRef.current = nextPage;
|
|
254
279
|
var lastRecord = loadMoreBase.length > 0 ? loadMoreBase[loadMoreBase.length - 1] : undefined;
|
|
255
280
|
pendingLoadMoreRef.current = true;
|
|
281
|
+
// eslint-disable-next-line no-console
|
|
282
|
+
console.log("[Table][loadMore] click → request page", nextPage, {
|
|
283
|
+
chunk: chunk,
|
|
284
|
+
accumulated: loadMoreBase.length,
|
|
285
|
+
totalRecords: totalRecords,
|
|
286
|
+
hasMore: hasMoreEffective,
|
|
287
|
+
});
|
|
256
288
|
(_a = onPaginationRef.current) === null || _a === void 0 ? void 0 : _a.call(onPaginationRef, nextPage, chunk, lastRecord, "next");
|
|
257
289
|
};
|
|
258
290
|
var groupLoadMoreCaption = totalRecords > 0 ? "Showing ".concat(loadMoreBase.length, " of ").concat(totalRecords) : undefined;
|
|
@@ -368,7 +400,7 @@ function Table(_a) {
|
|
|
368
400
|
react_1.default.createElement(TableSearch_1.default, { onSearch: onGlobalSearch }),
|
|
369
401
|
isTableSettings && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
370
402
|
react_1.default.createElement(Divider_1.default, null),
|
|
371
|
-
react_1.default.createElement(TableSettings_1.default, { columns: columnsList, onSave: function (cols) { return
|
|
403
|
+
react_1.default.createElement(TableSettings_1.default, { columns: columnsList, onSave: function (cols, group) { return handleSettingsSave(cols, group); }, tableSettings: tableSettings, density: densityState, onDensityChange: handleDensityChange, groupBy: groupByState }))),
|
|
372
404
|
headerActions && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
373
405
|
react_1.default.createElement(Divider_1.default, null),
|
|
374
406
|
react_1.default.createElement(HeaderActions_1.default, { actions: headerActions, selections: selection }))),
|
|
@@ -41,7 +41,7 @@ declare const useTable: ({ tableBorderColor, data, isPagination, selections, onS
|
|
|
41
41
|
rowsPerPage: number;
|
|
42
42
|
setCurrentPage: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
43
43
|
columnsList: TableHeaderProps[];
|
|
44
|
-
handleColumnPreferences: (columns: any) => void;
|
|
44
|
+
handleColumnPreferences: (columns: any, extra?: Record<string, any>) => void;
|
|
45
45
|
isSelecting: boolean;
|
|
46
46
|
};
|
|
47
47
|
export default useTable;
|
|
@@ -187,10 +187,11 @@ var useTable = function (_a) {
|
|
|
187
187
|
(_a = onSelectionRef.current) === null || _a === void 0 ? void 0 : _a.call(onSelectionRef, selectedItems);
|
|
188
188
|
}
|
|
189
189
|
}, [tableData]);
|
|
190
|
-
var handleColumnPreferences = function (columns) {
|
|
190
|
+
var handleColumnPreferences = function (columns, extra) {
|
|
191
|
+
if (extra === void 0) { extra = {}; }
|
|
191
192
|
setColumnsList(columns);
|
|
192
193
|
savePreferences &&
|
|
193
|
-
savePreferences(__assign(__assign({}, tablePreferences), { columns: columns }));
|
|
194
|
+
savePreferences(__assign(__assign(__assign({}, tablePreferences), { columns: columns }), extra));
|
|
194
195
|
};
|
|
195
196
|
return {
|
|
196
197
|
tableData: tableData,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { TableDensity, TableProps } from "../TableProps";
|
|
3
|
-
declare const TableSettings: ({ columns, onSave, density, onDensityChange, groupBy,
|
|
3
|
+
declare const TableSettings: ({ columns, onSave, density, onDensityChange, groupBy, }: {
|
|
4
4
|
columns: TableProps["columns"];
|
|
5
|
-
onSave: (updatedColumns: TableProps["columns"]) => void;
|
|
5
|
+
onSave: (updatedColumns: TableProps["columns"], groupBy: string | number | undefined) => void;
|
|
6
6
|
tableSettings?: TableProps["tableSettings"];
|
|
7
7
|
density?: TableDensity;
|
|
8
8
|
onDensityChange?: (d: TableDensity) => void;
|
|
9
9
|
groupBy?: string | number;
|
|
10
|
-
onGroupByChange?: (value: string | number | undefined) => void;
|
|
11
10
|
}) => React.JSX.Element;
|
|
12
11
|
export default TableSettings;
|
|
@@ -71,7 +71,7 @@ var DENSITY_OPTIONS = [
|
|
|
71
71
|
];
|
|
72
72
|
var TableSettings = function (_a) {
|
|
73
73
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
74
|
-
var columns = _a.columns, onSave = _a.onSave, _p = _a.density, density = _p === void 0 ? "normal" : _p, onDensityChange = _a.onDensityChange, groupBy = _a.groupBy
|
|
74
|
+
var columns = _a.columns, onSave = _a.onSave, _p = _a.density, density = _p === void 0 ? "normal" : _p, onDensityChange = _a.onDensityChange, groupBy = _a.groupBy;
|
|
75
75
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
76
76
|
var childInputMethodsRef = (0, react_2.useRef)({});
|
|
77
77
|
var _q = (0, react_2.useState)(false), settingsOpen = _q[0], setSettingsOpen = _q[1];
|
|
@@ -80,10 +80,9 @@ var TableSettings = function (_a) {
|
|
|
80
80
|
// Group selection is applied on Save (not live), per "click Apply to group".
|
|
81
81
|
var _t = (0, react_2.useState)(groupBy), selectedGroup = _t[0], setSelectedGroup = _t[1];
|
|
82
82
|
var handleSave = (0, react_2.useCallback)(function () {
|
|
83
|
-
onSave(items);
|
|
84
|
-
onGroupByChange === null || onGroupByChange === void 0 ? void 0 : onGroupByChange(selectedGroup);
|
|
83
|
+
onSave(items, selectedGroup);
|
|
85
84
|
setSettingsOpen(false);
|
|
86
|
-
}, [onSave, items,
|
|
85
|
+
}, [onSave, items, selectedGroup]);
|
|
87
86
|
var handleOpen = (0, react_2.useCallback)(function () {
|
|
88
87
|
setItems(columns);
|
|
89
88
|
setSelectedGroup(groupBy);
|