@economic/taco 2.48.5 → 2.49.0-dataloader.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Report/Report.d.ts +1 -1
- package/dist/components/SearchInput2/SearchInput2.d.ts +2 -0
- package/dist/components/Table3/features/useEditingState.d.ts +13 -13
- package/dist/components/Table3/features/useTableEditing.d.ts +15 -15
- package/dist/components/Table3/types.d.ts +2 -0
- package/dist/esm/packages/taco/src/charts/components/Donut/Legend.js +1 -0
- package/dist/esm/packages/taco/src/charts/components/Donut/Legend.js.map +1 -1
- package/dist/esm/packages/taco/src/charts/components/Legend.js +1 -0
- package/dist/esm/packages/taco/src/charts/components/Legend.js.map +1 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +6 -3
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table/hooks/plugins/useRowActions.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +15 -9
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +4 -2
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +3 -2
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +61 -69
- package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +13 -6
- package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +15 -12
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/useTable3.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
- package/dist/esm/packages/taco/src/index.js +1 -0
- package/dist/esm/packages/taco/src/index.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js +7 -4
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Summary.js +7 -6
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Summary.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js +24 -22
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js +41 -4
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js +3 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js +26 -3
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableGlobalShortcuts.js +2 -2
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableGlobalShortcuts.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +40 -13
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js +13 -12
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader2.js +223 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader2.js.map +1 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js +3 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js +6 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableFilterListener.js +3 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableFilterListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableRowSelectionListener.js +4 -4
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableRowSelectionListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js +14 -13
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js +7 -3
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +3 -3
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js +4 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +8 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
- package/dist/hooks/useLazyDebouncedEffect.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.d.ts +2 -2
- package/dist/primitives/Table/Core/components/Row/Row.d.ts +2 -0
- package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +1 -1
- package/dist/primitives/Table/types.d.ts +10 -6
- package/dist/primitives/Table/useTableDataLoader.d.ts +2 -2
- package/dist/primitives/Table/useTableDataLoader2.d.ts +23 -0
- package/dist/primitives/Table/useTableManager/features/useTableSearch.d.ts +4 -2
- package/dist/primitives/Table/useTableManager/features/useTableServerLoading.d.ts +4 -1
- package/dist/primitives/Table/useTableManager/listeners/useTableSearchListener.d.ts +1 -2
- package/dist/primitives/Table/useTableManager/util/columns.d.ts +2 -1
- package/dist/taco.cjs.development.js +575 -232
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/package.json +2 -2
@@ -31,12 +31,12 @@ var reactPortal = require('@radix-ui/react-portal');
|
|
31
31
|
var reactTable = require('@tanstack/react-table');
|
32
32
|
var get = _interopDefault(require('lodash/get'));
|
33
33
|
var reactVirtual = require('@tanstack/react-virtual');
|
34
|
-
var reactIntersectionObserver = require('react-intersection-observer');
|
35
34
|
var core = require('@dnd-kit/core');
|
36
35
|
var modifiers = require('@dnd-kit/modifiers');
|
37
36
|
var SortablePrimitive = require('@dnd-kit/sortable');
|
38
37
|
var utilities = require('@dnd-kit/utilities');
|
39
38
|
var reactTable$1 = require('react-table');
|
39
|
+
var reactIntersectionObserver = require('react-intersection-observer');
|
40
40
|
var reactWindow = require('react-window');
|
41
41
|
var InfiniteLoader = _interopDefault(require('react-window-infinite-loader'));
|
42
42
|
var set = _interopDefault(require('lodash/set'));
|
@@ -10318,6 +10318,9 @@ function unfreezeAllExternalColumns(leftPinnedState) {
|
|
10318
10318
|
function freezeUptoExternalColumn(index, columns) {
|
10319
10319
|
return columns.slice(0, index + 1);
|
10320
10320
|
}
|
10321
|
+
function getHiddenColumns(columnVisibility = {}) {
|
10322
|
+
return Object.keys(columnVisibility).filter(c => columnVisibility[c] === false);
|
10323
|
+
}
|
10321
10324
|
|
10322
10325
|
function getSettings(table) {
|
10323
10326
|
const meta = table.options.meta;
|
@@ -10582,7 +10585,8 @@ function configureReactTableOptions(options, props, localization) {
|
|
10582
10585
|
getExpandedRowModel: reactTable.getExpandedRowModel(),
|
10583
10586
|
getGroupedRowModel: reactTable.getGroupedRowModel(),
|
10584
10587
|
getRowId,
|
10585
|
-
groupedColumnMode: false
|
10588
|
+
groupedColumnMode: false,
|
10589
|
+
keepPinnedRows: false
|
10586
10590
|
};
|
10587
10591
|
if (tableOptions.enableColumnResizing) {
|
10588
10592
|
tableOptions.columnResizeMode = 'onChange';
|
@@ -10604,6 +10608,12 @@ function configureReactTableOptions(options, props, localization) {
|
|
10604
10608
|
var _column$columnDef$met;
|
10605
10609
|
return ((_column$columnDef$met = column.columnDef.meta) === null || _column$columnDef$met === void 0 ? void 0 : _column$columnDef$met.enableSearch) !== false && column.getIsVisible();
|
10606
10610
|
};
|
10611
|
+
// enter controlled search mode (controlled could be local state, but usually the server)
|
10612
|
+
if (props.onChangeSearch) {
|
10613
|
+
if (props._experimentalDataLoader2) {
|
10614
|
+
tableOptions.manualFiltering = true;
|
10615
|
+
}
|
10616
|
+
}
|
10607
10617
|
}
|
10608
10618
|
if (tableOptions.enableSorting) {
|
10609
10619
|
// enter controlled sort mode (controlled could be local state, but usually the server)
|
@@ -10987,7 +10997,7 @@ function useTableRowActive(isEnabled = false, initialRowActiveIndex) {
|
|
10987
10997
|
return index;
|
10988
10998
|
});
|
10989
10999
|
}
|
10990
|
-
}, [rowActiveIndex,
|
11000
|
+
}, [rowActiveIndex, isEnabled]);
|
10991
11001
|
return {
|
10992
11002
|
isEnabled,
|
10993
11003
|
rowActiveIndex,
|
@@ -11103,7 +11113,7 @@ function useTableRowSelection(isEnabled = false) {
|
|
11103
11113
|
- Highlighting search results, this is custom and only uses the state part of globalFilter (to store the search query)
|
11104
11114
|
- Filtering of results, this is essentially the built in filtering, and relies on enableGlobalFilter being on or off
|
11105
11115
|
*/
|
11106
|
-
function useTableSearch(isEnabled = false, defaultEnableGlobalFilter = false) {
|
11116
|
+
function useTableSearch(isEnabled = false, onChangeSearch, defaultEnableGlobalFilter = false) {
|
11107
11117
|
const [enableGlobalFilter, _setEnableGlobalFilter] = React__default.useState(defaultEnableGlobalFilter);
|
11108
11118
|
function setEnableGlobalFilter(enabled, instance) {
|
11109
11119
|
_setEnableGlobalFilter(enabled);
|
@@ -11128,7 +11138,8 @@ function useTableSearch(isEnabled = false, defaultEnableGlobalFilter = false) {
|
|
11128
11138
|
highlightedColumnIndexes,
|
11129
11139
|
setHighlightedColumnIndexes,
|
11130
11140
|
currentHighlightColumnIndex,
|
11131
|
-
setCurrentHighlightColumnIndex
|
11141
|
+
setCurrentHighlightColumnIndex,
|
11142
|
+
handleSearch: isEnabled && typeof onChangeSearch === 'function' ? onChangeSearch : undefined
|
11132
11143
|
};
|
11133
11144
|
}
|
11134
11145
|
|
@@ -11338,9 +11349,10 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
11338
11349
|
const _lastUsedSorting = React__default.useRef([]);
|
11339
11350
|
const _lastUsedFilters = React__default.useRef([]);
|
11340
11351
|
const _lastUsedSearch = React__default.useRef();
|
11352
|
+
const _lastUsedHiddenColumns = React__default.useRef([]);
|
11341
11353
|
const _lastUsedPageIndex = React__default.useRef();
|
11342
11354
|
const _forceReset = React__default.useRef(false);
|
11343
|
-
const loadPage = function (pageIndex, sorting, filters) {
|
11355
|
+
const loadPage = function (pageIndex, sorting, filters, hiddenColumns) {
|
11344
11356
|
try {
|
11345
11357
|
let reset = false;
|
11346
11358
|
// sorting or filters changed, reset everything
|
@@ -11362,9 +11374,10 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
11362
11374
|
_lastUsedSorting.current = sorting;
|
11363
11375
|
// set the filters so we can track if it changed between loads
|
11364
11376
|
_lastUsedFilters.current = filters;
|
11377
|
+
_lastUsedHiddenColumns.current = hiddenColumns;
|
11365
11378
|
const _temp = _finallyRethrows(function () {
|
11366
11379
|
return _catch(function () {
|
11367
|
-
return Promise.resolve(fetchPage(pageIndex, pageSize, sorting, filters)).then(function (response) {
|
11380
|
+
return Promise.resolve(fetchPage(pageIndex, pageSize, sorting, filters, hiddenColumns)).then(function (response) {
|
11368
11381
|
// update state, here we do some "magic" to support "load in place"
|
11369
11382
|
setData(currentData => {
|
11370
11383
|
let nextData;
|
@@ -11393,14 +11406,15 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
11393
11406
|
return Promise.reject(e);
|
11394
11407
|
}
|
11395
11408
|
};
|
11396
|
-
const loadAll = function (sorting, filters) {
|
11409
|
+
const loadAll = function (sorting, filters, hiddenColumns) {
|
11397
11410
|
try {
|
11398
11411
|
// set the sorting so we can track if it changed between loads
|
11399
11412
|
_lastUsedSorting.current = sorting;
|
11400
11413
|
// set the filters so we can track if it changed between loads
|
11401
11414
|
_lastUsedFilters.current = filters;
|
11415
|
+
_lastUsedHiddenColumns.current = hiddenColumns;
|
11402
11416
|
const _temp2 = _catch(function () {
|
11403
|
-
return Promise.resolve(fetchAll(sorting, filters)).then(function (response) {
|
11417
|
+
return Promise.resolve(fetchAll(sorting, filters, hiddenColumns)).then(function (response) {
|
11404
11418
|
length.current = response.length;
|
11405
11419
|
setData(() => {
|
11406
11420
|
let nextData;
|
@@ -11425,11 +11439,11 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
11425
11439
|
_forceReset.current = true;
|
11426
11440
|
if (_lastUsedSearch.current) {
|
11427
11441
|
// we're searching, which means we need to refetch all with the correct sorting applied
|
11428
|
-
return loadAll(_lastUsedSorting.current, _lastUsedFilters.current);
|
11442
|
+
return loadAll(_lastUsedSorting.current, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
|
11429
11443
|
} else {
|
11430
11444
|
var _lastUsedPageIndex$cu;
|
11431
11445
|
// load the last page that we scrolled to
|
11432
|
-
return loadPage((_lastUsedPageIndex$cu = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu !== void 0 ? _lastUsedPageIndex$cu : 0, _lastUsedSorting.current, _lastUsedFilters.current);
|
11446
|
+
return loadPage((_lastUsedPageIndex$cu = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu !== void 0 ? _lastUsedPageIndex$cu : 0, _lastUsedSorting.current, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
|
11433
11447
|
}
|
11434
11448
|
} catch (e) {
|
11435
11449
|
return Promise.reject(e);
|
@@ -11441,13 +11455,12 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
11441
11455
|
try {
|
11442
11456
|
if (_lastUsedSearch.current) {
|
11443
11457
|
// we're searching, which means we need to refetch all with the correct sorting applied
|
11444
|
-
loadAll(sorting, _lastUsedFilters.current);
|
11458
|
+
return loadAll(sorting, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
|
11445
11459
|
} else {
|
11446
11460
|
var _lastUsedPageIndex$cu2;
|
11447
11461
|
// load the last page that we scrolled to
|
11448
|
-
loadPage((_lastUsedPageIndex$cu2 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu2 !== void 0 ? _lastUsedPageIndex$cu2 : 0, sorting, _lastUsedFilters.current);
|
11462
|
+
return loadPage((_lastUsedPageIndex$cu2 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu2 !== void 0 ? _lastUsedPageIndex$cu2 : 0, sorting, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
|
11449
11463
|
}
|
11450
|
-
return Promise.resolve();
|
11451
11464
|
} catch (e) {
|
11452
11465
|
return Promise.reject(e);
|
11453
11466
|
}
|
@@ -11456,13 +11469,12 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
11456
11469
|
try {
|
11457
11470
|
if (_lastUsedSearch.current) {
|
11458
11471
|
// we're searching, which means we need to refetch all with the correct sorting applied
|
11459
|
-
loadAll(_lastUsedSorting.current, filters);
|
11472
|
+
return loadAll(_lastUsedSorting.current, filters, _lastUsedHiddenColumns.current);
|
11460
11473
|
} else {
|
11461
11474
|
var _lastUsedPageIndex$cu3;
|
11462
11475
|
// load the last page that we scrolled to
|
11463
|
-
loadPage((_lastUsedPageIndex$cu3 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu3 !== void 0 ? _lastUsedPageIndex$cu3 : 0, _lastUsedSorting.current, filters);
|
11476
|
+
return loadPage((_lastUsedPageIndex$cu3 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu3 !== void 0 ? _lastUsedPageIndex$cu3 : 0, _lastUsedSorting.current, filters, _lastUsedHiddenColumns.current);
|
11464
11477
|
}
|
11465
|
-
return Promise.resolve();
|
11466
11478
|
} catch (e) {
|
11467
11479
|
return Promise.reject(e);
|
11468
11480
|
}
|
@@ -11490,7 +11502,7 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
11490
11502
|
}, invalidate];
|
11491
11503
|
}
|
11492
11504
|
|
11493
|
-
function useTableServerLoading(length, data, loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE) {
|
11505
|
+
function useTableServerLoading(length, data, loadPage, loadAll, pages, pageSize = DEFAULT_PAGE_SIZE, _experimentalDataLoader2 = false) {
|
11494
11506
|
const isEnabled = !!loadPage && !!loadAll;
|
11495
11507
|
const [isReady, setReady] = React__default.useState(false);
|
11496
11508
|
const [loading, setLoading] = React__default.useState(false);
|
@@ -11551,14 +11563,18 @@ function useTableServerLoading(length, data, loadPage, loadAll, pageSize = DEFAU
|
|
11551
11563
|
}
|
11552
11564
|
};
|
11553
11565
|
}
|
11566
|
+
const pageCount = Math.ceil(length / pageSize);
|
11554
11567
|
return {
|
11568
|
+
pages,
|
11555
11569
|
isEnabled,
|
11556
11570
|
isReady,
|
11557
11571
|
loadPage: _loadPage,
|
11558
11572
|
loadAll: _loadAll,
|
11559
11573
|
loadAllIfNeeded: _loadAllIfNeeded,
|
11560
11574
|
loading,
|
11561
|
-
pageSize
|
11575
|
+
pageSize,
|
11576
|
+
pageCount,
|
11577
|
+
_experimentalDataLoader2
|
11562
11578
|
};
|
11563
11579
|
}
|
11564
11580
|
|
@@ -11655,7 +11671,8 @@ function useTableFilterListener(table, onFilter) {
|
|
11655
11671
|
const columnFilters = table.getState().columnFilters;
|
11656
11672
|
useLazyEffect(() => {
|
11657
11673
|
if (table.options.enableColumnFilters && typeof onFilter === 'function') {
|
11658
|
-
|
11674
|
+
const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
|
11675
|
+
onFilter(columnFilters, hiddenColumns);
|
11659
11676
|
if (table.options.enableRowSelection) {
|
11660
11677
|
table.resetRowSelection();
|
11661
11678
|
}
|
@@ -11714,11 +11731,12 @@ function useTableRowHeightListener(table) {
|
|
11714
11731
|
}
|
11715
11732
|
|
11716
11733
|
function useTableRowSelectionListener(table, onRowSelect) {
|
11734
|
+
// note that the selected row model may not contain all rows in state when using server loading
|
11717
11735
|
const rows = table.getSelectedRowModel().flatRows;
|
11718
|
-
const
|
11736
|
+
const state = table.getState().rowSelection;
|
11719
11737
|
useLazyEffect(() => {
|
11720
11738
|
if (table.options.enableRowSelection && typeof onRowSelect === 'function') {
|
11721
|
-
onRowSelect(
|
11739
|
+
onRowSelect(rows.map(row => row.original), Object.keys(state));
|
11722
11740
|
}
|
11723
11741
|
/**
|
11724
11742
|
* Casting to a boolean, since enableRowSelection can be a function,
|
@@ -11726,33 +11744,33 @@ function useTableRowSelectionListener(table, onRowSelect) {
|
|
11726
11744
|
* we only need to know if selection was enabled or disabled, because enableRowSelection function
|
11727
11745
|
* will be applied directly to particular rows.
|
11728
11746
|
*/
|
11729
|
-
}, [!!table.options.enableRowSelection, JSON.stringify(
|
11747
|
+
}, [!!table.options.enableRowSelection, JSON.stringify(state)]);
|
11730
11748
|
}
|
11731
11749
|
|
11732
|
-
function useTableSearchListener(table
|
11750
|
+
function useTableSearchListener(table) {
|
11733
11751
|
const meta = table.options.meta;
|
11734
11752
|
const localization = useLocalization();
|
11735
|
-
const
|
11753
|
+
const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
|
11754
|
+
const query = table.getState().globalFilter;
|
11736
11755
|
// Need to re-run search when columns are getting shown/hidden.
|
11737
|
-
|
11738
|
-
if (meta.search.isEnabled
|
11739
|
-
const currentFilter =
|
11756
|
+
useLazyEffect(() => {
|
11757
|
+
if (meta.search.isEnabled) {
|
11758
|
+
const currentFilter = query;
|
11740
11759
|
requestAnimationFrame(() => {
|
11741
11760
|
table.resetGlobalFilter();
|
11742
11761
|
table.setGlobalFilter(currentFilter);
|
11743
11762
|
});
|
11763
|
+
if (meta.search.handleSearch && meta.search.enableGlobalFilter && query) {
|
11764
|
+
meta.search.handleSearch(query, hiddenColumns);
|
11765
|
+
}
|
11744
11766
|
}
|
11745
|
-
}, [
|
11767
|
+
}, [hiddenColumns.length]);
|
11746
11768
|
// recalculates highlighted indexes whenever something important changes
|
11747
|
-
|
11769
|
+
useLazyEffect(() => {
|
11748
11770
|
if (meta.search.isEnabled) {
|
11749
|
-
const query = table.getState().globalFilter;
|
11750
11771
|
resetHighlightedColumnIndexes(query, table, localization);
|
11751
|
-
if (typeof onChangeSearch === 'function') {
|
11752
|
-
onChangeSearch(query);
|
11753
|
-
}
|
11754
11772
|
}
|
11755
|
-
}, [meta.server.loading, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length,
|
11773
|
+
}, [meta.server.loading, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, query, JSON.stringify(table.getState().sorting)]);
|
11756
11774
|
}
|
11757
11775
|
|
11758
11776
|
function useTableSettingsListener(table, onChangeSettings) {
|
@@ -11836,12 +11854,15 @@ function useTableSortingListener(table, onSort) {
|
|
11836
11854
|
}
|
11837
11855
|
|
11838
11856
|
function useTableServerLoadingListener(table, loadPage) {
|
11839
|
-
const
|
11840
|
-
const columnFilters = table.getState().columnFilters;
|
11857
|
+
const meta = table.options.meta;
|
11841
11858
|
// trigger load of the first page on mount
|
11842
11859
|
React__default.useEffect(() => {
|
11843
11860
|
if (loadPage) {
|
11844
|
-
|
11861
|
+
const sorting = table.getState().sorting;
|
11862
|
+
const columnFilters = table.getState().columnFilters;
|
11863
|
+
const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
|
11864
|
+
const search = meta.search.enableGlobalFilter ? table.getState().globalFilter : undefined;
|
11865
|
+
loadPage(0, sorting, columnFilters, hiddenColumns, search);
|
11845
11866
|
}
|
11846
11867
|
}, []);
|
11847
11868
|
}
|
@@ -11893,8 +11914,8 @@ function useTableManager(props, meta, internalColumns) {
|
|
11893
11914
|
const rowGroups = useTableRowGroups(props.rowActionsForGroup);
|
11894
11915
|
const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);
|
11895
11916
|
const rowSelection = useTableRowSelection(!!options.enableRowSelection);
|
11896
|
-
const search = useTableSearch(options.enableSearch, settings.excludeUnmatchedRecordsInSearch);
|
11897
|
-
const server = useTableServerLoading(length, data, props.loadPage, props.loadAll, props.pageSize);
|
11917
|
+
const search = useTableSearch(options.enableSearch, props.onChangeSearch, settings.excludeUnmatchedRecordsInSearch);
|
11918
|
+
const server = useTableServerLoading(length, data, props.loadPage, props.loadAll, props.pages, props.pageSize, props._experimentalDataLoader2);
|
11898
11919
|
// TODO: memoise
|
11899
11920
|
// convert jsx column components into valid table columns
|
11900
11921
|
const {
|
@@ -11945,7 +11966,7 @@ function useTableManager(props, meta, internalColumns) {
|
|
11945
11966
|
useTableFontSizeListener(instance);
|
11946
11967
|
useTableRowHeightListener(instance);
|
11947
11968
|
useTableRowSelectionListener(instance, props.onRowSelect);
|
11948
|
-
useTableSearchListener(instance
|
11969
|
+
useTableSearchListener(instance);
|
11949
11970
|
useTableServerLoadingListener(instance, server.loadPage);
|
11950
11971
|
useTableSettingsListener(instance, setSettings);
|
11951
11972
|
useTableShortcutsListener(instance, props.shortcuts);
|
@@ -12171,7 +12192,7 @@ function useTableGlobalShortcuts(table, tableRef, scrollToIndex) {
|
|
12171
12192
|
if (isElementInsideOverlay(trigger) && !isSiblingElementInsideSameParentOverlay(trigger, tableRef.current) || isElementInteractive(trigger) && !isElementInsideOrTriggeredFromContainer(trigger, tableRef.current)) {
|
12172
12193
|
return;
|
12173
12194
|
}
|
12174
|
-
tableMeta.rowActive.handleKeyDown(event,
|
12195
|
+
tableMeta.rowActive.handleKeyDown(event, tableMeta.length, scrollToIndex);
|
12175
12196
|
tableMeta.rowSelection.handleKeyDown(event, table);
|
12176
12197
|
if (tableMeta.rowActive.rowActiveIndex !== undefined) {
|
12177
12198
|
var _rows$tableMeta$rowAc;
|
@@ -12184,7 +12205,7 @@ function useTableGlobalShortcuts(table, tableRef, scrollToIndex) {
|
|
12184
12205
|
};
|
12185
12206
|
},
|
12186
12207
|
// scrollToIndex function changes when row count changes, so it is important to update handlers
|
12187
|
-
[tableRef.current, tableMeta.rowActive.rowActiveIndex, scrollToIndex]);
|
12208
|
+
[tableRef.current, tableMeta.length, tableMeta.rowActive.rowActiveIndex, scrollToIndex]);
|
12188
12209
|
}
|
12189
12210
|
|
12190
12211
|
function useTableRef(table, ref) {
|
@@ -12207,57 +12228,131 @@ const ROW_HEIGHT_ESTIMATES = {
|
|
12207
12228
|
'extra-tall': 57
|
12208
12229
|
};
|
12209
12230
|
|
12231
|
+
const RowContext = /*#__PURE__*/React__default.createContext({
|
12232
|
+
hideInternalColumns: false,
|
12233
|
+
hideRowActions: false,
|
12234
|
+
isHovered: false,
|
12235
|
+
rowIndex: -1
|
12236
|
+
});
|
12237
|
+
|
12238
|
+
const DELAY_BEFORE_LOAD_MS = 250;
|
12239
|
+
/* anonymous functions will break the memoisation on each render, wrap handlers in callbacks */
|
12240
|
+
function Row(props) {
|
12241
|
+
const {
|
12242
|
+
renderer: RowRenderer,
|
12243
|
+
cellRenderer: CellRenderer,
|
12244
|
+
hideInternalColumns = false,
|
12245
|
+
hideRowActions = false,
|
12246
|
+
scrollDirection,
|
12247
|
+
skipPageLoading = false,
|
12248
|
+
...displayRowProps
|
12249
|
+
} = props;
|
12250
|
+
const tableMeta = props.table.options.meta;
|
12251
|
+
const isHovered = tableMeta.rowActive.rowHoverIndex === props.index;
|
12252
|
+
// context - it must be here for cells to read it, since they render alongside the row inside DisplayRow
|
12253
|
+
const contextValue = React__default.useMemo(() => ({
|
12254
|
+
isHovered,
|
12255
|
+
rowIndex: props.index,
|
12256
|
+
hideInternalColumns,
|
12257
|
+
hideRowActions
|
12258
|
+
}), [isHovered, props.index, hideInternalColumns, hideRowActions]);
|
12259
|
+
React__default.useEffect(() => {
|
12260
|
+
let timeout;
|
12261
|
+
if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2 && !skipPageLoading) {
|
12262
|
+
const pageIndex = Math.floor(props.index / tableMeta.server.pageSize) * tableMeta.server.pageSize / tableMeta.server.pageSize;
|
12263
|
+
const sorting = props.table.getState().sorting;
|
12264
|
+
const filters = props.table.getState().columnFilters;
|
12265
|
+
const search = props.table.getState().globalFilter;
|
12266
|
+
const hiddenColumns = getHiddenColumns(props.table.getState().columnVisibility);
|
12267
|
+
const pageIndexesToFetch = [];
|
12268
|
+
// if there's no direction, it means the scroll bar got dropped un unloaded pages,
|
12269
|
+
// in that case, load forward and backward pages to prevent skeletons
|
12270
|
+
if (scrollDirection === 'backward' || !scrollDirection) {
|
12271
|
+
const backIndex = pageIndex - 1;
|
12272
|
+
if (backIndex > -1) {
|
12273
|
+
pageIndexesToFetch.push(backIndex);
|
12274
|
+
}
|
12275
|
+
}
|
12276
|
+
// always load the next page
|
12277
|
+
if ((scrollDirection === 'forward' || !scrollDirection) && pageIndex + 2 < tableMeta.server.pageCount) {
|
12278
|
+
pageIndexesToFetch.push(pageIndex + 1);
|
12279
|
+
}
|
12280
|
+
if (pageIndexesToFetch.length) {
|
12281
|
+
// the virtualiser fetches a page ahead, so this won't get called in most cases
|
12282
|
+
// but it provides a fallback for some edge cases
|
12283
|
+
timeout = setTimeout(() => {
|
12284
|
+
pageIndexesToFetch.forEach(index => {
|
12285
|
+
var _tableMeta$server$loa, _tableMeta$server;
|
12286
|
+
// this can be called by every row within the current page, but loadPage returns early if a pending request exists
|
12287
|
+
(_tableMeta$server$loa = (_tableMeta$server = tableMeta.server).loadPage) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, index, sorting, filters, hiddenColumns, tableMeta.search.enableGlobalFilter ? search : undefined);
|
12288
|
+
});
|
12289
|
+
}, DELAY_BEFORE_LOAD_MS);
|
12290
|
+
}
|
12291
|
+
}
|
12292
|
+
return () => {
|
12293
|
+
clearTimeout(timeout);
|
12294
|
+
};
|
12295
|
+
}, [tableMeta.server.pages]);
|
12296
|
+
return /*#__PURE__*/React__default.createElement(RowContext.Provider, {
|
12297
|
+
value: contextValue
|
12298
|
+
}, /*#__PURE__*/React__default.createElement(RowRenderer, Object.assign({}, displayRowProps, {
|
12299
|
+
cellRenderer: CellRenderer
|
12300
|
+
})));
|
12301
|
+
}
|
12302
|
+
|
12303
|
+
const DELAY_BEFORE_LOAD_MS$1 = 150;
|
12210
12304
|
function SkeletonRow(props) {
|
12211
12305
|
const {
|
12212
12306
|
index,
|
12213
|
-
row,
|
12214
12307
|
table
|
12215
12308
|
} = props;
|
12216
12309
|
const tableMeta = table.options.meta;
|
12217
12310
|
if (tableMeta.server.isEnabled) {
|
12218
|
-
return /*#__PURE__*/React__default.createElement(RowWithServerLoading, Object.assign({}, props
|
12219
|
-
index: index
|
12220
|
-
}));
|
12311
|
+
return /*#__PURE__*/React__default.createElement(RowWithServerLoading, Object.assign({}, props));
|
12221
12312
|
}
|
12222
12313
|
return /*#__PURE__*/React__default.createElement(Skeleton, {
|
12223
|
-
cellsCount:
|
12314
|
+
cellsCount: table.getVisibleFlatColumns().length,
|
12315
|
+
index: index
|
12224
12316
|
});
|
12225
12317
|
}
|
12226
12318
|
function RowWithServerLoading(props) {
|
12227
12319
|
var _table$getState$group, _table$getState;
|
12228
12320
|
const {
|
12229
12321
|
index,
|
12230
|
-
row,
|
12231
12322
|
table
|
12232
12323
|
} = props;
|
12233
12324
|
const tableMeta = table.options.meta;
|
12234
12325
|
const pageIndex = Math.floor(index / tableMeta.server.pageSize) * tableMeta.server.pageSize / tableMeta.server.pageSize;
|
12235
|
-
const {
|
12236
|
-
ref,
|
12237
|
-
inView
|
12238
|
-
} = reactIntersectionObserver.useInView({
|
12239
|
-
threshold: 0,
|
12240
|
-
triggerOnce: true,
|
12241
|
-
initialInView: pageIndex === 0
|
12242
|
-
});
|
12243
12326
|
React__default.useEffect(() => {
|
12244
|
-
|
12245
|
-
|
12246
|
-
|
12327
|
+
let timeout;
|
12328
|
+
if (tableMeta.server.isEnabled) {
|
12329
|
+
const sorting = props.table.getState().sorting;
|
12330
|
+
const filters = props.table.getState().columnFilters;
|
12331
|
+
const search = props.table.getState().globalFilter;
|
12332
|
+
const hiddenColumns = getHiddenColumns(props.table.getState().columnVisibility);
|
12333
|
+
timeout = setTimeout(() => {
|
12334
|
+
var _tableMeta$server$loa, _tableMeta$server;
|
12335
|
+
(_tableMeta$server$loa = (_tableMeta$server = tableMeta.server).loadPage) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, pageIndex, sorting, filters, hiddenColumns, tableMeta.search.enableGlobalFilter ? search : undefined);
|
12336
|
+
}, DELAY_BEFORE_LOAD_MS$1);
|
12247
12337
|
}
|
12248
|
-
|
12338
|
+
return () => {
|
12339
|
+
clearTimeout(timeout);
|
12340
|
+
};
|
12341
|
+
}, []);
|
12249
12342
|
const groupedCellCount = (_table$getState$group = (_table$getState = table.getState()) === null || _table$getState === void 0 ? void 0 : _table$getState.grouping.length) !== null && _table$getState$group !== void 0 ? _table$getState$group : 0;
|
12250
|
-
const ungroupedCellCount =
|
12343
|
+
const ungroupedCellCount = table.getVisibleFlatColumns().length - groupedCellCount;
|
12251
12344
|
return /*#__PURE__*/React__default.createElement(Skeleton, {
|
12252
12345
|
cellsCount: ungroupedCellCount,
|
12253
|
-
|
12346
|
+
index: index
|
12254
12347
|
});
|
12255
12348
|
}
|
12256
12349
|
const Skeleton = /*#__PURE__*/React__default.forwardRef(function Skeleton(props, ref) {
|
12257
12350
|
const {
|
12258
|
-
cellsCount
|
12351
|
+
cellsCount,
|
12352
|
+
index
|
12259
12353
|
} = props;
|
12260
12354
|
return /*#__PURE__*/React__default.createElement("tr", {
|
12355
|
+
"data-row-index": index,
|
12261
12356
|
ref: ref
|
12262
12357
|
}, Array(cellsCount).fill(null).map((_, index) => (/*#__PURE__*/React__default.createElement("td", {
|
12263
12358
|
key: index
|
@@ -12266,41 +12361,6 @@ const Skeleton = /*#__PURE__*/React__default.forwardRef(function Skeleton(props,
|
|
12266
12361
|
})))));
|
12267
12362
|
});
|
12268
12363
|
|
12269
|
-
const RowContext = /*#__PURE__*/React__default.createContext({
|
12270
|
-
hideInternalColumns: false,
|
12271
|
-
hideRowActions: false,
|
12272
|
-
isHovered: false,
|
12273
|
-
rowIndex: -1
|
12274
|
-
});
|
12275
|
-
|
12276
|
-
/* anonymous functions will break the memoisation on each render, wrap handlers in callbacks */
|
12277
|
-
function Row(props) {
|
12278
|
-
const {
|
12279
|
-
renderer: RowRenderer,
|
12280
|
-
cellRenderer: CellRenderer,
|
12281
|
-
hideInternalColumns = false,
|
12282
|
-
hideRowActions = false,
|
12283
|
-
...displayRowProps
|
12284
|
-
} = props;
|
12285
|
-
const tableMeta = props.table.options.meta;
|
12286
|
-
const isHovered = tableMeta.rowActive.rowHoverIndex === props.index;
|
12287
|
-
// context - it must be here for cells to read it, since they render alongside the row inside DisplayRow
|
12288
|
-
const contextValue = React__default.useMemo(() => ({
|
12289
|
-
isHovered,
|
12290
|
-
rowIndex: props.index,
|
12291
|
-
hideInternalColumns,
|
12292
|
-
hideRowActions
|
12293
|
-
}), [isHovered, props.index, hideInternalColumns, hideRowActions]);
|
12294
|
-
if (props.row.original === undefined) {
|
12295
|
-
return /*#__PURE__*/React__default.createElement(SkeletonRow, Object.assign({}, props));
|
12296
|
-
}
|
12297
|
-
return /*#__PURE__*/React__default.createElement(RowContext.Provider, {
|
12298
|
-
value: contextValue
|
12299
|
-
}, /*#__PURE__*/React__default.createElement(RowRenderer, Object.assign({}, displayRowProps, {
|
12300
|
-
cellRenderer: CellRenderer
|
12301
|
-
})));
|
12302
|
-
}
|
12303
|
-
|
12304
12364
|
// scroll padding end is designed to always show half of the next row
|
12305
12365
|
function getScrollPaddingEndOffset(table) {
|
12306
12366
|
const tableMeta = table.options.meta;
|
@@ -12325,8 +12385,8 @@ function getPaddingEndOffset(table, options) {
|
|
12325
12385
|
const bottomRows = (_table$getBottomRows = table.getBottomRows()) !== null && _table$getBottomRows !== void 0 ? _table$getBottomRows : [];
|
12326
12386
|
return ROW_HEIGHT_ESTIMATES.medium * ((_options$virtualiserP = options === null || options === void 0 ? void 0 : options.virtualiserPaddingEndOffset) !== null && _options$virtualiserP !== void 0 ? _options$virtualiserP : 1) * bottomRows.length;
|
12327
12387
|
}
|
12328
|
-
function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex, options) {
|
12329
|
-
var _table$getState$group, _table$getCenterRows, _virtualItems$padding, _virtualItems$padding2, _virtualItems$padding3,
|
12388
|
+
function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIndex, options) {
|
12389
|
+
var _table$getState$group, _table$getCenterRows, _virtualItems$padding, _virtualItems$padding2, _virtualItems$padding3, _virtualItems$end, _virtualItems;
|
12330
12390
|
const tableMeta = table.options.meta;
|
12331
12391
|
const isTableRowGrouped = !!((_table$getState$group = table.getState().grouping) !== null && _table$getState$group !== void 0 && _table$getState$group.length);
|
12332
12392
|
const rows = (_table$getCenterRows = table.getCenterRows()) !== null && _table$getCenterRows !== void 0 ? _table$getCenterRows : [];
|
@@ -12339,11 +12399,12 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex, opt
|
|
12339
12399
|
const rangeExtractor = useRowGroupVirtualisation(table);
|
12340
12400
|
// account for thead and tfoot in the scroll area - both are always medium row height
|
12341
12401
|
const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;
|
12402
|
+
const count = tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2 ? length : rows.length;
|
12342
12403
|
const virtualiser = reactVirtual.useVirtualizer({
|
12343
|
-
count
|
12404
|
+
count,
|
12344
12405
|
estimateSize,
|
12345
12406
|
getScrollElement: () => tableRef.current,
|
12346
|
-
overscan: tableMeta.printing.isPrinting ?
|
12407
|
+
overscan: tableMeta.printing.isPrinting ? count : undefined,
|
12347
12408
|
rangeExtractor,
|
12348
12409
|
// correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list
|
12349
12410
|
scrollPaddingStart,
|
@@ -12363,19 +12424,19 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex, opt
|
|
12363
12424
|
if (tableRef.current) {
|
12364
12425
|
if (index === 0) {
|
12365
12426
|
virtualiser.scrollToOffset(0, notSmooth);
|
12366
|
-
} else if (index ===
|
12427
|
+
} else if (index === count - 1) {
|
12367
12428
|
// sometimes the last row doesn't fully show, so we just force scroll to the bottom
|
12368
12429
|
tableRef.current.scrollTop = tableRef.current.scrollHeight;
|
12369
12430
|
} else {
|
12370
12431
|
virtualiser.scrollToIndex(index, options);
|
12371
12432
|
}
|
12372
12433
|
}
|
12373
|
-
}, [virtualItems.length, tableRef.current, totalSize,
|
12434
|
+
}, [virtualItems.length, tableRef.current, totalSize, count]);
|
12374
12435
|
// use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0
|
12375
|
-
const paddingStartIndex = isTableRowGrouped &&
|
12436
|
+
const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;
|
12376
12437
|
const startValue = isTableRowGrouped ? ((_virtualItems$padding = virtualItems[paddingStartIndex]) === null || _virtualItems$padding === void 0 ? void 0 : _virtualItems$padding.start) - ((_virtualItems$padding2 = virtualItems[paddingStartIndex]) === null || _virtualItems$padding2 === void 0 ? void 0 : _virtualItems$padding2.size) : (_virtualItems$padding3 = virtualItems[paddingStartIndex]) === null || _virtualItems$padding3 === void 0 ? void 0 : _virtualItems$padding3.start;
|
12377
12438
|
// styling for offsetting rows - this "is" the virtualisation
|
12378
|
-
const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [Math.max(0, startValue !== null && startValue !== void 0 ? startValue : 0), Math.max(0,
|
12439
|
+
const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [Math.max(0, startValue !== null && startValue !== void 0 ? startValue : 0), Math.max(0, totalSize - ((_virtualItems$end = (_virtualItems = virtualItems[virtualItems.length - 1]) === null || _virtualItems === void 0 ? void 0 : _virtualItems.end) !== null && _virtualItems$end !== void 0 ? _virtualItems$end : 0))] : [0, 0];
|
12379
12440
|
// ensure default active rows are scrolled to
|
12380
12441
|
React__default.useEffect(() => {
|
12381
12442
|
if (defaultRowActiveIndex) {
|
@@ -12389,26 +12450,51 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex, opt
|
|
12389
12450
|
let style = {};
|
12390
12451
|
let content = null;
|
12391
12452
|
// bottom rows aren't virtualised (they're sticky) but we need to set the height
|
12392
|
-
if (
|
12453
|
+
if (count || table.getBottomRows().length) {
|
12393
12454
|
style = {
|
12394
12455
|
height: totalSize,
|
12395
|
-
paddingBottom,
|
12396
|
-
paddingTop
|
12456
|
+
paddingBottom: isNaN(paddingBottom) ? 0 : paddingBottom,
|
12457
|
+
paddingTop: isNaN(paddingTop) ? 0 : paddingTop
|
12397
12458
|
};
|
12398
12459
|
}
|
12399
12460
|
// only render non sticky rows
|
12400
|
-
if (
|
12461
|
+
if (count) {
|
12401
12462
|
content = virtualItems.map(virtualRow => {
|
12463
|
+
var _row, _virtualiser$scrollDi2;
|
12402
12464
|
// there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here
|
12403
12465
|
if (!virtualRow) {
|
12404
12466
|
return null;
|
12405
12467
|
}
|
12406
|
-
|
12468
|
+
let row;
|
12469
|
+
if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {
|
12470
|
+
var _tableMeta$server$pag, _tableMeta$server$pag2;
|
12471
|
+
const currentPageIndex = Math.floor(virtualRow.index / tableMeta.server.pageSize) * tableMeta.server.pageSize / tableMeta.server.pageSize;
|
12472
|
+
const pagePosition = (_tableMeta$server$pag = (_tableMeta$server$pag2 = tableMeta.server.pages) === null || _tableMeta$server$pag2 === void 0 ? void 0 : _tableMeta$server$pag2.indexOf(currentPageIndex)) !== null && _tableMeta$server$pag !== void 0 ? _tableMeta$server$pag : -1;
|
12473
|
+
if (pagePosition > -1) {
|
12474
|
+
// "flatten" row indexes down into the dataloader2 dataset size
|
12475
|
+
// for example, with a page size of 100...
|
12476
|
+
// row index 14267 is actually one of index 67, 167, 267 etc within the dataset (depending on number of pages stored)
|
12477
|
+
const fakeIndex = pagePosition * tableMeta.server.pageSize + virtualRow.index % tableMeta.server.pageSize;
|
12478
|
+
row = rows[fakeIndex];
|
12479
|
+
}
|
12480
|
+
} else {
|
12481
|
+
row = rows[virtualRow.index];
|
12482
|
+
}
|
12483
|
+
if (!((_row = row) !== null && _row !== void 0 && _row.original)) {
|
12484
|
+
var _virtualiser$scrollDi;
|
12485
|
+
return /*#__PURE__*/React__default.createElement(SkeletonRow, {
|
12486
|
+
key: virtualRow.index,
|
12487
|
+
index: virtualRow.index,
|
12488
|
+
scrollDirection: (_virtualiser$scrollDi = virtualiser.scrollDirection) !== null && _virtualiser$scrollDi !== void 0 ? _virtualiser$scrollDi : undefined,
|
12489
|
+
table: table
|
12490
|
+
});
|
12491
|
+
}
|
12407
12492
|
const measureRow = createRowMeasurer(virtualiser.resizeItem, virtualRow);
|
12408
12493
|
return /*#__PURE__*/React__default.createElement(Row, {
|
12409
12494
|
key: row.id,
|
12410
12495
|
row: row,
|
12411
12496
|
index: virtualRow.index,
|
12497
|
+
scrollDirection: (_virtualiser$scrollDi2 = virtualiser.scrollDirection) !== null && _virtualiser$scrollDi2 !== void 0 ? _virtualiser$scrollDi2 : undefined,
|
12412
12498
|
table: table,
|
12413
12499
|
measureRow: measureRow,
|
12414
12500
|
renderer: renderers.row,
|
@@ -12715,8 +12801,9 @@ function Header$4(context) {
|
|
12715
12801
|
}
|
12716
12802
|
const _temp = function () {
|
12717
12803
|
if (tableMeta.server.loadAllIfNeeded) {
|
12804
|
+
const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
|
12718
12805
|
// don't pass the search query because we need all data - not filtered data
|
12719
|
-
return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
|
12806
|
+
return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, hiddenColumns, tableMeta.search.enableGlobalFilter ? table.getState().globalFilter : undefined)).then(function () {});
|
12720
12807
|
}
|
12721
12808
|
}();
|
12722
12809
|
// load all data if that is possible
|
@@ -12775,6 +12862,7 @@ function Cell$3(context) {
|
|
12775
12862
|
if (event.shiftKey) {
|
12776
12863
|
var _tableMeta$rowSelecti;
|
12777
12864
|
function _temp4() {
|
12865
|
+
const selectedRows = table.getRowModel().rows.slice(fromIndex, toIndex + 1);
|
12778
12866
|
table.setRowSelection(currentRowSelection => ({
|
12779
12867
|
...currentRowSelection,
|
12780
12868
|
...selectedRows.filter(row => row.getCanSelect()).reduce((state, row) => ({
|
@@ -12784,11 +12872,11 @@ function Cell$3(context) {
|
|
12784
12872
|
}));
|
12785
12873
|
}
|
12786
12874
|
const [fromIndex, toIndex] = toggleBetween((_tableMeta$rowSelecti = tableMeta.rowSelection.lastSelectedRowIndex.current) !== null && _tableMeta$rowSelecti !== void 0 ? _tableMeta$rowSelecti : 0, rowIndex);
|
12787
|
-
const selectedRows = table.getRowModel().rows.slice(fromIndex, toIndex + 1);
|
12788
12875
|
const _temp3 = function () {
|
12789
|
-
if (tableMeta.server.loadAllIfNeeded
|
12876
|
+
if (tableMeta.server.loadAllIfNeeded) {
|
12877
|
+
const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
|
12790
12878
|
// don't pass the search query because we need all data - not filtered data
|
12791
|
-
return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
|
12879
|
+
return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, hiddenColumns, tableMeta.search.enableGlobalFilter ? table.getState().globalFilter : undefined)).then(function () {});
|
12792
12880
|
}
|
12793
12881
|
}();
|
12794
12882
|
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
|
@@ -12846,7 +12934,7 @@ function useTable(props, externalRef, renderers, meta, options) {
|
|
12846
12934
|
// configure the table
|
12847
12935
|
const manager = useTableManager(props, meta, INTERNAL_RENDERERS);
|
12848
12936
|
// configure the virtualised renderer
|
12849
|
-
const renderer = useTableRenderer(renderers, manager.instance, ref, props.defaultRowActiveIndex, options);
|
12937
|
+
const renderer = useTableRenderer(renderers, manager.instance, ref, manager.meta.length, props.defaultRowActiveIndex, options);
|
12850
12938
|
// configure dynamic styling
|
12851
12939
|
const {
|
12852
12940
|
style,
|
@@ -13914,21 +14002,22 @@ function Summary(props) {
|
|
13914
14002
|
locale,
|
13915
14003
|
texts
|
13916
14004
|
} = useLocalization();
|
13917
|
-
const
|
14005
|
+
const tableMeta = table.options.meta;
|
14006
|
+
const length = tableMeta.length;
|
13918
14007
|
const currentLength = table.getRowModel().rows.length;
|
13919
14008
|
let label;
|
13920
14009
|
let count;
|
13921
14010
|
// row selection
|
13922
|
-
|
14011
|
+
// use table state and not the selected row model because of the way server loading works
|
14012
|
+
const rowsSelectedLength = Object.keys(table.getState().rowSelection).length;
|
13923
14013
|
if (rowsSelectedLength > 0) {
|
13924
14014
|
label = texts.table.footer.summary.selected;
|
13925
14015
|
count = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(rowsSelectedLength)), "\u00A0", texts.table.footer.summary.count, "\u00A0", /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(length)));
|
13926
|
-
} else if ((_table$getState$colum = table.getState().columnFilters) !== null && _table$getState$colum !== void 0 && _table$getState$colum.length ||
|
14016
|
+
} else if (!tableMeta.server.isEnabled && ((_table$getState$colum = table.getState().columnFilters) !== null && _table$getState$colum !== void 0 && _table$getState$colum.length ||
|
13927
14017
|
// filtered data
|
13928
|
-
!!table.getState().globalFilter && table.options.enableGlobalFilter
|
13929
|
-
) {
|
14018
|
+
!!table.getState().globalFilter && table.options.enableGlobalFilter)) {
|
13930
14019
|
label = texts.table.footer.summary.records;
|
13931
|
-
count = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("strong", null, currentLength), "\u00A0", texts.table.footer.summary.count, "\u00A0", /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(length)));
|
14020
|
+
count = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(currentLength)), "\u00A0", texts.table.footer.summary.count, "\u00A0", /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(length)));
|
13932
14021
|
} else {
|
13933
14022
|
label = texts.table.footer.summary.records;
|
13934
14023
|
count = /*#__PURE__*/React__default.createElement("strong", null, new Intl.NumberFormat(locale).format(length));
|
@@ -14035,6 +14124,7 @@ const SearchInput2 = /*#__PURE__*/React__default.forwardRef(function SearchInput
|
|
14035
14124
|
onClickFindPrevious: handleClickFindPrevious,
|
14036
14125
|
settingsContent,
|
14037
14126
|
shortcut,
|
14127
|
+
showTotal = true,
|
14038
14128
|
value,
|
14039
14129
|
...attributes
|
14040
14130
|
} = props;
|
@@ -14113,10 +14203,12 @@ const SearchInput2 = /*#__PURE__*/React__default.forwardRef(function SearchInput
|
|
14113
14203
|
}
|
14114
14204
|
if (hasFind && isActive) {
|
14115
14205
|
postfix = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("span", {
|
14116
|
-
className: "text-grey-700 flex h-4 items-center
|
14117
|
-
}, loading ? /*#__PURE__*/React__default.createElement(Spinner, {
|
14206
|
+
className: "text-grey-700 flex h-4 items-center"
|
14207
|
+
}, loading ? (/*#__PURE__*/React__default.createElement(Spinner, {
|
14118
14208
|
className: "h-4 w-4"
|
14119
|
-
}) :
|
14209
|
+
})) : showTotal ? (/*#__PURE__*/React__default.createElement("span", {
|
14210
|
+
className: "border-r border-black/[0.25] pr-2"
|
14211
|
+
}, `${findCurrent !== null && findCurrent !== void 0 ? findCurrent : 0}/${findTotal !== null && findTotal !== void 0 ? findTotal : 0}`)) : null), findCurrent ? (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(IconButton, {
|
14120
14212
|
"aria-label": texts.searchInput.findPrevious,
|
14121
14213
|
className: "scale-75 !bg-transparent hover:!bg-black/[0.08] [&>svg]:scale-125",
|
14122
14214
|
icon: "chevron-up",
|
@@ -14220,6 +14312,7 @@ function Search$1(props) {
|
|
14220
14312
|
const scrollTo = rowIndex => scrollToIndex(rowIndex, {
|
14221
14313
|
align: 'center'
|
14222
14314
|
});
|
14315
|
+
const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
|
14223
14316
|
React__default.useEffect(() => {
|
14224
14317
|
if (tableMeta.search.highlightedColumnIndexes.length) {
|
14225
14318
|
scrollTo(tableMeta.search.highlightedColumnIndexes[0][0]);
|
@@ -14228,9 +14321,11 @@ function Search$1(props) {
|
|
14228
14321
|
const handleFocus = function () {
|
14229
14322
|
try {
|
14230
14323
|
const _temp = function () {
|
14231
|
-
if (tableMeta.server.loadAllIfNeeded) {
|
14324
|
+
if (tableMeta.server.loadAllIfNeeded && !tableMeta.server._experimentalDataLoader2) {
|
14232
14325
|
// don't pass the search query because we need all data - not filtered data
|
14233
|
-
return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters
|
14326
|
+
return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, hiddenColumns,
|
14327
|
+
// the old data loader doesn't have server side search
|
14328
|
+
undefined)).then(function () {});
|
14234
14329
|
}
|
14235
14330
|
}();
|
14236
14331
|
// load all data if that is possible
|
@@ -14239,8 +14334,20 @@ function Search$1(props) {
|
|
14239
14334
|
return Promise.reject(e);
|
14240
14335
|
}
|
14241
14336
|
};
|
14337
|
+
const [loading, setLoading] = React__default.useState(false);
|
14338
|
+
const searchTimeoutRef = React__default.useRef();
|
14242
14339
|
const handleChange = query => {
|
14243
14340
|
table.setGlobalFilter(String(query !== null && query !== void 0 ? query : ''));
|
14341
|
+
if (tableMeta.search.enableGlobalFilter && tableMeta.search.handleSearch) {
|
14342
|
+
clearTimeout(searchTimeoutRef.current);
|
14343
|
+
searchTimeoutRef.current = setTimeout(() => {
|
14344
|
+
var _tableMeta$search$han, _tableMeta$search;
|
14345
|
+
setLoading(true);
|
14346
|
+
(_tableMeta$search$han = (_tableMeta$search = tableMeta.search).handleSearch) === null || _tableMeta$search$han === void 0 ? void 0 : _tableMeta$search$han.call(_tableMeta$search, query, hiddenColumns).then(() => {
|
14347
|
+
setLoading(false);
|
14348
|
+
});
|
14349
|
+
}, 150);
|
14350
|
+
}
|
14244
14351
|
};
|
14245
14352
|
const handleToggleExcludeUnmatchedResults = enabled => {
|
14246
14353
|
tableMeta.search.setEnableGlobalFilter(enabled, table);
|
@@ -14248,6 +14355,12 @@ function Search$1(props) {
|
|
14248
14355
|
var _ref$current;
|
14249
14356
|
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
14250
14357
|
});
|
14358
|
+
if (tableMeta.search.handleSearch) {
|
14359
|
+
setLoading(true);
|
14360
|
+
tableMeta.search.handleSearch(enabled ? query : undefined, hiddenColumns).then(() => {
|
14361
|
+
setLoading(false);
|
14362
|
+
});
|
14363
|
+
}
|
14251
14364
|
};
|
14252
14365
|
const handleNextResult = () => {
|
14253
14366
|
if (!tableMeta.search.highlightedColumnIndexes.length) {
|
@@ -14291,7 +14404,7 @@ function Search$1(props) {
|
|
14291
14404
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(SearchInput2, {
|
14292
14405
|
findCurrent: tableMeta.search.currentHighlightColumnIndex !== undefined ? tableMeta.search.currentHighlightColumnIndex + 1 : null,
|
14293
14406
|
findTotal: (_tableMeta$search$hig = (_tableMeta$search$hig2 = tableMeta.search.highlightedColumnIndexes) === null || _tableMeta$search$hig2 === void 0 ? void 0 : _tableMeta$search$hig2.length) !== null && _tableMeta$search$hig !== void 0 ? _tableMeta$search$hig : null,
|
14294
|
-
loading: tableMeta.server.loading,
|
14407
|
+
loading: tableMeta.server._experimentalDataLoader2 ? loading : tableMeta.server.loading,
|
14295
14408
|
name: "table-search",
|
14296
14409
|
onClickFindPrevious: handlePreviousResult,
|
14297
14410
|
onClickFindNext: handleNextResult,
|
@@ -14306,6 +14419,7 @@ function Search$1(props) {
|
|
14306
14419
|
meta: true,
|
14307
14420
|
shift: false
|
14308
14421
|
},
|
14422
|
+
showTotal: !tableMeta.server._experimentalDataLoader2,
|
14309
14423
|
value: query
|
14310
14424
|
}));
|
14311
14425
|
}
|
@@ -16392,8 +16506,9 @@ function Print$1(props) {
|
|
16392
16506
|
const toastRef = toast.loading(texts.table.print.loading);
|
16393
16507
|
const _temp2 = function () {
|
16394
16508
|
if (tableMeta.server.isEnabled && tableMeta.server.loadAllIfNeeded) {
|
16509
|
+
const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
|
16395
16510
|
const _temp = _catch(function () {
|
16396
|
-
return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
|
16511
|
+
return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, hiddenColumns, tableMeta.search.enableGlobalFilter ? table.getState().globalFilter : undefined)).then(function () {});
|
16397
16512
|
}, function (error) {
|
16398
16513
|
const errorMessage = `${texts.table.print.error}: ${error}`;
|
16399
16514
|
console.error(errorMessage);
|
@@ -18759,18 +18874,21 @@ function useTableEditingListener(table, tableRef, scrollToIndex) {
|
|
18759
18874
|
document.addEventListener('click', onClickOutside);
|
18760
18875
|
return () => document.removeEventListener('click', onClickOutside);
|
18761
18876
|
}, [tableMeta.editing.isEditing, tableMeta.editing.saveChanges]);
|
18762
|
-
|
18763
|
-
|
18764
|
-
|
18765
|
-
|
18766
|
-
|
18767
|
-
|
18768
|
-
|
18769
|
-
|
18770
|
-
|
18771
|
-
|
18772
|
-
|
18773
|
-
|
18877
|
+
/*
|
18878
|
+
const rows = table.getRowModel().rows;
|
18879
|
+
// make sure pending changes are removed for rows that no longer exist
|
18880
|
+
useLazyEffect(() => {
|
18881
|
+
const pendingChanges = tableMeta.editing.getErrorsShownInAlert();
|
18882
|
+
pendingChanges.forEach(pendingChange => {
|
18883
|
+
try {
|
18884
|
+
table.getRow(pendingChange.rowId);
|
18885
|
+
} catch {
|
18886
|
+
// TODO: this has the potential to remove changes for "unloaded" rows in server loading
|
18887
|
+
//tableMeta.editing.discardChanges(pendingChange.rowId, table);
|
18888
|
+
}
|
18889
|
+
});
|
18890
|
+
}, [rows.length]);
|
18891
|
+
*/
|
18774
18892
|
// shortcuts
|
18775
18893
|
useGlobalKeyDown(tableMeta.editing.isEnabled ? shortcut : undefined, event => {
|
18776
18894
|
event.preventDefault();
|
@@ -18798,6 +18916,7 @@ function reducer$2(state, action) {
|
|
18798
18916
|
{
|
18799
18917
|
const {
|
18800
18918
|
columnId,
|
18919
|
+
index,
|
18801
18920
|
row,
|
18802
18921
|
value
|
18803
18922
|
} = payload;
|
@@ -18807,7 +18926,8 @@ function reducer$2(state, action) {
|
|
18807
18926
|
...state.changes,
|
18808
18927
|
rows: setWith(state.changes.rows, `${rowId}.${columnId}`, value, Object),
|
18809
18928
|
originals: setWith(state.changes.originals, rowId, row, Object)
|
18810
|
-
}
|
18929
|
+
},
|
18930
|
+
indexes: setWith(state.indexes, rowId, index, Object)
|
18811
18931
|
};
|
18812
18932
|
}
|
18813
18933
|
case 'removeCellValue':
|
@@ -18841,6 +18961,7 @@ function reducer$2(state, action) {
|
|
18841
18961
|
{
|
18842
18962
|
const {
|
18843
18963
|
cellErrors,
|
18964
|
+
index,
|
18844
18965
|
moveReasons,
|
18845
18966
|
original,
|
18846
18967
|
value
|
@@ -18855,7 +18976,8 @@ function reducer$2(state, action) {
|
|
18855
18976
|
moveReasons: setWith(state.changes.moveReasons, rowId, moveReasons !== null && moveReasons !== void 0 ? moveReasons : state.changes.moveReasons[rowId], Object),
|
18856
18977
|
// status can be undefined, so don't use ??
|
18857
18978
|
status: setWith(state.changes.status, rowId, undefined, Object)
|
18858
|
-
}
|
18979
|
+
},
|
18980
|
+
indexes: setWith(state.indexes, rowId, index, Object)
|
18859
18981
|
};
|
18860
18982
|
}
|
18861
18983
|
case 'removeRow':
|
@@ -18873,6 +18995,7 @@ function reducer$2(state, action) {
|
|
18873
18995
|
originals: omit(state.changes.originals, rowId),
|
18874
18996
|
status: omit(state.changes.status, rowId)
|
18875
18997
|
},
|
18998
|
+
indexes: omit(state.indexes, rowId),
|
18876
18999
|
temporaryRows: state.temporaryRows.filter(row => row[rowIdentityAccessor] !== rowId)
|
18877
19000
|
};
|
18878
19001
|
}
|
@@ -18905,6 +19028,7 @@ function reducer$2(state, action) {
|
|
18905
19028
|
case 'insertTemporaryRow':
|
18906
19029
|
{
|
18907
19030
|
const {
|
19031
|
+
index,
|
18908
19032
|
value
|
18909
19033
|
} = payload;
|
18910
19034
|
return {
|
@@ -18914,14 +19038,36 @@ function reducer$2(state, action) {
|
|
18914
19038
|
...state.changes,
|
18915
19039
|
rows: setWith(state.changes.rows, rowId, value, Object),
|
18916
19040
|
originals: setWith(state.changes.originals, rowId, value, Object)
|
18917
|
-
}
|
19041
|
+
},
|
19042
|
+
indexes: setWith(state.indexes, rowId, index, Object)
|
18918
19043
|
};
|
18919
19044
|
}
|
18920
19045
|
default:
|
18921
19046
|
return state;
|
18922
19047
|
}
|
18923
19048
|
}
|
18924
|
-
function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, validator) {
|
19049
|
+
function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIdentityAccessor, validator) {
|
19050
|
+
const discardChanges = function (rowId, table) {
|
19051
|
+
try {
|
19052
|
+
// remove any new rows from pinned state before discarding them
|
19053
|
+
table.resetRowPinning(true);
|
19054
|
+
dispatch({
|
19055
|
+
type: 'removeRow',
|
19056
|
+
rowId,
|
19057
|
+
payload: {
|
19058
|
+
rowIdentityAccessor
|
19059
|
+
}
|
19060
|
+
});
|
19061
|
+
const _temp8 = function () {
|
19062
|
+
if (typeof handleDiscard === 'function') {
|
19063
|
+
return Promise.resolve(handleDiscard()).then(function () {});
|
19064
|
+
}
|
19065
|
+
}();
|
19066
|
+
return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(function () {}) : void 0);
|
19067
|
+
} catch (e) {
|
19068
|
+
return Promise.reject(e);
|
19069
|
+
}
|
19070
|
+
};
|
18925
19071
|
const saveChanges = function (table, rowId = undefined) {
|
18926
19072
|
try {
|
18927
19073
|
let _exit = false;
|
@@ -18934,19 +19080,20 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
18934
19080
|
[rowId]: state.changes.rows[rowId]
|
18935
19081
|
} : state.changes.rows;
|
18936
19082
|
let completed = true;
|
18937
|
-
const
|
19083
|
+
const _temp7 = _forOf(Object.keys(changes), function (rowId) {
|
18938
19084
|
const status = getRowStatus(rowId);
|
18939
19085
|
return _catch(function () {
|
18940
19086
|
var _changes$rowId;
|
18941
|
-
function
|
19087
|
+
function _temp6(_result) {
|
18942
19088
|
return _exit ? _result : Promise.resolve(handleSave(changeSet)).then(function () {
|
18943
19089
|
// cleanup changes, we don't need them after saving
|
18944
|
-
discardChanges(rowId, table)
|
18945
|
-
|
18946
|
-
|
18947
|
-
|
18948
|
-
|
18949
|
-
|
19090
|
+
return Promise.resolve(discardChanges(rowId, table)).then(function () {
|
19091
|
+
// show the saved status, then remove it after a delay
|
19092
|
+
setRowStatus(rowId, 'saved');
|
19093
|
+
setTimeout(() => {
|
19094
|
+
setRowStatus(rowId, undefined);
|
19095
|
+
}, DELAY_BEFORE_REMOVING_SAVE_STATUS);
|
19096
|
+
});
|
18950
19097
|
});
|
18951
19098
|
}
|
18952
19099
|
const rowChanges = (_changes$rowId = changes[rowId]) !== null && _changes$rowId !== void 0 ? _changes$rowId : {};
|
@@ -18964,7 +19111,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
18964
19111
|
delete changeSet[rowIdentityAccessor];
|
18965
19112
|
}
|
18966
19113
|
// re-run validation, maybe a cell is already invalid but has never been blurred
|
18967
|
-
const
|
19114
|
+
const _temp5 = function () {
|
18968
19115
|
if (validator) {
|
18969
19116
|
return Promise.resolve(validator(changeSet)).then(function (errors) {
|
18970
19117
|
if (errors && Object.keys(errors).length) {
|
@@ -18973,7 +19120,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
18973
19120
|
});
|
18974
19121
|
}
|
18975
19122
|
}();
|
18976
|
-
return
|
19123
|
+
return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5); // send new data to the server
|
18977
19124
|
}, function (error) {
|
18978
19125
|
var _error$response;
|
18979
19126
|
if (error instanceof ReferenceError || error instanceof TypeError || (error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) >= 500) {
|
@@ -19013,18 +19160,18 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19013
19160
|
}, function () {
|
19014
19161
|
return _exit;
|
19015
19162
|
});
|
19016
|
-
return Promise.resolve(
|
19163
|
+
return Promise.resolve(_temp7 && _temp7.then ? _temp7.then(function (_result3) {
|
19017
19164
|
return _exit ? _result3 : completed;
|
19018
|
-
}) : _exit ?
|
19165
|
+
}) : _exit ? _temp7 : completed);
|
19019
19166
|
} catch (e) {
|
19020
19167
|
return Promise.reject(e);
|
19021
19168
|
}
|
19022
19169
|
};
|
19023
19170
|
const onCellChanged = function (cell, rowIndex, nextValue, shouldRunUpdaters = true) {
|
19024
19171
|
try {
|
19025
|
-
function
|
19172
|
+
function _temp4() {
|
19026
19173
|
var _state$changes$errors11;
|
19027
|
-
function
|
19174
|
+
function _temp2() {
|
19028
19175
|
// only set errors and move reasons for the cells we're currently acting on
|
19029
19176
|
// why? because the UX is not good if we set them for cells the user hasn't touched yet
|
19030
19177
|
const cellsToActOn = [cell.column.id, ...Object.keys(updatesForOtherCells)];
|
@@ -19055,6 +19202,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19055
19202
|
rowId: cell.row.id,
|
19056
19203
|
payload: {
|
19057
19204
|
cellErrors: nextCellErrors,
|
19205
|
+
index: rowIndex,
|
19058
19206
|
moveReasons: nextMoveReasons,
|
19059
19207
|
value: nextChanges
|
19060
19208
|
}
|
@@ -19073,7 +19221,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19073
19221
|
};
|
19074
19222
|
// run validation - if there are changes, and if there is an original stored
|
19075
19223
|
let validationErrors = {};
|
19076
|
-
const
|
19224
|
+
const _temp = function () {
|
19077
19225
|
if (validator && Object.keys(nextChanges).length && state.changes.originals[cell.row.id]) {
|
19078
19226
|
// merge with the original so we get a full row
|
19079
19227
|
const nextRowValue = {
|
@@ -19081,12 +19229,12 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19081
19229
|
...changes,
|
19082
19230
|
...updatesForOtherCells
|
19083
19231
|
};
|
19084
|
-
return Promise.resolve(validator(nextRowValue)).then(function (
|
19085
|
-
validationErrors =
|
19232
|
+
return Promise.resolve(validator(nextRowValue)).then(function (_validator) {
|
19233
|
+
validationErrors = _validator !== null && _validator !== void 0 ? _validator : {};
|
19086
19234
|
});
|
19087
19235
|
}
|
19088
19236
|
}();
|
19089
|
-
return
|
19237
|
+
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
|
19090
19238
|
}
|
19091
19239
|
const changes = nextValue !== undefined ? {
|
19092
19240
|
...state.changes.rows[cell.row.id],
|
@@ -19099,7 +19247,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19099
19247
|
}
|
19100
19248
|
let updatesForOtherCells = {};
|
19101
19249
|
// run the updater handler if there is one, to see if there are any other cells to update
|
19102
|
-
const
|
19250
|
+
const _temp3 = function () {
|
19103
19251
|
if (typeof handleChange === 'function' && shouldRunUpdaters) {
|
19104
19252
|
const previousRowValue = {
|
19105
19253
|
...state.changes.originals[cell.row.id]
|
@@ -19113,42 +19261,11 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19113
19261
|
});
|
19114
19262
|
}
|
19115
19263
|
}();
|
19116
|
-
return Promise.resolve(
|
19264
|
+
return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3));
|
19117
19265
|
} catch (e) {
|
19118
19266
|
return Promise.reject(e);
|
19119
19267
|
}
|
19120
19268
|
}; // general
|
19121
|
-
// rows
|
19122
|
-
const setRowValue = function (rowId, original, value) {
|
19123
|
-
try {
|
19124
|
-
function _temp2() {
|
19125
|
-
dispatch({
|
19126
|
-
type: 'updateRow',
|
19127
|
-
rowId,
|
19128
|
-
payload: {
|
19129
|
-
cellErrors,
|
19130
|
-
original,
|
19131
|
-
value
|
19132
|
-
}
|
19133
|
-
});
|
19134
|
-
}
|
19135
|
-
let cellErrors;
|
19136
|
-
const _temp = function () {
|
19137
|
-
if (validator) {
|
19138
|
-
const row = {
|
19139
|
-
...original,
|
19140
|
-
...value
|
19141
|
-
};
|
19142
|
-
return Promise.resolve(validator(row)).then(function (_validator) {
|
19143
|
-
cellErrors = _validator !== null && _validator !== void 0 ? _validator : {};
|
19144
|
-
});
|
19145
|
-
}
|
19146
|
-
}();
|
19147
|
-
return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
|
19148
|
-
} catch (e) {
|
19149
|
-
return Promise.reject(e);
|
19150
|
-
}
|
19151
|
-
};
|
19152
19269
|
const localization = useLocalization();
|
19153
19270
|
const [state, dispatch] = React__default.useReducer(reducer$2, {
|
19154
19271
|
changes: {
|
@@ -19158,8 +19275,10 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19158
19275
|
originals: {},
|
19159
19276
|
status: {}
|
19160
19277
|
},
|
19278
|
+
indexes: {},
|
19161
19279
|
temporaryRows: []
|
19162
19280
|
});
|
19281
|
+
// rows
|
19163
19282
|
function getRowValue(rowId) {
|
19164
19283
|
var _state$changes$rows$r, _state$changes$rows;
|
19165
19284
|
return (_state$changes$rows$r = (_state$changes$rows = state.changes.rows) === null || _state$changes$rows === void 0 ? void 0 : _state$changes$rows[rowId]) !== null && _state$changes$rows$r !== void 0 ? _state$changes$rows$r : undefined;
|
@@ -19197,7 +19316,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19197
19316
|
}
|
19198
19317
|
});
|
19199
19318
|
}
|
19200
|
-
function insertTemporaryRow(data) {
|
19319
|
+
function insertTemporaryRow(data, rowIndex) {
|
19201
19320
|
const newRowId = `${TEMPORARY_ROW_ID_PREFIX}${uuid.v4()}`;
|
19202
19321
|
const value = {
|
19203
19322
|
...data,
|
@@ -19207,13 +19326,14 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19207
19326
|
type: 'insertTemporaryRow',
|
19208
19327
|
rowId: newRowId,
|
19209
19328
|
payload: {
|
19329
|
+
index: rowIndex,
|
19210
19330
|
value
|
19211
19331
|
}
|
19212
19332
|
});
|
19213
19333
|
return newRowId;
|
19214
19334
|
}
|
19215
19335
|
// cells
|
19216
|
-
function setCellValue(cell, value) {
|
19336
|
+
function setCellValue(cell, rowIndex, value) {
|
19217
19337
|
const rowId = cell.row.id;
|
19218
19338
|
const columnId = cell.column.id;
|
19219
19339
|
// update if the change is different to the original value
|
@@ -19223,6 +19343,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19223
19343
|
rowId,
|
19224
19344
|
payload: {
|
19225
19345
|
columnId,
|
19346
|
+
index: rowIndex,
|
19226
19347
|
row: cell.row.original,
|
19227
19348
|
value
|
19228
19349
|
}
|
@@ -19255,6 +19376,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19255
19376
|
}
|
19256
19377
|
return rowsWithErrors.filter(hasRowErrorsShownInAlert).map(rowId => ({
|
19257
19378
|
rowId,
|
19379
|
+
index: state.indexes[rowId],
|
19258
19380
|
changes: state.changes.rows[rowId],
|
19259
19381
|
errors: state.changes.errors[rowId]
|
19260
19382
|
}));
|
@@ -19265,20 +19387,8 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19265
19387
|
function hasChanges(rowId) {
|
19266
19388
|
return rowId ? !!state.changes.rows[rowId] : !!Object.keys(state.changes.rows).length;
|
19267
19389
|
}
|
19268
|
-
function discardChanges(rowId, table) {
|
19269
|
-
// remove any new rows from pinned state before discarding them
|
19270
|
-
table.resetRowPinning(true);
|
19271
|
-
dispatch({
|
19272
|
-
type: 'removeRow',
|
19273
|
-
rowId,
|
19274
|
-
payload: {
|
19275
|
-
rowIdentityAccessor
|
19276
|
-
}
|
19277
|
-
});
|
19278
|
-
}
|
19279
19390
|
return {
|
19280
19391
|
// row
|
19281
|
-
setRowValue,
|
19282
19392
|
getRowValue,
|
19283
19393
|
getRowMoveReason,
|
19284
19394
|
hasRowErrors,
|
@@ -19303,7 +19413,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
|
|
19303
19413
|
};
|
19304
19414
|
}
|
19305
19415
|
|
19306
|
-
function useTableEditing(isEnabled = false, handleSave, handleChange, handleCreate, rowIdentityAccessor, validator) {
|
19416
|
+
function useTableEditing(isEnabled = false, handleSave, handleChange, handleCreate, handleDiscard, rowIdentityAccessor, validator) {
|
19307
19417
|
const createRow = function (table, scrollToIndex, row) {
|
19308
19418
|
try {
|
19309
19419
|
let _exit = false;
|
@@ -19312,17 +19422,24 @@ function useTableEditing(isEnabled = false, handleSave, handleChange, handleCrea
|
|
19312
19422
|
const changeset = row !== null && row !== void 0 ? row : handleCreate();
|
19313
19423
|
try {
|
19314
19424
|
if (changeset) {
|
19315
|
-
const newRowId = pendingChangesFns.insertTemporaryRow(changeset);
|
19316
|
-
// reset before changing row otherwise the cell changes and validation might run
|
19317
|
-
setLastFocusedCellIndex(undefined);
|
19318
19425
|
// set the active row to the new row before toggling editing on
|
19319
19426
|
const temporaryRows = tableMeta.editing.temporaryRows;
|
19320
19427
|
const nextRowIndex = temporaryRows.length ? tableMeta.length + 1 : tableMeta.length;
|
19428
|
+
const newRowId = pendingChangesFns.insertTemporaryRow(changeset, nextRowIndex);
|
19429
|
+
// reset before changing row otherwise the cell changes and validation might run
|
19430
|
+
setLastFocusedCellIndex(undefined);
|
19431
|
+
// set the active row to the new row before toggling editing on
|
19321
19432
|
tableMeta.rowActive.setRowActiveIndex(nextRowIndex);
|
19322
19433
|
// wait until set states have run
|
19323
19434
|
requestAnimationFrame(() => {
|
19324
19435
|
toggleEditing(true, table, scrollToIndex, false);
|
19325
|
-
table.
|
19436
|
+
table.setRowPinning(currentState => {
|
19437
|
+
var _ref, _currentState$bottom;
|
19438
|
+
return {
|
19439
|
+
...currentState,
|
19440
|
+
bottom: (_ref = (_currentState$bottom = currentState.bottom) !== null && _currentState$bottom !== void 0 ? _currentState$bottom : []) === null || _ref === void 0 ? void 0 : _ref.concat(newRowId)
|
19441
|
+
};
|
19442
|
+
});
|
19326
19443
|
});
|
19327
19444
|
}
|
19328
19445
|
} catch (error) {
|
@@ -19356,7 +19473,7 @@ function useTableEditing(isEnabled = false, handleSave, handleChange, handleCrea
|
|
19356
19473
|
const createRowButtonRef = React__default.useRef(null);
|
19357
19474
|
// store the last focused cell, so that up/down arrow key navigation remains in the same column
|
19358
19475
|
const [lastFocusedCellIndex, setLastFocusedCellIndex] = React__default.useState(undefined);
|
19359
|
-
const pendingChangesFns = usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, validator);
|
19476
|
+
const pendingChangesFns = usePendingChangesState(handleSave, handleChange, handleDiscard, rowIdentityAccessor, validator);
|
19360
19477
|
function toggleEditing(enabled, table, scrollToIndex, doSave = true) {
|
19361
19478
|
const tableMeta = table.options.meta;
|
19362
19479
|
if (enabled) {
|
@@ -19646,7 +19763,7 @@ function EditingControlCell(props) {
|
|
19646
19763
|
}, [cellRef.current]);
|
19647
19764
|
const handleChange = React__default.useCallback(nextValue => {
|
19648
19765
|
if (nextValue !== value) {
|
19649
|
-
tableMeta.editing.setCellValue(cell, nextValue);
|
19766
|
+
tableMeta.editing.setCellValue(cell, rowIndex, nextValue);
|
19650
19767
|
if (hasNonTextControl) {
|
19651
19768
|
requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue));
|
19652
19769
|
}
|
@@ -20067,7 +20184,7 @@ const RENDERERS$1 = {
|
|
20067
20184
|
cell: Cell$5
|
20068
20185
|
};
|
20069
20186
|
function useTable3(props, ref) {
|
20070
|
-
const editing = useTableEditing(props.enableEditing, props.onEditingSave, props.onEditingChange, props.onEditingCreate, props.rowIdentityAccessor, props.validator);
|
20187
|
+
const editing = useTableEditing(props.enableEditing, props.onEditingSave, props.onEditingChange, props.onEditingCreate, props.onEditingDiscard, props.rowIdentityAccessor, props.validator);
|
20071
20188
|
const creationEnabled = editing.isEnabled && !!props.onEditingCreate;
|
20072
20189
|
// this gives me the performance heeby jeebies, but can't think of a better way to internalise the state
|
20073
20190
|
const data = React__default.useMemo(() => {
|
@@ -20164,20 +20281,22 @@ function Alert$1(props) {
|
|
20164
20281
|
// table.getColumn(columName) throw error in strict dev mode. Related thread: https://github.com/TanStack/table/discussions/5505
|
20165
20282
|
table.getAllColumns().find(x => x.id === String(tableMeta.rowIdentityAccessor)) : undefined;
|
20166
20283
|
pendingChangesWithErrors.forEach((pendingChangeWithError, index) => {
|
20284
|
+
var _row;
|
20167
20285
|
// if appropriate, concatenate the item with the text "and"
|
20168
20286
|
if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {
|
20169
20287
|
// Add space before and after `messageAnd` text
|
20170
20288
|
links.push(` ${validationTexts.alert.messageAnd} `);
|
20171
20289
|
}
|
20172
|
-
|
20290
|
+
// note: if this row click functionality is removed, indexes can be removed from useEditingState
|
20173
20291
|
const handleClick = () => {
|
20174
20292
|
// if row is visible
|
20175
|
-
if (
|
20176
|
-
scrollToRow(
|
20293
|
+
if (pendingChangeWithError.index > -1) {
|
20294
|
+
scrollToRow(pendingChangeWithError.index);
|
20295
|
+
tableMeta.rowActive.setRowActiveIndex(pendingChangeWithError.index);
|
20177
20296
|
}
|
20178
20297
|
// if row is filtered out
|
20179
20298
|
else {
|
20180
|
-
setShowFilterResetDialog(pendingChangeWithError.
|
20299
|
+
setShowFilterResetDialog(pendingChangeWithError.index);
|
20181
20300
|
}
|
20182
20301
|
};
|
20183
20302
|
let tooltip;
|
@@ -20189,7 +20308,12 @@ function Alert$1(props) {
|
|
20189
20308
|
const columnName = (_table$getAllColumns$ = table.getAllColumns().find(column => column.id === firstCellErrorColumnId)) === null || _table$getAllColumns$ === void 0 ? void 0 : (_table$getAllColumns$2 = _table$getAllColumns$.columnDef.meta) === null || _table$getAllColumns$2 === void 0 ? void 0 : _table$getAllColumns$2.header;
|
20190
20309
|
tooltip = `${columnName}: ${pendingChangeWithError.errors.cells[firstCellErrorColumnId]}`;
|
20191
20310
|
}
|
20192
|
-
|
20311
|
+
let row;
|
20312
|
+
try {
|
20313
|
+
row = table.getRow(pendingChangeWithError.rowId).original;
|
20314
|
+
} catch {
|
20315
|
+
// because of server loading, some rows may not be accessible
|
20316
|
+
}
|
20193
20317
|
links.push(/*#__PURE__*/React__default.createElement(Tooltip, {
|
20194
20318
|
key: pendingChangeWithError.rowId,
|
20195
20319
|
title: tooltip
|
@@ -20197,7 +20321,7 @@ function Alert$1(props) {
|
|
20197
20321
|
className: "text-blue",
|
20198
20322
|
onClick: handleClick,
|
20199
20323
|
role: "button"
|
20200
|
-
}, rowIdentityColumn ? row[rowIdentityColumn.id] :
|
20324
|
+
}, rowIdentityColumn ? (_row = row) === null || _row === void 0 ? void 0 : _row[rowIdentityColumn.id] : pendingChangeWithError.index + 1)));
|
20201
20325
|
// if appropriate, concatenate the item with the text ","
|
20202
20326
|
if (pendingChangesWithErrors.length > 2 && index < pendingChangesWithErrors.length - 2) {
|
20203
20327
|
links.push(', ');
|
@@ -20218,9 +20342,8 @@ function Alert$1(props) {
|
|
20218
20342
|
table.resetGlobalFilter();
|
20219
20343
|
table.resetColumnFilters();
|
20220
20344
|
requestAnimationFrame(() => {
|
20221
|
-
|
20222
|
-
|
20223
|
-
scrollToRow(rowIndex);
|
20345
|
+
if (showFilterResetDialog && showFilterResetDialog > -1) {
|
20346
|
+
scrollToRow(showFilterResetDialog);
|
20224
20347
|
}
|
20225
20348
|
setShowFilterResetDialog(false);
|
20226
20349
|
});
|
@@ -20301,7 +20424,9 @@ function CreateNewRow(props) {
|
|
20301
20424
|
if (isDisabled) {
|
20302
20425
|
return Promise.resolve();
|
20303
20426
|
}
|
20304
|
-
return Promise.resolve(tableMeta.editing.createRow(table, scrollToIndex)).then(function () {
|
20427
|
+
return Promise.resolve(tableMeta.editing.createRow(table, scrollToIndex)).then(function () {
|
20428
|
+
table.resetRowSelection();
|
20429
|
+
});
|
20305
20430
|
} catch (e) {
|
20306
20431
|
return Promise.reject(e);
|
20307
20432
|
}
|
@@ -20320,7 +20445,7 @@ function CreateNewRow(props) {
|
|
20320
20445
|
keys: shortcut
|
20321
20446
|
});
|
20322
20447
|
}
|
20323
|
-
const className = cn('group/row border-grey-300 !sticky z-[21]', {
|
20448
|
+
const className = cn('group/row border-grey-300 !sticky z-[21] print:hidden', {
|
20324
20449
|
'bottom-10': tableMeta.footer.isEnabled,
|
20325
20450
|
'bottom-0': !tableMeta.footer.isEnabled,
|
20326
20451
|
'border-b': !isScrolled
|
@@ -20410,7 +20535,7 @@ function TemporaryRow(props) {
|
|
20410
20535
|
}
|
20411
20536
|
}
|
20412
20537
|
};
|
20413
|
-
const className = cn('group/row border-grey-300 !sticky z-[22]', {
|
20538
|
+
const className = cn('group/row border-grey-300 !sticky z-[22] print:hidden', {
|
20414
20539
|
'bottom-[calc(5rem_+_2px)] data-[row-editing-move]:bottom-[calc(5rem_+_2px)]': tableMeta.footer.isEnabled,
|
20415
20540
|
'bottom-[calc(2.5rem_+_2px)] data-[row-editing-move]:bottom-[calc(2.5rem_+_2px)]': !tableMeta.footer.isEnabled,
|
20416
20541
|
'border-t-2 shadow-[0px_-5px_20px_0px_rgba(0,0,0,0.1)] [&>td]:!border-b-0': isScrolled
|
@@ -20427,7 +20552,8 @@ function TemporaryRow(props) {
|
|
20427
20552
|
onKeyDown: handleKeyDown,
|
20428
20553
|
onKeyDownCapture: handleKeyDownCapture,
|
20429
20554
|
hideInternalColumns: true,
|
20430
|
-
hideRowActions: !tableMeta.editing.isEditing
|
20555
|
+
hideRowActions: !tableMeta.editing.isEditing,
|
20556
|
+
skipPageLoading: true
|
20431
20557
|
}))));
|
20432
20558
|
}
|
20433
20559
|
|
@@ -22216,6 +22342,222 @@ Navigation2.Link = Link$3;
|
|
22216
22342
|
Navigation2.Section = Section;
|
22217
22343
|
Navigation2.Content = Content$a;
|
22218
22344
|
|
22345
|
+
const DATASET_SIZE_MULTIPLIER = 15;
|
22346
|
+
function useTableDataLoader2(fetchPage, fetchAll, options = {
|
22347
|
+
pageSize: DEFAULT_PAGE_SIZE
|
22348
|
+
}) {
|
22349
|
+
const loadPage = function (pageIndex, sorting, filters, hiddenColumns, search, reset = false) {
|
22350
|
+
try {
|
22351
|
+
// if a request is already pending for this page (and it's not a reset), skip it
|
22352
|
+
if (_pendingPageRequests.current[pageIndex] && !reset) {
|
22353
|
+
return Promise.resolve();
|
22354
|
+
}
|
22355
|
+
const hasChangedData = JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current) || search !== _lastUsedSearch.current;
|
22356
|
+
// if the page is already loaded and has actual rows, abort
|
22357
|
+
if (data.cache[pageIndex] && data.cache[pageIndex][0] && !hasChangedData && !reset) {
|
22358
|
+
return Promise.resolve();
|
22359
|
+
}
|
22360
|
+
// create an id to track the update
|
22361
|
+
const requestId = uuid.v4();
|
22362
|
+
// set the page as loading, so that subsequent requests don't retrigger it
|
22363
|
+
_pendingPageRequests.current[pageIndex] = true;
|
22364
|
+
const _temp2 = _catch(function () {
|
22365
|
+
_lastRequestId.current = requestId;
|
22366
|
+
return Promise.resolve(fetchPage(pageIndex, pageSize, sorting, filters, hiddenColumns, search)).then(function (response) {
|
22367
|
+
length.current = response.length;
|
22368
|
+
// update state, here we do some "magic" to support "load in place"
|
22369
|
+
setData(currentData => {
|
22370
|
+
// if this request wasn't the last one, just return the current state to prevent weird updates
|
22371
|
+
if (_lastRequestId.current !== requestId) {
|
22372
|
+
return currentData;
|
22373
|
+
}
|
22374
|
+
const direction = getDirection(pageIndex, currentData.pages);
|
22375
|
+
const nextPages = getPages(pageIndex, currentData.lastFetchedPage, reset ? [] : currentData.pages, direction);
|
22376
|
+
// set values so we can track if they changed between loads
|
22377
|
+
_lastUsedSorting.current = sorting;
|
22378
|
+
_lastUsedFilters.current = filters;
|
22379
|
+
_lastUsedSearch.current = search;
|
22380
|
+
_lastUsedHiddenColumns.current = hiddenColumns;
|
22381
|
+
// cache data as an object to prevent any duplicates for pages
|
22382
|
+
let nextCache;
|
22383
|
+
if (reset || hasChangedData || !direction) {
|
22384
|
+
nextCache = nextPages.reduce((acc, p) => ({
|
22385
|
+
...acc,
|
22386
|
+
[p]: Array(pageSize).fill(undefined)
|
22387
|
+
}), {});
|
22388
|
+
} else {
|
22389
|
+
nextCache = {
|
22390
|
+
...currentData.cache
|
22391
|
+
};
|
22392
|
+
}
|
22393
|
+
nextCache[pageIndex] = response.data;
|
22394
|
+
// cleanup "unloaded" pages
|
22395
|
+
if (direction === 'forward' && currentData.rows.length >= DATASET_SIZE) {
|
22396
|
+
delete nextCache[currentData.pages[0]];
|
22397
|
+
} else if (direction === 'backward' && currentData.rows.length >= DATASET_SIZE) {
|
22398
|
+
delete nextCache[currentData.pages[currentData.pages.length - 1]];
|
22399
|
+
}
|
22400
|
+
// remap rows from the cached data - do it here and not in render to save some performance
|
22401
|
+
const rows = Object.values(nextCache).reduce((acc, p) => acc.concat(p), []);
|
22402
|
+
return {
|
22403
|
+
cache: nextCache,
|
22404
|
+
pages: nextPages,
|
22405
|
+
rows: rows,
|
22406
|
+
lastFetchedPage: pageIndex
|
22407
|
+
};
|
22408
|
+
});
|
22409
|
+
// reset pending requests
|
22410
|
+
delete _pendingPageRequests.current[pageIndex];
|
22411
|
+
});
|
22412
|
+
}, function () {});
|
22413
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
|
22414
|
+
} catch (e) {
|
22415
|
+
return Promise.reject(e);
|
22416
|
+
}
|
22417
|
+
};
|
22418
|
+
const {
|
22419
|
+
pageSize
|
22420
|
+
} = options;
|
22421
|
+
const DATASET_SIZE = DATASET_SIZE_MULTIPLIER * pageSize;
|
22422
|
+
// track the data length, we don't know it until the first request
|
22423
|
+
const length = React__default.useRef(0);
|
22424
|
+
// data will be filled after the first request
|
22425
|
+
const [data, setData] = React__default.useState({
|
22426
|
+
rows: [],
|
22427
|
+
pages: [],
|
22428
|
+
cache: {},
|
22429
|
+
lastFetchedPage: undefined
|
22430
|
+
});
|
22431
|
+
// track which pages have been loaded to dedupe requests
|
22432
|
+
const _pendingPageRequests = React__default.useRef({});
|
22433
|
+
// it's possible to spam updates, e.g. sort, so we don't set state if the last request wasn't the current oen
|
22434
|
+
const _lastRequestId = React__default.useRef();
|
22435
|
+
// store last used properties
|
22436
|
+
const _lastUsedSorting = React__default.useRef([]);
|
22437
|
+
const _lastUsedFilters = React__default.useRef([]);
|
22438
|
+
const _lastUsedSearch = React__default.useRef();
|
22439
|
+
const _lastUsedHiddenColumns = React__default.useRef([]);
|
22440
|
+
const loadAll = function (sorting, filters, hiddenColumns, search) {
|
22441
|
+
try {
|
22442
|
+
// set values so we can track if they changed between loads
|
22443
|
+
_lastUsedSorting.current = sorting;
|
22444
|
+
_lastUsedFilters.current = filters;
|
22445
|
+
_lastUsedSearch.current = search;
|
22446
|
+
_lastUsedHiddenColumns.current = hiddenColumns;
|
22447
|
+
const _temp = _finallyRethrows(function () {
|
22448
|
+
return _catch(function () {
|
22449
|
+
return Promise.resolve(fetchAll(sorting, filters, hiddenColumns, search)).then(function (response) {
|
22450
|
+
length.current = response.length;
|
22451
|
+
const pages = [];
|
22452
|
+
const cache = {};
|
22453
|
+
Array.from(Array(response.length / pageSize).keys()).forEach(index => {
|
22454
|
+
pages.push(index);
|
22455
|
+
const startIndex = index * pageSize;
|
22456
|
+
cache[index] = response.data.slice(startIndex, startIndex + pageSize);
|
22457
|
+
});
|
22458
|
+
setData({
|
22459
|
+
cache,
|
22460
|
+
pages,
|
22461
|
+
rows: response.data,
|
22462
|
+
lastFetchedPage: undefined
|
22463
|
+
});
|
22464
|
+
});
|
22465
|
+
}, function () {});
|
22466
|
+
}, function (_wasThrown, _result) {
|
22467
|
+
// reset pending requests
|
22468
|
+
_pendingPageRequests.current = {};
|
22469
|
+
if (_wasThrown) throw _result;
|
22470
|
+
return _result;
|
22471
|
+
});
|
22472
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
22473
|
+
} catch (e) {
|
22474
|
+
return Promise.reject(e);
|
22475
|
+
}
|
22476
|
+
};
|
22477
|
+
const invalidate = function () {
|
22478
|
+
try {
|
22479
|
+
// reset stuff
|
22480
|
+
_pendingPageRequests.current = {};
|
22481
|
+
// load the current page again
|
22482
|
+
return loadPage(getCurrentPage(data.pages), _lastUsedSorting.current, _lastUsedFilters.current, _lastUsedHiddenColumns.current, _lastUsedSearch.current, true);
|
22483
|
+
} catch (e) {
|
22484
|
+
return Promise.reject(e);
|
22485
|
+
}
|
22486
|
+
};
|
22487
|
+
const handleSort = function (sorting) {
|
22488
|
+
try {
|
22489
|
+
// reset before loading the current page
|
22490
|
+
_pendingPageRequests.current = {};
|
22491
|
+
return loadPage(getCurrentPage(data.pages), sorting, _lastUsedFilters.current, _lastUsedHiddenColumns.current, _lastUsedSearch.current, true);
|
22492
|
+
} catch (e) {
|
22493
|
+
return Promise.reject(e);
|
22494
|
+
}
|
22495
|
+
};
|
22496
|
+
const handleFilter = function (filters, hiddenColumns) {
|
22497
|
+
try {
|
22498
|
+
// reset before loading the current page
|
22499
|
+
_pendingPageRequests.current = {};
|
22500
|
+
return loadPage(0, _lastUsedSorting.current, filters, hiddenColumns, _lastUsedSearch.current, true);
|
22501
|
+
} catch (e) {
|
22502
|
+
return Promise.reject(e);
|
22503
|
+
}
|
22504
|
+
};
|
22505
|
+
const handleSearch = function (search, hiddenColumns) {
|
22506
|
+
try {
|
22507
|
+
// reset before loading the current page
|
22508
|
+
_pendingPageRequests.current = {};
|
22509
|
+
return loadPage(0, _lastUsedSorting.current, _lastUsedFilters.current, hiddenColumns, search, true);
|
22510
|
+
} catch (e) {
|
22511
|
+
return Promise.reject(e);
|
22512
|
+
}
|
22513
|
+
};
|
22514
|
+
return [{
|
22515
|
+
data: data.rows,
|
22516
|
+
pages: data.pages,
|
22517
|
+
length: length.current,
|
22518
|
+
loadAll,
|
22519
|
+
loadPage,
|
22520
|
+
onChangeFilter: handleFilter,
|
22521
|
+
onChangeSearch: handleSearch,
|
22522
|
+
onChangeSort: handleSort,
|
22523
|
+
pageSize,
|
22524
|
+
_experimentalDataLoader2: true
|
22525
|
+
}, invalidate];
|
22526
|
+
}
|
22527
|
+
function getCurrentPage(currentPages) {
|
22528
|
+
if (currentPages.length <= 2) {
|
22529
|
+
return currentPages[0];
|
22530
|
+
}
|
22531
|
+
// for even page lengths we can't know which is the current visible page - it could even be both
|
22532
|
+
// so we load one of them and rely on the "load next/previous page" functionality in row
|
22533
|
+
const middle = Math.floor(currentPages.length / 2);
|
22534
|
+
return currentPages[middle];
|
22535
|
+
}
|
22536
|
+
function getDirection(pageIndex, currentPages) {
|
22537
|
+
if (currentPages.length) {
|
22538
|
+
if (pageIndex === currentPages[currentPages.length - 1] + 1) {
|
22539
|
+
return 'forward';
|
22540
|
+
} else if (pageIndex === currentPages[0] - 1 || currentPages.length === 2 && currentPages[0] !== 0 && pageIndex === currentPages[0]) {
|
22541
|
+
return 'backward';
|
22542
|
+
}
|
22543
|
+
}
|
22544
|
+
return undefined;
|
22545
|
+
}
|
22546
|
+
function getPages(pageIndex, lastUsedPageIndex, currentPages, direction) {
|
22547
|
+
if (currentPages.length && (pageIndex === lastUsedPageIndex || currentPages.includes(pageIndex))) {
|
22548
|
+
return currentPages;
|
22549
|
+
}
|
22550
|
+
if (direction === 'forward') {
|
22551
|
+
const nextPages = currentPages.length === DATASET_SIZE_MULTIPLIER ? currentPages.slice(1) : currentPages;
|
22552
|
+
return nextPages.concat(pageIndex);
|
22553
|
+
}
|
22554
|
+
if (direction === 'backward') {
|
22555
|
+
const nextPages = currentPages.length === DATASET_SIZE_MULTIPLIER ? currentPages.slice(0, -1) : currentPages;
|
22556
|
+
return [pageIndex].concat(nextPages);
|
22557
|
+
}
|
22558
|
+
return [pageIndex];
|
22559
|
+
}
|
22560
|
+
|
22219
22561
|
const useBoundaryOverflowDetection = (ref, dependencies = []) => {
|
22220
22562
|
const [boundaryIndex, setBoundaryIndex] = React__default.useState();
|
22221
22563
|
const dimensions = useBoundingClientRectListener(ref, dependencies);
|
@@ -22355,6 +22697,7 @@ exports.useOnClickOutside = useOnClickOutside;
|
|
22355
22697
|
exports.usePagination = usePagination;
|
22356
22698
|
exports.useRadioGroup = useRadioGroup;
|
22357
22699
|
exports.useTableDataLoader = useTableDataLoader;
|
22700
|
+
exports.useTableDataLoader2 = useTableDataLoader2;
|
22358
22701
|
exports.useTableRowCreation = useTableRowCreation;
|
22359
22702
|
exports.useToast = useToast;
|
22360
22703
|
//# sourceMappingURL=taco.cjs.development.js.map
|