@wavemaker/react-runtime 11.14.2-rc.6311 → 11.15.0-1.246
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/actions/base-action.js +5 -7
- package/actions/login-action.js +7 -8
- package/actions/logout-action.js +5 -7
- package/actions/navigation-action.js +73 -18
- package/actions/notification-action.js +22 -8
- package/actions/timer-action.js +13 -15
- package/actions/toast.js +4 -2
- package/actions/toast.service.js +1 -2
- package/components/advanced/carousel/index.js +1 -1
- package/components/advanced/carousel/template.js +1 -1
- package/components/basic/anchor/index.js +31 -11
- package/components/basic/html/index.js +115 -24
- package/components/basic/icon/index.js +2 -1
- package/components/basic/iframe/index.js +2 -1
- package/components/basic/label/index.js +12 -9
- package/components/basic/message/index.js +12 -3
- package/components/basic/picture/index.js +11 -4
- package/components/basic/progress-bar/index.js +4 -1
- package/components/basic/progress-circle/index.js +34 -28
- package/components/basic/progress-circle/props.js +10 -2
- package/components/basic/richtexteditor/index.js +95 -94
- package/components/basic/search/index.js +401 -156
- package/components/basic/search/providers.js +126 -61
- package/components/basic/spinner/index.js +2 -1
- package/components/basic/tree/index.js +34 -34
- package/components/basic/tree/utils.js +10 -4
- package/components/chart/components/barColumnChart/index.js +36 -33
- package/components/chart/components/bubbleChart/index.js +35 -25
- package/components/chart/components/chartLegend/utils.js +2 -1
- package/components/chart/components/cumulativeLineChart/index.js +30 -26
- package/components/chart/components/lineAreaChart/index.js +50 -32
- package/components/chart/components/pieDonutChart/index.js +13 -4
- package/components/chart/hooks/useXAxisConfig.js +15 -8
- package/components/chart/index.js +223 -53
- package/components/chart/utils.js +12 -1
- package/components/constants.js +5 -2
- package/components/container/accordion/accordion-pane/index.js +17 -12
- package/components/container/accordion/index.js +9 -4
- package/components/container/alignment-utils.js +56 -1
- package/components/container/index.js +49 -20
- package/components/container/panel/components/panel-header/index.js +3 -4
- package/components/container/panel/index.js +15 -10
- package/components/container/repeat-template/index.js +33 -0
- package/components/container/tabs/index.js +83 -14
- package/components/container/tabs/tab-pane/index.js +33 -10
- package/components/container/tabs/utils.js +51 -0
- package/components/container/wizard/components/StepComponents.js +2 -1
- package/components/container/wizard/components/WizardStep.js +2 -1
- package/components/container/wizard/index.js +64 -35
- package/components/container/wizard/utils.js +46 -1
- package/components/container/wizard/wizard-step/index.js +11 -1
- package/components/data/card/card-content/index.js +1 -1
- package/components/data/form/base-form/index.js +985 -183
- package/components/data/form/base-form/props.js +3 -1
- package/components/data/form/base-form/utils.js +159 -1
- package/components/data/form/dynamic-fields/constant.js +53 -0
- package/components/data/form/dynamic-fields/index.js +10 -45
- package/components/data/form/dynamic-fields/utils.js +37 -2
- package/components/data/form/form-action/index.js +5 -4
- package/components/data/form/form-context.js +5 -1
- package/components/data/form/form-controller/utils.js +84 -0
- package/components/data/form/form-controller/validation-contrustor.js +402 -189
- package/components/data/form/form-controller/withFormController.js +191 -52
- package/components/data/form/form-field/base-field.js +67 -45
- package/components/data/form/form-field/index.js +28 -5
- package/components/data/form/form-header/index.js +3 -4
- package/components/data/form/index.js +20 -1
- package/components/data/list/components/ListDND.js +2 -1
- package/components/data/list/components/ListItem.js +6 -2
- package/components/data/list/components/ListItemWithTemplate.js +46 -2
- package/components/data/list/components/ListItems.js +17 -26
- package/components/data/list/components/ListPagination.js +3 -3
- package/components/data/list/components/StandardListItems.js +3 -4
- package/components/data/list/hooks/useListEffects.js +55 -14
- package/components/data/list/hooks/useListEventHandlers.js +3 -1
- package/components/data/list/hooks/useListState.js +3 -1
- package/components/data/list/hooks/usePaginatedGroupedData.js +18 -5
- package/components/data/list/index.js +74 -55
- package/components/data/list/utils/list-helpers.js +73 -35
- package/components/data/list/utils/list-widget-methods.js +138 -95
- package/components/data/live-filter/index.js +26 -15
- package/components/data/live-form/index.js +51 -18
- package/components/data/live-form/props.js +1 -1
- package/components/data/pagination/components/BasicPagination.js +71 -16
- package/components/data/pagination/components/PageSizeSelector.js +8 -3
- package/components/data/pagination/components/TotalRecords.js +1 -5
- package/components/data/pagination/hooks/usePagination.js +349 -66
- package/components/data/pagination/index.js +137 -19
- package/components/data/table/components/AddNewRow.js +5 -1
- package/components/data/table/components/EditableCell.js +2 -2
- package/components/data/table/components/RowCells.js +64 -0
- package/components/data/table/components/RowExpansionButton.js +2 -2
- package/components/data/table/components/SummaryCell.js +111 -0
- package/components/data/table/components/SummaryRow.js +54 -0
- package/components/data/table/components/SummaryRowFooter.js +46 -0
- package/components/data/table/components/TableBody.js +61 -59
- package/components/data/table/components/TableDataRow.js +109 -0
- package/components/data/table/components/TableFilters.js +225 -121
- package/components/data/table/components/TableHeader.js +291 -23
- package/components/data/table/components/TablePanelHeading.js +139 -8
- package/components/data/table/components/index.js +22 -1
- package/components/data/table/hooks/use-edited-rows.js +141 -0
- package/components/data/table/hooks/useCellState.js +5 -12
- package/components/data/table/hooks/useFormWidget.js +58 -52
- package/components/data/table/hooks/usePaginationState.js +45 -24
- package/components/data/table/hooks/usePanelStructure.js +4 -4
- package/components/data/table/hooks/useRowHandlers.js +39 -5
- package/components/data/table/hooks/useRowSelection.js +244 -50
- package/components/data/table/hooks/useServerSideSorting.js +81 -37
- package/components/data/table/hooks/useTableColumns.js +211 -118
- package/components/data/table/hooks/useTableData.js +54 -9
- package/components/data/table/hooks/useTableEdit.js +272 -97
- package/components/data/table/hooks/useTableEffects.js +31 -13
- package/components/data/table/hooks/useTableFilter.js +1 -1
- package/components/data/table/hooks/useTableInitialization.js +23 -22
- package/components/data/table/hooks/useTableState.js +11 -5
- package/components/data/table/hooks/useTableStateManager.js +140 -65
- package/components/data/table/index.js +637 -274
- package/components/data/table/live-table/index.js +54 -22
- package/components/data/table/table-action/index.js +1 -1
- package/components/data/table/table-group/index.js +26 -0
- package/components/data/table/table-row-action/index.js +32 -18
- package/components/data/table/utils/buildSelectionColumns.js +12 -21
- package/components/data/table/utils/columnBuilder.js +29 -14
- package/components/data/table/utils/columnProxy.js +68 -1
- package/components/data/table/utils/constants.js +6 -2
- package/components/data/table/utils/crud-handlers.js +68 -63
- package/components/data/table/utils/groupHeaderUtils.js +102 -0
- package/components/data/table/utils/index.js +210 -21
- package/components/data/table/utils/renderDisplayCell.js +6 -6
- package/components/data/table/utils/selectionUtils.js +25 -26
- package/components/data/table/utils/validation.js +1 -0
- package/components/data/utils/filter-field-util.js +3 -3
- package/components/dialogs/alert-dialog/index.js +1 -1
- package/components/dialogs/confirm-dialog/index.js +1 -1
- package/components/dialogs/dialog/index.js +4 -1
- package/components/dialogs/dialog-content/index.js +3 -1
- package/components/dialogs/dialog-header/index.js +2 -2
- package/components/dialogs/iframe-dialog/index.js +11 -5
- package/components/dialogs/index.js +1 -1
- package/components/dialogs/login-dialog/index.js +1 -1
- package/components/dialogs/page-dialog/index.js +1 -1
- package/components/form/button/index.js +33 -7
- package/components/input/calendar/index.js +18 -6
- package/components/input/chips/index.js +99 -28
- package/components/input/chips/utils.js +34 -4
- package/components/input/color-picker/index.js +74 -25
- package/components/input/composite/index.js +3 -3
- package/components/input/currency/index.js +35 -49
- package/components/input/default/checkbox/index.js +23 -28
- package/components/input/default/checkboxset/index.js +38 -18
- package/components/input/default/checkboxset/utils.js +30 -0
- package/components/input/default/radioset/index.js +36 -39
- package/components/input/default/switch/index.js +30 -13
- package/components/input/epoch/date/index.js +130 -69
- package/components/input/epoch/date/utils.js +94 -1
- package/components/input/epoch/datetime/index.js +72 -22
- package/components/input/epoch/datetime/utils.js +49 -10
- package/components/input/epoch/time/index.js +68 -19
- package/components/input/epoch/time/utils.js +62 -14
- package/components/input/fileupload/Utils.js +12 -7
- package/components/input/fileupload/components/MultiUpload.js +2 -6
- package/components/input/fileupload/components/SingleUpload.js +3 -7
- package/components/input/fileupload/index.js +6 -10
- package/components/input/fileupload/useFileUpload.js +16 -5
- package/components/input/number/index.js +158 -43
- package/components/input/rating/index.js +90 -7
- package/components/input/select/index.js +209 -72
- package/components/input/slider/index.js +84 -26
- package/components/input/text/index.js +38 -18
- package/components/input/text/util.js +283 -130
- package/components/input/textarea/index.js +13 -10
- package/components/input/upload/index.js +124 -0
- package/components/input/upload/props.js +5 -0
- package/components/input/util/index.js +11 -0
- package/components/navbar/index.js +51 -3
- package/components/navbar/nav/index.js +46 -16
- package/components/navbar/nav-item/index.js +11 -5
- package/components/navigation/menu/components/ListItems.js +3 -0
- package/components/navigation/menu/constants.js +2 -1
- package/components/navigation/menu/hooks/useHoverState.hook.js +48 -0
- package/components/navigation/menu/hooks/useKeyboardMovements.hook.js +37 -0
- package/components/navigation/menu/hooks/useTransformedDataset.hook.js +15 -0
- package/components/navigation/menu/index.js +326 -188
- package/components/navigation/menu/utils/action-task.js +14 -0
- package/components/navigation/menu/utils/role-filter.js +76 -0
- package/components/navigation/popover/index.js +105 -32
- package/components/page/partial-container/index.js +34 -5
- package/components/prefab/index.js +2 -4
- package/context/PrefabContext.js +10 -6
- package/context/WidgetProvider.js +30 -31
- package/core/app.service.js +1 -1
- package/core/constants/events.js +57 -1
- package/core/dialog.service.js +1 -2
- package/core/event-notifier.js +1 -2
- package/core/formatter/array-formatters.js +33 -0
- package/core/formatter/date-formatters.js +2 -4
- package/core/formatter/index.js +2 -1
- package/core/formatter/number-formatters.js +5 -10
- package/core/formatter/security-formatters.js +2 -4
- package/core/formatter/string-formatters.js +3 -6
- package/core/proxy-service.js +85 -13
- package/core/script-registry.js +108 -48
- package/core/util/common.js +4 -4
- package/core/util/compare.js +30 -0
- package/core/util/dom.js +8 -8
- package/core/util/index.js +16 -6
- package/core/util/safe-is-equal.js +156 -0
- package/core/util/security.js +1 -2
- package/core/util/utils.js +16 -7
- package/higherOrder/BaseApp.js +108 -65
- package/higherOrder/BaseDateTime.js +31 -13
- package/higherOrder/BasePage.js +268 -144
- package/higherOrder/BasePartial.js +1 -1
- package/higherOrder/BasePrefab.js +33 -15
- package/higherOrder/DataNav.js +99 -16
- package/higherOrder/helper.js +41 -3
- package/higherOrder/withBaseWrapper.js +41 -28
- package/hooks/useAuth.js +11 -5
- package/hooks/useHttp.js +280 -94
- package/mui-config/theme-provider.js +1 -1
- package/mui-config/theme.js +1 -1
- package/package-lock.json +840 -740
- package/package.json +8 -8
- package/store/bindActions/i18nActions.js +18 -0
- package/store/index.js +3 -1
- package/store/slices/appConfigSlice.js +2 -2
- package/store/slices/authSlice.js +31 -28
- package/store/slices/i18nSlice.js +2 -2
- package/store/slices/navigationSlice.js +35 -0
- package/store/viewport.service.js +255 -0
- package/utils/attr.js +35 -0
- package/utils/dataset-util.js +1 -2
- package/utils/form-state.util.js +43 -12
- package/utils/form-utils.js +47 -2
- package/utils/format-util.js +28 -13
- package/utils/page-params-util.js +33 -1
- package/utils/state-persistance.js +72 -13
- package/utils/transformedDataset-utils.js +35 -24
- package/variables/base-variable.js +12 -14
- package/variables/crud-variable.js +225 -0
- package/variables/live-variable.js +56 -20
- package/variables/metadata.service.js +123 -0
- package/variables/model-variable.js +21 -15
- package/variables/service-variable.js +88 -83
|
@@ -21,6 +21,33 @@ var isDataSourceHasPaging = function isDataSourceHasPaging(datasource) {
|
|
|
21
21
|
var calculatePagingValues = function calculatePagingValues(dataSize, maxResults) {
|
|
22
22
|
return dataSize > maxResults ? Math.ceil(dataSize / maxResults) : dataSize < 0 ? 0 : 1;
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
// Utility function to create a dummy synthetic event when no event is available
|
|
26
|
+
var createDummyEvent = function createDummyEvent() {
|
|
27
|
+
var eventName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "synthetic";
|
|
28
|
+
return {
|
|
29
|
+
bubbles: false,
|
|
30
|
+
cancelable: false,
|
|
31
|
+
currentTarget: null,
|
|
32
|
+
defaultPrevented: false,
|
|
33
|
+
eventPhase: 0,
|
|
34
|
+
isTrusted: false,
|
|
35
|
+
nativeEvent: new Event(eventName),
|
|
36
|
+
target: null,
|
|
37
|
+
timeStamp: Date.now(),
|
|
38
|
+
type: eventName,
|
|
39
|
+
// Dynamic type based on the event being triggered
|
|
40
|
+
isDefaultPrevented: function isDefaultPrevented() {
|
|
41
|
+
return false;
|
|
42
|
+
},
|
|
43
|
+
isPropagationStopped: function isPropagationStopped() {
|
|
44
|
+
return false;
|
|
45
|
+
},
|
|
46
|
+
persist: function persist() {},
|
|
47
|
+
preventDefault: function preventDefault() {},
|
|
48
|
+
stopPropagation: function stopPropagation() {}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
24
51
|
var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
25
52
|
var _listener$Widgets;
|
|
26
53
|
var dataset = _ref.dataset,
|
|
@@ -62,15 +89,16 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
62
89
|
dataState = _useState2[0],
|
|
63
90
|
setDataState = _useState2[1];
|
|
64
91
|
|
|
65
|
-
//
|
|
92
|
+
// Accumulated data state - used for both Scroll and On-Demand navigation
|
|
93
|
+
// Both modes need to accumulate data as user loads more pages
|
|
66
94
|
var _useState3 = (0, _react.useState)({
|
|
67
95
|
accumulatedData: [],
|
|
68
96
|
lastLoadedPage: 0,
|
|
69
|
-
isAccumulating: navigation === "Scroll",
|
|
97
|
+
isAccumulating: navigation === "Scroll" || navigation === "On-Demand",
|
|
70
98
|
isInitialized: false
|
|
71
99
|
}),
|
|
72
|
-
|
|
73
|
-
|
|
100
|
+
accumulatingState = _useState3[0],
|
|
101
|
+
setAccumulatingState = _useState3[1];
|
|
74
102
|
|
|
75
103
|
// Navigation disable states - consolidated for better performance
|
|
76
104
|
var _useState4 = (0, _react.useState)({
|
|
@@ -84,16 +112,18 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
84
112
|
disableStates = _useState4[0],
|
|
85
113
|
setDisableStates = _useState4[1];
|
|
86
114
|
var isFetchingRef = (0, _react.useRef)(false);
|
|
115
|
+
var isResettingRef = (0, _react.useRef)(false); // Track if we're currently resetting accumulated data
|
|
87
116
|
|
|
88
|
-
// Refs for
|
|
117
|
+
// Refs for accumulated data (Scroll and On-Demand)
|
|
89
118
|
var observerRef = (0, _react.useRef)(null);
|
|
90
119
|
var sentinelRef = (0, _react.useRef)(null);
|
|
91
|
-
var
|
|
120
|
+
var accumulatingStateRef = (0, _react.useRef)(accumulatingState);
|
|
121
|
+
var sentinelHasLeftViewportRef = (0, _react.useRef)(true); // Track if sentinel has left viewport after View Less
|
|
92
122
|
|
|
93
123
|
// Keep ref in sync with state
|
|
94
124
|
(0, _react.useEffect)(function () {
|
|
95
|
-
|
|
96
|
-
}, [
|
|
125
|
+
accumulatingStateRef.current = accumulatingState;
|
|
126
|
+
}, [accumulatingState]);
|
|
97
127
|
|
|
98
128
|
// Memoized computed values for better performance
|
|
99
129
|
var isFirstPage = (0, _react.useMemo)(function () {
|
|
@@ -114,7 +144,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
114
144
|
}, [paginationState.currentPage, paginationState.pageCount, paginationMeta]);
|
|
115
145
|
|
|
116
146
|
// Navigation controls
|
|
117
|
-
var allowedNavControls = ["Basic", "Classic", "Pager", "Scroll"];
|
|
147
|
+
var allowedNavControls = ["Basic", "Classic", "Pager", "Scroll", "On-Demand"];
|
|
118
148
|
var getValidNavControl = function getValidNavControl(nav) {
|
|
119
149
|
return allowedNavControls.includes(nav) ? nav : "Basic";
|
|
120
150
|
};
|
|
@@ -157,15 +187,15 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
157
187
|
return Promise.resolve(result).then(function (response) {
|
|
158
188
|
isFetchingRef.current = false;
|
|
159
189
|
|
|
160
|
-
// For
|
|
190
|
+
// For accumulating mode (Scroll/On-Demand), we need to accumulate data instead of replacing
|
|
161
191
|
if (isScrollMode && response && response.data) {
|
|
162
192
|
// Get the new accumulated data using ref to avoid circular dependency
|
|
163
|
-
var currentAccumulatedData =
|
|
193
|
+
var currentAccumulatedData = accumulatingStateRef.current.accumulatedData;
|
|
164
194
|
|
|
165
195
|
// Ensure unique row IDs using the existing utility
|
|
166
196
|
var newDataWithIds = (0, _utils.addUniqueRowIds)(response.data);
|
|
167
197
|
var newAccumulatedData = [].concat((0, _toConsumableArray2["default"])(currentAccumulatedData), (0, _toConsumableArray2["default"])(newDataWithIds));
|
|
168
|
-
|
|
198
|
+
setAccumulatingState(function (prev) {
|
|
169
199
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
170
200
|
accumulatedData: newAccumulatedData,
|
|
171
201
|
lastLoadedPage: page
|
|
@@ -205,12 +235,53 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
205
235
|
return Promise.resolve();
|
|
206
236
|
}, [datasource, isServerSidePagination, datasourceInvokeOptions]);
|
|
207
237
|
|
|
208
|
-
// Function to load more data for
|
|
209
|
-
var loadMoreData = (0, _react.useCallback)(function () {
|
|
210
|
-
|
|
238
|
+
// Function to load more data for Scroll and On-Demand navigation
|
|
239
|
+
var loadMoreData = (0, _react.useCallback)(function (event) {
|
|
240
|
+
// Support both Scroll and On-Demand navigation
|
|
241
|
+
var isAccumulatingMode = navigation === "Scroll" || navigation === "On-Demand";
|
|
242
|
+
if (!isAccumulatingMode || isLastPage || isFetchingRef.current) {
|
|
211
243
|
return;
|
|
212
244
|
}
|
|
213
|
-
|
|
245
|
+
|
|
246
|
+
// For client-side pagination (non-server), just show more items
|
|
247
|
+
if (!isServerSidePagination) {
|
|
248
|
+
var currentVisible = accumulatingStateRef.current.accumulatedData.length;
|
|
249
|
+
var totalAvailable = dataState.fullData.length;
|
|
250
|
+
var nextBatchSize = paginationState.currentMaxResults;
|
|
251
|
+
var newVisibleCount = Math.min(currentVisible + nextBatchSize, totalAvailable);
|
|
252
|
+
|
|
253
|
+
// Get next batch of data
|
|
254
|
+
var nextBatch = dataState.fullData.slice(currentVisible, newVisibleCount);
|
|
255
|
+
var newAccumulatedData = [].concat((0, _toConsumableArray2["default"])(accumulatingStateRef.current.accumulatedData), (0, _toConsumableArray2["default"])(nextBatch));
|
|
256
|
+
setAccumulatingState(function (prev) {
|
|
257
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
258
|
+
accumulatedData: newAccumulatedData,
|
|
259
|
+
lastLoadedPage: prev.lastLoadedPage + 1
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Update the result to show accumulated data
|
|
264
|
+
setDataState(function (prev) {
|
|
265
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
266
|
+
result: newAccumulatedData
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// Update current page
|
|
271
|
+
var _nextPage = accumulatingStateRef.current.lastLoadedPage + 1;
|
|
272
|
+
setPaginationState(function (prev) {
|
|
273
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
274
|
+
currentPage: _nextPage
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
if (onPaginationChange) {
|
|
278
|
+
onPaginationChange(event || createDummyEvent("paginationchange"), widgetInstance, _nextPage);
|
|
279
|
+
}
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Server-side pagination
|
|
284
|
+
var nextPage = accumulatingStateRef.current.lastLoadedPage + 1;
|
|
214
285
|
if (setIsLoadingMore) {
|
|
215
286
|
setIsLoadingMore(true);
|
|
216
287
|
}
|
|
@@ -221,7 +292,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
221
292
|
});
|
|
222
293
|
});
|
|
223
294
|
if (onPaginationChange) {
|
|
224
|
-
onPaginationChange(
|
|
295
|
+
onPaginationChange(event || createDummyEvent("paginationchange"), widgetInstance, nextPage);
|
|
225
296
|
}
|
|
226
297
|
if (setIsLoadingMore) {
|
|
227
298
|
setIsLoadingMore(false);
|
|
@@ -231,7 +302,115 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
231
302
|
setIsLoadingMore(false);
|
|
232
303
|
}
|
|
233
304
|
});
|
|
234
|
-
}, [navigation, isServerSidePagination, isLastPage, setIsLoadingMore, datasourceInvoke, paginationState.currentMaxResults, onPaginationChange, widgetInstance]);
|
|
305
|
+
}, [navigation, isServerSidePagination, isLastPage, setIsLoadingMore, datasourceInvoke, paginationState.currentMaxResults, onPaginationChange, widgetInstance, dataState.fullData]);
|
|
306
|
+
|
|
307
|
+
// Function to reset accumulated data (for View Less button in On-Demand navigation)
|
|
308
|
+
var resetAccumulatedData = (0, _react.useCallback)(function (event) {
|
|
309
|
+
if (navigation === "Scroll") {
|
|
310
|
+
sentinelHasLeftViewportRef.current = false;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Set resetting flag to prevent dataset prop from overwriting our reset
|
|
314
|
+
isResettingRef.current = true;
|
|
315
|
+
|
|
316
|
+
// Reset to initial state
|
|
317
|
+
setAccumulatingState({
|
|
318
|
+
accumulatedData: [],
|
|
319
|
+
lastLoadedPage: 0,
|
|
320
|
+
isAccumulating: navigation === "Scroll" || navigation === "On-Demand",
|
|
321
|
+
isInitialized: false
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Immediately clear the result data to trigger UI update
|
|
325
|
+
setDataState(function (prev) {
|
|
326
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
327
|
+
result: []
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// Reset current page to 1
|
|
332
|
+
setPaginationState(function (prev) {
|
|
333
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
334
|
+
currentPage: 1
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// Immediately trigger pagination change callback to reset table's page index
|
|
339
|
+
if (onPaginationChange) {
|
|
340
|
+
onPaginationChange(event || createDummyEvent(), widgetInstance, 1);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// For client-side, reset result to first page
|
|
344
|
+
if (!isServerSidePagination && dataState.fullData.length > 0) {
|
|
345
|
+
var firstPageData = dataState.fullData.slice(0, paginationState.currentMaxResults);
|
|
346
|
+
setDataState(function (prev) {
|
|
347
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
348
|
+
result: firstPageData
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
// Re-initialize with first page data
|
|
353
|
+
setTimeout(function () {
|
|
354
|
+
setAccumulatingState({
|
|
355
|
+
accumulatedData: firstPageData,
|
|
356
|
+
lastLoadedPage: 1,
|
|
357
|
+
isAccumulating: true,
|
|
358
|
+
isInitialized: true
|
|
359
|
+
});
|
|
360
|
+
}, 0);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// For server-side, refetch first page
|
|
364
|
+
if (isServerSidePagination && datasource && typeof datasource.invoke === "function") {
|
|
365
|
+
if (setIsLoadingMore) {
|
|
366
|
+
setIsLoadingMore(true);
|
|
367
|
+
}
|
|
368
|
+
var invokeOptions = {
|
|
369
|
+
page: 1
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// Include additional options if provided
|
|
373
|
+
if (datasourceInvokeOptions) {
|
|
374
|
+
Object.assign(invokeOptions, datasourceInvokeOptions);
|
|
375
|
+
}
|
|
376
|
+
var result = datasource.invoke(invokeOptions);
|
|
377
|
+
Promise.resolve(result).then(function (response) {
|
|
378
|
+
if (response && response.data) {
|
|
379
|
+
var newDataWithIds = (0, _utils.addUniqueRowIds)(response.data);
|
|
380
|
+
setAccumulatingState({
|
|
381
|
+
accumulatedData: newDataWithIds,
|
|
382
|
+
lastLoadedPage: 1,
|
|
383
|
+
isAccumulating: true,
|
|
384
|
+
isInitialized: true
|
|
385
|
+
});
|
|
386
|
+
setDataState(function (prev) {
|
|
387
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
388
|
+
fullData: newDataWithIds,
|
|
389
|
+
result: newDataWithIds
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
// Clear resetting flag after successfully setting new data
|
|
393
|
+
isResettingRef.current = false;
|
|
394
|
+
}
|
|
395
|
+
if (setIsLoadingMore) {
|
|
396
|
+
setIsLoadingMore(false);
|
|
397
|
+
}
|
|
398
|
+
})["catch"](function () {
|
|
399
|
+
// Clear resetting flag on error
|
|
400
|
+
isResettingRef.current = false;
|
|
401
|
+
if (setIsLoadingMore) {
|
|
402
|
+
setIsLoadingMore(false);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
} else {
|
|
406
|
+
// For client-side, clear resetting flag after setTimeout
|
|
407
|
+
setTimeout(function () {
|
|
408
|
+
isResettingRef.current = false;
|
|
409
|
+
}, 0);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Note: Pagination change callback is already called above when resetting state
|
|
413
|
+
}, [navigation, isServerSidePagination, datasource, datasourceInvokeOptions, dataState.fullData, paginationState.currentMaxResults, setIsLoadingMore, onPaginationChange, widgetInstance]);
|
|
235
414
|
|
|
236
415
|
// Set up intersection observer for infinite scroll
|
|
237
416
|
var setupInfiniteScrollObserver = (0, _react.useCallback)(function (sentinel) {
|
|
@@ -240,15 +419,21 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
240
419
|
observerRef.current.disconnect();
|
|
241
420
|
observerRef.current = null;
|
|
242
421
|
}
|
|
243
|
-
if (!sentinel || navigation !== "Scroll" || !
|
|
422
|
+
if (!sentinel || navigation !== "Scroll" || !accumulatingStateRef.current.isInitialized) {
|
|
244
423
|
return;
|
|
245
424
|
}
|
|
246
425
|
|
|
247
426
|
// Create new observer
|
|
248
427
|
observerRef.current = new IntersectionObserver(function (entries) {
|
|
249
428
|
var entry = entries[0];
|
|
250
|
-
|
|
251
|
-
|
|
429
|
+
|
|
430
|
+
// Track sentinel visibility changes for View Less handling
|
|
431
|
+
if (!entry.isIntersecting && sentinelHasLeftViewportRef.current === false) {
|
|
432
|
+
// Sentinel left viewport - allow future loading
|
|
433
|
+
sentinelHasLeftViewportRef.current = true;
|
|
434
|
+
}
|
|
435
|
+
if (entry.isIntersecting && accumulatingStateRef.current.isInitialized && !isLastPage && !isFetchingRef.current && sentinelHasLeftViewportRef.current // Only load if sentinel has left viewport before
|
|
436
|
+
) {
|
|
252
437
|
loadMoreData();
|
|
253
438
|
}
|
|
254
439
|
}, {
|
|
@@ -282,7 +467,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
282
467
|
|
|
283
468
|
// Calculate page count based on updated values
|
|
284
469
|
// Use paginationMeta.totalPages if available
|
|
285
|
-
var newPageCount = (paginationMeta === null || paginationMeta === void 0 ? void 0 : paginationMeta.totalPages) !== undefined ? paginationMeta.totalPages : updatedDataSize > updatedMaxResults ? Math.ceil(updatedDataSize / updatedMaxResults) : updatedDataSize < 0 ? 0 : 1;
|
|
470
|
+
var newPageCount = (paginationMeta === null || paginationMeta === void 0 ? void 0 : paginationMeta.totalPages) !== undefined && (paginationMeta === null || paginationMeta === void 0 ? void 0 : paginationMeta.totalPages) > 1 ? paginationMeta.totalPages : updatedDataSize > updatedMaxResults ? Math.ceil(updatedDataSize / updatedMaxResults) : updatedDataSize < 0 ? 0 : 1;
|
|
286
471
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
287
472
|
currentPage: updatedCurrentPage,
|
|
288
473
|
dataSize: updatedDataSize,
|
|
@@ -307,7 +492,16 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
307
492
|
// Set non-pageable data
|
|
308
493
|
var setNonPageableData = (0, _react.useCallback)(function (newVal) {
|
|
309
494
|
var newDataSize, newMaxResults, currentPage, startIndex;
|
|
310
|
-
|
|
495
|
+
|
|
496
|
+
// For server-side pagination, use totalItems or paginationMeta.totalElements as dataSize
|
|
497
|
+
// This represents the total count of all records, not just the current page
|
|
498
|
+
if (isServerSidePagination) {
|
|
499
|
+
var serverTotalCount = totalItems !== null && totalItems !== void 0 ? totalItems : paginationMeta === null || paginationMeta === void 0 ? void 0 : paginationMeta.totalElements;
|
|
500
|
+
newDataSize = serverTotalCount !== undefined && serverTotalCount >= 0 ? serverTotalCount : (0, _lodash.isArray)(newVal) ? newVal.length : (0, _lodash.isEmpty)(newVal) ? 0 : 1;
|
|
501
|
+
} else {
|
|
502
|
+
// For client-side pagination, use the array length
|
|
503
|
+
newDataSize = (0, _lodash.isArray)(newVal) ? newVal.length : (0, _lodash.isEmpty)(newVal) ? 0 : 1;
|
|
504
|
+
}
|
|
311
505
|
newMaxResults = paginationState.currentMaxResults || newDataSize;
|
|
312
506
|
// Don't default to 1 if currentPage exists
|
|
313
507
|
currentPage = paginationState.currentPage;
|
|
@@ -319,20 +513,21 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
319
513
|
result: (0, _lodash.isArray)(newVal) ? newVal.slice(startIndex, startIndex + newMaxResults) : newVal
|
|
320
514
|
});
|
|
321
515
|
});
|
|
322
|
-
}, [paginationState.currentPage, paginationState.currentMaxResults, disableNavigation, setDefaultPagingValues]);
|
|
516
|
+
}, [paginationState.currentPage, paginationState.currentMaxResults, disableNavigation, setDefaultPagingValues, isServerSidePagination, totalItems, paginationMeta]);
|
|
323
517
|
|
|
324
518
|
// Set pagination values
|
|
325
519
|
var setPagingValues = (0, _react.useCallback)(function (newVal) {
|
|
326
|
-
//
|
|
327
|
-
|
|
520
|
+
// Check if we're in accumulating mode (Scroll or On-Demand with server-side pagination)
|
|
521
|
+
var isAccumulatingMode = (navigation === "Scroll" || navigation === "On-Demand") && isServerSidePagination;
|
|
522
|
+
if (isAccumulatingMode) {
|
|
328
523
|
// Use ref to check accumulated data to avoid circular dependency
|
|
329
|
-
var currentAccumulatedData =
|
|
524
|
+
var currentAccumulatedData = accumulatingStateRef.current.accumulatedData;
|
|
330
525
|
|
|
331
526
|
// Only update on initial load (when accumulated data is empty)
|
|
332
527
|
if (currentAccumulatedData.length === 0 && (0, _lodash.isArray)(newVal)) {
|
|
333
528
|
// Ensure initial data has unique IDs using the existing utility
|
|
334
529
|
var initialDataWithIds = (0, _utils.addUniqueRowIds)(newVal);
|
|
335
|
-
|
|
530
|
+
setAccumulatingState(function (prev) {
|
|
336
531
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
337
532
|
accumulatedData: initialDataWithIds,
|
|
338
533
|
lastLoadedPage: 1,
|
|
@@ -346,7 +541,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
346
541
|
});
|
|
347
542
|
});
|
|
348
543
|
} else if (currentAccumulatedData.length > 0) {
|
|
349
|
-
// For subsequent updates in
|
|
544
|
+
// For subsequent updates in accumulating mode, always use accumulated data
|
|
350
545
|
setDataState(function (prev) {
|
|
351
546
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
352
547
|
fullData: currentAccumulatedData,
|
|
@@ -354,35 +549,77 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
354
549
|
});
|
|
355
550
|
});
|
|
356
551
|
}
|
|
357
|
-
// Always return early for
|
|
552
|
+
// Always return early for accumulating mode to prevent normal pagination logic
|
|
358
553
|
return;
|
|
359
|
-
}
|
|
360
|
-
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// For On-Demand with client-side pagination
|
|
557
|
+
if (navigation === "On-Demand" && !isServerSidePagination) {
|
|
558
|
+
// Store the full data
|
|
361
559
|
setDataState(function (prev) {
|
|
362
560
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
363
561
|
fullData: (0, _lodash.isArray)(newVal) ? newVal : []
|
|
364
562
|
});
|
|
365
563
|
});
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
564
|
+
var _currentAccumulatedData = accumulatingStateRef.current.accumulatedData;
|
|
565
|
+
|
|
566
|
+
// Initialize accumulated data with first page if empty
|
|
567
|
+
if (_currentAccumulatedData.length === 0 && (0, _lodash.isArray)(newVal) && newVal.length > 0) {
|
|
568
|
+
var firstPageData = newVal.slice(0, paginationState.currentMaxResults);
|
|
569
|
+
setAccumulatingState(function (prev) {
|
|
570
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
571
|
+
accumulatedData: firstPageData,
|
|
572
|
+
lastLoadedPage: 1,
|
|
573
|
+
isInitialized: true
|
|
574
|
+
});
|
|
575
|
+
});
|
|
371
576
|
setDataState(function (prev) {
|
|
372
577
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
373
|
-
result:
|
|
578
|
+
result: firstPageData
|
|
374
579
|
});
|
|
375
580
|
});
|
|
376
|
-
|
|
377
|
-
|
|
581
|
+
} else if (_currentAccumulatedData.length > 0) {
|
|
582
|
+
// Use accumulated data for result
|
|
583
|
+
setDataState(function (prev) {
|
|
378
584
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
379
|
-
|
|
380
|
-
dataSize: 0
|
|
585
|
+
result: _currentAccumulatedData
|
|
381
586
|
});
|
|
382
587
|
});
|
|
383
588
|
}
|
|
589
|
+
|
|
590
|
+
// Update dataSize for proper pagination calculation
|
|
591
|
+
if ((0, _lodash.isArray)(newVal)) {
|
|
592
|
+
setDefaultPagingValues(newVal.length, paginationState.currentMaxResults, 1);
|
|
593
|
+
}
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// Standard pagination logic
|
|
598
|
+
// Store the data in fullData. This is used for client side searching without modifying the actual dataset
|
|
599
|
+
setDataState(function (prev) {
|
|
600
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
601
|
+
fullData: (0, _lodash.isArray)(newVal) ? newVal : []
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
if (newVal && !(0, _lodash.isArray)(newVal)) {
|
|
605
|
+
setNonPageableData(newVal);
|
|
606
|
+
} else if (newVal) {
|
|
607
|
+
setNonPageableData(newVal);
|
|
608
|
+
} else {
|
|
609
|
+
setDataState(function (prev) {
|
|
610
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
611
|
+
result: newVal
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
// Don't reset page navigation when dataset is empty - just update counts
|
|
615
|
+
setPaginationState(function (prev) {
|
|
616
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
617
|
+
pageCount: 0,
|
|
618
|
+
dataSize: 0
|
|
619
|
+
});
|
|
620
|
+
});
|
|
384
621
|
}
|
|
385
|
-
}, [setNonPageableData, navigation, isServerSidePagination]);
|
|
622
|
+
}, [setNonPageableData, navigation, isServerSidePagination, paginationState.currentMaxResults, setDefaultPagingValues]);
|
|
386
623
|
|
|
387
624
|
// Validate current page
|
|
388
625
|
var validateCurrentPage = (0, _react.useCallback)(function (event) {
|
|
@@ -425,7 +662,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
425
662
|
}, [paginationState, dataState.fullData, disableNavigation]);
|
|
426
663
|
|
|
427
664
|
// Shared function for common pagination logic
|
|
428
|
-
var performPageNavigation = (0, _react.useCallback)(function (newPage, previousPage) {
|
|
665
|
+
var performPageNavigation = (0, _react.useCallback)(function (newPage, previousPage, event) {
|
|
429
666
|
// Set loading state if available
|
|
430
667
|
if (setIsLoadingMore) {
|
|
431
668
|
setIsLoadingMore(true);
|
|
@@ -443,7 +680,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
443
680
|
datasourceInvoke(newPage).then(function () {
|
|
444
681
|
// Only trigger callbacks on successful data fetch
|
|
445
682
|
if (onPaginationChange) {
|
|
446
|
-
onPaginationChange(
|
|
683
|
+
onPaginationChange(event || createDummyEvent("paginationchange"), widgetInstance, newPage);
|
|
447
684
|
}
|
|
448
685
|
|
|
449
686
|
// Call onSetRecord with the new page data
|
|
@@ -451,7 +688,13 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
451
688
|
var firstRow = (newPage - 1) * paginationState.currentMaxResults;
|
|
452
689
|
var startIndex = firstRow;
|
|
453
690
|
var data = (0, _lodash.isArray)(dataState.fullData) ? dataState.fullData.slice(startIndex, startIndex + paginationState.currentMaxResults) : dataState.fullData;
|
|
454
|
-
|
|
691
|
+
var pageInfo = {
|
|
692
|
+
currentPage: newPage,
|
|
693
|
+
size: paginationState.currentMaxResults,
|
|
694
|
+
totalElements: (paginationMeta === null || paginationMeta === void 0 ? void 0 : paginationMeta.totalElements) || dataState.fullData.length,
|
|
695
|
+
totalPages: paginationState.pageCount
|
|
696
|
+
};
|
|
697
|
+
onSetRecord(event || createDummyEvent("setrecord"), widgetInstance, data, pageInfo);
|
|
455
698
|
}
|
|
456
699
|
|
|
457
700
|
// Clear loading state immediately for better UX
|
|
@@ -475,7 +718,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
475
718
|
// Client-side pagination - no API call needed
|
|
476
719
|
// Just trigger the callbacks directly
|
|
477
720
|
if (onPaginationChange) {
|
|
478
|
-
onPaginationChange(
|
|
721
|
+
onPaginationChange(event || createDummyEvent("paginationchange"), widgetInstance, newPage);
|
|
479
722
|
}
|
|
480
723
|
|
|
481
724
|
// Call onSetRecord with the new page data
|
|
@@ -483,7 +726,13 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
483
726
|
var firstRow = (newPage - 1) * paginationState.currentMaxResults;
|
|
484
727
|
var startIndex = firstRow;
|
|
485
728
|
var data = (0, _lodash.isArray)(dataState.fullData) ? dataState.fullData.slice(startIndex, startIndex + paginationState.currentMaxResults) : dataState.fullData;
|
|
486
|
-
|
|
729
|
+
var pageInfo = {
|
|
730
|
+
currentPage: newPage,
|
|
731
|
+
size: paginationState.currentMaxResults,
|
|
732
|
+
totalElements: (paginationMeta === null || paginationMeta === void 0 ? void 0 : paginationMeta.totalElements) || dataState.fullData.length,
|
|
733
|
+
totalPages: paginationState.pageCount
|
|
734
|
+
};
|
|
735
|
+
onSetRecord(event || createDummyEvent("setrecord"), widgetInstance, data, pageInfo);
|
|
487
736
|
}
|
|
488
737
|
|
|
489
738
|
// Clear loading state immediately - no delay needed for client-side pagination
|
|
@@ -491,7 +740,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
491
740
|
setIsLoadingMore(false);
|
|
492
741
|
}
|
|
493
742
|
}
|
|
494
|
-
}, [isServerSidePagination, datasourceInvoke, onPaginationChange, onSetRecord, widgetInstance, paginationState, dataState.fullData, setIsLoadingMore]);
|
|
743
|
+
}, [isServerSidePagination, datasourceInvoke, onPaginationChange, onSetRecord, widgetInstance, paginationState, dataState.fullData, setIsLoadingMore, paginationMeta]);
|
|
495
744
|
|
|
496
745
|
// Navigate to page
|
|
497
746
|
var navigatePage = (0, _react.useCallback)(function (index, event) {
|
|
@@ -542,7 +791,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
542
791
|
|
|
543
792
|
// Call handlers only when page actually changes
|
|
544
793
|
if (newPage !== currentPage) {
|
|
545
|
-
performPageNavigation(newPage, currentPage);
|
|
794
|
+
performPageNavigation(newPage, currentPage, event);
|
|
546
795
|
}
|
|
547
796
|
}, [paginationState, isFirstPage, isLastPage, validateCurrentPage, goToPage, performPageNavigation]);
|
|
548
797
|
|
|
@@ -552,7 +801,7 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
552
801
|
if (page !== paginationState.currentPage) {
|
|
553
802
|
// Save current page to restore in case of error
|
|
554
803
|
var previousPage = paginationState.currentPage;
|
|
555
|
-
performPageNavigation(page, previousPage);
|
|
804
|
+
performPageNavigation(page, previousPage, event);
|
|
556
805
|
}
|
|
557
806
|
}, [paginationState.currentPage, performPageNavigation]);
|
|
558
807
|
|
|
@@ -577,15 +826,22 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
577
826
|
// Call onSetRecord with the current page data
|
|
578
827
|
if (onSetRecord) {
|
|
579
828
|
var currentPage = paginationState.currentPage,
|
|
580
|
-
currentMaxResults = paginationState.currentMaxResults
|
|
829
|
+
currentMaxResults = paginationState.currentMaxResults,
|
|
830
|
+
pageCount = paginationState.pageCount;
|
|
581
831
|
var fullData = dataState.fullData;
|
|
582
832
|
var firstRow = (currentPage - 1) * currentMaxResults;
|
|
583
833
|
var startIndex = firstRow;
|
|
584
834
|
var data = (0, _lodash.isArray)(fullData) ? fullData.slice(startIndex, startIndex + currentMaxResults) : fullData;
|
|
585
|
-
|
|
835
|
+
var pageInfo = {
|
|
836
|
+
currentPage: currentPage,
|
|
837
|
+
size: currentMaxResults,
|
|
838
|
+
totalElements: (paginationMeta === null || paginationMeta === void 0 ? void 0 : paginationMeta.totalElements) || fullData.length,
|
|
839
|
+
totalPages: pageCount
|
|
840
|
+
};
|
|
841
|
+
onSetRecord(event, widgetInstance, data, pageInfo);
|
|
586
842
|
}
|
|
587
843
|
goToPage();
|
|
588
|
-
}, [goToPage, validateCurrentPage, onSetRecord, paginationState, dataState.fullData, widgetInstance]);
|
|
844
|
+
}, [goToPage, validateCurrentPage, onSetRecord, paginationState, dataState.fullData, widgetInstance, paginationMeta]);
|
|
589
845
|
|
|
590
846
|
// Handle key down
|
|
591
847
|
var onKeyDown = (0, _react.useCallback)(function (event) {
|
|
@@ -638,13 +894,20 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
638
894
|
datasourceInvoke(1, pageSize).then(function () {
|
|
639
895
|
// Trigger paginationchange event
|
|
640
896
|
if (onPaginationChange) {
|
|
641
|
-
onPaginationChange(
|
|
897
|
+
onPaginationChange(event || createDummyEvent("paginationchange"), widgetInstance, 1);
|
|
642
898
|
}
|
|
643
899
|
|
|
644
900
|
// Call onSetRecord with the new page data
|
|
645
901
|
if (onSetRecord) {
|
|
646
902
|
var data = (0, _lodash.isArray)(dataState.fullData) ? dataState.fullData.slice(0, pageSize) : dataState.fullData;
|
|
647
|
-
|
|
903
|
+
var newPageCount = calculatePagingValues(dataState.fullData.length, pageSize);
|
|
904
|
+
var pageInfo = {
|
|
905
|
+
currentPage: 1,
|
|
906
|
+
size: pageSize,
|
|
907
|
+
totalElements: (paginationMeta === null || paginationMeta === void 0 ? void 0 : paginationMeta.totalElements) || dataState.fullData.length,
|
|
908
|
+
totalPages: newPageCount
|
|
909
|
+
};
|
|
910
|
+
onSetRecord(event || createDummyEvent("setrecord"), widgetInstance, data, pageInfo);
|
|
648
911
|
}
|
|
649
912
|
|
|
650
913
|
// Clear loading state
|
|
@@ -668,15 +931,15 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
668
931
|
setIsLoadingMore(false);
|
|
669
932
|
}
|
|
670
933
|
}
|
|
671
|
-
}, [pageSizeChangeHandler, navigatePage, datasource, paginationState, isServerSidePagination, datasourceInvoke, onPaginationChange, onSetRecord, widgetInstance, dataState.fullData, setIsLoadingMore]);
|
|
934
|
+
}, [pageSizeChangeHandler, navigatePage, datasource, paginationState, isServerSidePagination, datasourceInvoke, onPaginationChange, onSetRecord, widgetInstance, dataState.fullData, setIsLoadingMore, paginationMeta]);
|
|
672
935
|
|
|
673
936
|
// Effect for navigation controls
|
|
674
937
|
(0, _react.useEffect)(function () {
|
|
675
938
|
setNavcontrols(getValidNavControl(navigation));
|
|
676
939
|
|
|
677
|
-
// Reset
|
|
678
|
-
if (navigation === "Scroll") {
|
|
679
|
-
|
|
940
|
+
// Reset accumulated data state when navigation changes to Scroll or On-Demand
|
|
941
|
+
if (navigation === "Scroll" || navigation === "On-Demand") {
|
|
942
|
+
setAccumulatingState({
|
|
680
943
|
accumulatedData: [],
|
|
681
944
|
lastLoadedPage: 0,
|
|
682
945
|
isAccumulating: true,
|
|
@@ -688,9 +951,25 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
688
951
|
// for dataset changes
|
|
689
952
|
(0, _react.useEffect)(function () {
|
|
690
953
|
if (dataset !== undefined) {
|
|
691
|
-
|
|
954
|
+
// Check if we're in accumulating mode (Scroll or On-Demand with server-side pagination)
|
|
955
|
+
var isAccumulatingMode = (navigation === "Scroll" || navigation === "On-Demand") && isServerSidePagination;
|
|
956
|
+
|
|
957
|
+
// For accumulating mode, only process dataset updates if accumulated data is empty
|
|
958
|
+
// This prevents overwriting accumulated data when datasource updates with new page data
|
|
959
|
+
// Also skip if we're currently resetting (to prevent old dataset from overwriting reset)
|
|
960
|
+
if (isAccumulatingMode) {
|
|
961
|
+
var currentAccumulatedData = accumulatingStateRef.current.accumulatedData;
|
|
962
|
+
// Only process dataset if accumulated data is empty (initial load or after reset)
|
|
963
|
+
// AND we're not currently in the middle of a reset operation
|
|
964
|
+
if (currentAccumulatedData.length === 0 && !isResettingRef.current) {
|
|
965
|
+
setPagingValues(dataset);
|
|
966
|
+
}
|
|
967
|
+
} else {
|
|
968
|
+
// For non-accumulating modes, always process dataset updates
|
|
969
|
+
setPagingValues(dataset);
|
|
970
|
+
}
|
|
692
971
|
}
|
|
693
|
-
}, [dataset, setPagingValues]);
|
|
972
|
+
}, [dataset, setPagingValues, navigation, isServerSidePagination]);
|
|
694
973
|
|
|
695
974
|
// For server-side pagination, update dataSize and pageCount based on metadata
|
|
696
975
|
(0, _react.useEffect)(function () {
|
|
@@ -741,10 +1020,10 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
741
1020
|
|
|
742
1021
|
// Re-setup observer when initialization state changes
|
|
743
1022
|
(0, _react.useEffect)(function () {
|
|
744
|
-
if (
|
|
1023
|
+
if (accumulatingState.isInitialized && sentinelRef.current && navigation === "Scroll") {
|
|
745
1024
|
setupInfiniteScrollObserver(sentinelRef.current);
|
|
746
1025
|
}
|
|
747
|
-
}, [
|
|
1026
|
+
}, [accumulatingState.isInitialized, navigation, setupInfiniteScrollObserver]);
|
|
748
1027
|
|
|
749
1028
|
// Cleanup observer on unmount
|
|
750
1029
|
(0, _react.useEffect)(function () {
|
|
@@ -790,7 +1069,11 @@ var usePagination = exports.usePagination = function usePagination(_ref) {
|
|
|
790
1069
|
// Infinite scroll specific
|
|
791
1070
|
setupInfiniteScrollObserver: setupInfiniteScrollObserver,
|
|
792
1071
|
sentinelRef: sentinelRef,
|
|
793
|
-
isLoadingMore: isFetchingRef.current && navigation === "Scroll" &&
|
|
794
|
-
hasMoreData: !isLastPage && navigation === "Scroll"
|
|
1072
|
+
isLoadingMore: isFetchingRef.current && (navigation === "Scroll" || navigation === "On-Demand") && accumulatingStateRef.current.lastLoadedPage > 0,
|
|
1073
|
+
hasMoreData: !isLastPage && (navigation === "Scroll" || navigation === "On-Demand"),
|
|
1074
|
+
// On-Demand specific
|
|
1075
|
+
loadMoreData: loadMoreData,
|
|
1076
|
+
resetAccumulatedData: resetAccumulatedData,
|
|
1077
|
+
accumulatedDataCount: accumulatingStateRef.current.accumulatedData.length
|
|
795
1078
|
};
|
|
796
1079
|
};
|