@redsift/table 12.6.1 → 12.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_internal/StatefulDataGrid2.js +77 -41
- package/_internal/StatefulDataGrid2.js.map +1 -1
- package/index.d.ts +93 -60
- package/index.js +18 -1
- package/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -804,16 +804,40 @@ const clearAllVersionStorage = (id, maxVersion) => {
|
|
|
804
804
|
clearPreviousVersionStorage(id, versions);
|
|
805
805
|
};
|
|
806
806
|
|
|
807
|
+
/** Options for `resetStatefulDataGridState` and `resetColumnVisibility`. */
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* The query string a reset strips: `getSearch()` when given, otherwise the
|
|
811
|
+
* browser's live URL, otherwise the `search` fallback.
|
|
812
|
+
*/
|
|
813
|
+
const readLiveSearch = _ref2 => {
|
|
814
|
+
let {
|
|
815
|
+
search,
|
|
816
|
+
getSearch
|
|
817
|
+
} = _ref2;
|
|
818
|
+
if (getSearch) {
|
|
819
|
+
return getSearch();
|
|
820
|
+
}
|
|
821
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
822
|
+
return window.location.search;
|
|
823
|
+
}
|
|
824
|
+
return search !== null && search !== void 0 ? search : '';
|
|
825
|
+
};
|
|
826
|
+
|
|
807
827
|
/**
|
|
808
828
|
* Fully reset a `StatefulDataGrid` — clear localStorage for the given versions
|
|
809
829
|
* and strip all grid-owned URL params (`_*` and `v=`), preserving any non-grid params.
|
|
810
830
|
*
|
|
811
|
-
* The
|
|
812
|
-
*
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
* is only used in non-browser environments (SSR, unit tests without
|
|
831
|
+
* The strip always operates on the live URL, because consumers typically call
|
|
832
|
+
* this from a component whose captured `search` snapshot may be stale — for
|
|
833
|
+
* example when the grid has just written its own keys to the URL via the
|
|
834
|
+
* router adapter but the parent hasn't re-rendered yet. The live URL is
|
|
835
|
+
* `getSearch()` when given, otherwise `window.location.search`. The supplied
|
|
836
|
+
* `search` is only used in non-browser environments (SSR, unit tests without
|
|
837
|
+
* jsdom).
|
|
838
|
+
*
|
|
839
|
+
* Under a browser router `window.location` is the router's URL. Under a memory
|
|
840
|
+
* history it is not, so pass `getSearch` (see `StatefulDataGridResetOptions`).
|
|
817
841
|
*
|
|
818
842
|
* The write is performed via `historyReplace(newSearch, { authoritative: true })`.
|
|
819
843
|
* Adapters with delta/coalescing logic (e.g. `createReactRouterV5Adapter`)
|
|
@@ -826,17 +850,26 @@ const clearAllVersionStorage = (id, maxVersion) => {
|
|
|
826
850
|
* const { search, historyReplace } = useMyRouter();
|
|
827
851
|
* resetStatefulDataGridState({ id: 'myGrid', versions: [0, 1, 2], search, historyReplace });
|
|
828
852
|
* ```
|
|
853
|
+
*
|
|
854
|
+
* Under a memory history, with `createReactRouterV5Adapter`:
|
|
855
|
+
* ```ts
|
|
856
|
+
* const { pathname, getSearch, historyReplace } = useRouter();
|
|
857
|
+
* resetStatefulDataGridState({ id: pathname, versions: [0, 1], getSearch, historyReplace });
|
|
858
|
+
* ```
|
|
829
859
|
*/
|
|
830
|
-
const resetStatefulDataGridState =
|
|
860
|
+
const resetStatefulDataGridState = _ref3 => {
|
|
831
861
|
let {
|
|
832
862
|
id,
|
|
833
863
|
versions,
|
|
834
864
|
search,
|
|
865
|
+
getSearch,
|
|
835
866
|
historyReplace
|
|
836
|
-
} =
|
|
867
|
+
} = _ref3;
|
|
837
868
|
clearPreviousVersionStorage(id, versions);
|
|
838
|
-
const
|
|
839
|
-
|
|
869
|
+
const params = new URLSearchParams(readLiveSearch({
|
|
870
|
+
search,
|
|
871
|
+
getSearch
|
|
872
|
+
}));
|
|
840
873
|
const keysToDelete = [];
|
|
841
874
|
params.forEach((_value, key) => {
|
|
842
875
|
if (key.startsWith('_') || key === 'v') {
|
|
@@ -865,9 +898,10 @@ const resetStatefulDataGridState = _ref2 => {
|
|
|
865
898
|
* other params alone it will not clobber a filter the caller is writing in the
|
|
866
899
|
* same transition.
|
|
867
900
|
*
|
|
868
|
-
* Like `resetStatefulDataGridState`, the URL strip
|
|
869
|
-
*
|
|
870
|
-
*
|
|
901
|
+
* Like `resetStatefulDataGridState`, the URL strip operates on the live URL
|
|
902
|
+
* (the caller's captured snapshot may be stale): `getSearch()` when given,
|
|
903
|
+
* otherwise `window.location.search`. Pass `getSearch` under a memory history.
|
|
904
|
+
* It writes via `historyReplace(newSearch, { authoritative: true })`.
|
|
871
905
|
*
|
|
872
906
|
* This clears the *persisted* state only. The caller is responsible for
|
|
873
907
|
* resetting the *live* grid in the same tick:
|
|
@@ -876,13 +910,14 @@ const resetStatefulDataGridState = _ref2 => {
|
|
|
876
910
|
* apiRef.current?.setColumnVisibilityModel?.({});
|
|
877
911
|
* ```
|
|
878
912
|
*/
|
|
879
|
-
const resetColumnVisibility =
|
|
913
|
+
const resetColumnVisibility = _ref4 => {
|
|
880
914
|
let {
|
|
881
915
|
id,
|
|
882
916
|
versions,
|
|
883
917
|
search,
|
|
918
|
+
getSearch,
|
|
884
919
|
historyReplace
|
|
885
|
-
} =
|
|
920
|
+
} = _ref4;
|
|
886
921
|
for (const version of versions) {
|
|
887
922
|
try {
|
|
888
923
|
window.localStorage.removeItem(buildStorageKey({
|
|
@@ -894,8 +929,10 @@ const resetColumnVisibility = _ref3 => {
|
|
|
894
929
|
// Ignore — storage may be unavailable (SSR, Safari private mode).
|
|
895
930
|
}
|
|
896
931
|
}
|
|
897
|
-
const
|
|
898
|
-
|
|
932
|
+
const params = new URLSearchParams(readLiveSearch({
|
|
933
|
+
search,
|
|
934
|
+
getSearch
|
|
935
|
+
}));
|
|
899
936
|
params.delete('_columnVisibility');
|
|
900
937
|
historyReplace(params.toString(), {
|
|
901
938
|
authoritative: true
|
|
@@ -3427,16 +3464,25 @@ const COMPONENT_NAME = 'DataGrid';
|
|
|
3427
3464
|
const CLASSNAME = 'redsift-datagrid';
|
|
3428
3465
|
|
|
3429
3466
|
/**
|
|
3430
|
-
* StatefulDataGrid extends DataGrid with automatic state persistence to localStorage.
|
|
3431
|
-
*
|
|
3432
|
-
*
|
|
3467
|
+
* StatefulDataGrid extends DataGrid with automatic state persistence to the URL and localStorage.
|
|
3468
|
+
* Filters, sorting, pagination, column visibility, column order, pinned
|
|
3469
|
+
* columns, density, row grouping, aggregation and pivot are written to the URL
|
|
3470
|
+
* query string and to localStorage; column widths are kept in localStorage
|
|
3471
|
+
* only. On load the URL wins, then localStorage, then `initialState`, so state
|
|
3472
|
+
* survives page refreshes and a copied URL reopens the same view.
|
|
3433
3473
|
*
|
|
3434
|
-
* Use when users need persistent table preferences
|
|
3474
|
+
* Use when users need persistent table preferences or shareable filtered views.
|
|
3475
|
+
* Requires a `useRouter` hook returning `{ pathname, search, historyReplace }`
|
|
3476
|
+
* (`createReactRouterV5Adapter` builds one from a React Router v5 `history`).
|
|
3477
|
+
* State is stored in localStorage under the `pathname` it returns, and
|
|
3478
|
+
* versioned by `localStorageVersion` (a number, default `1`).
|
|
3435
3479
|
*
|
|
3436
3480
|
* @example
|
|
3437
|
-
* // Basic stateful grid (
|
|
3481
|
+
* // Basic stateful grid (URL + localStorage)
|
|
3482
|
+
* const useRouter = createReactRouterV5Adapter(history);
|
|
3483
|
+
*
|
|
3438
3484
|
* <StatefulDataGrid
|
|
3439
|
-
*
|
|
3485
|
+
* useRouter={useRouter}
|
|
3440
3486
|
* columns={columns}
|
|
3441
3487
|
* rows={users}
|
|
3442
3488
|
* pagination
|
|
@@ -3445,34 +3491,24 @@ const CLASSNAME = 'redsift-datagrid';
|
|
|
3445
3491
|
* @example
|
|
3446
3492
|
* // With version migration (clears old preferences)
|
|
3447
3493
|
* <StatefulDataGrid
|
|
3448
|
-
*
|
|
3449
|
-
* localStorageVersion=
|
|
3450
|
-
* previousLocalStorageVersions={[
|
|
3494
|
+
* useRouter={useRouter}
|
|
3495
|
+
* localStorageVersion={2}
|
|
3496
|
+
* previousLocalStorageVersions={[1]}
|
|
3451
3497
|
* columns={columns}
|
|
3452
3498
|
* rows={reports}
|
|
3453
3499
|
* />
|
|
3454
3500
|
*
|
|
3455
3501
|
* @example
|
|
3456
|
-
* // With URL state sync (shareable filtered views)
|
|
3457
|
-
* <StatefulDataGrid
|
|
3458
|
-
* localStorageKey="domains-table"
|
|
3459
|
-
* useRouter={true}
|
|
3460
|
-
* columns={columns}
|
|
3461
|
-
* rows={domains}
|
|
3462
|
-
* pagination
|
|
3463
|
-
* />
|
|
3464
|
-
*
|
|
3465
|
-
* @example
|
|
3466
3502
|
* // All features combined
|
|
3467
3503
|
* <StatefulDataGrid
|
|
3468
|
-
*
|
|
3469
|
-
* localStorageVersion=
|
|
3470
|
-
* previousLocalStorageVersions={[
|
|
3471
|
-
* useRouter={true}
|
|
3504
|
+
* useRouter={useRouter}
|
|
3505
|
+
* localStorageVersion={3}
|
|
3506
|
+
* previousLocalStorageVersions={[1, 2]}
|
|
3472
3507
|
* columns={columns}
|
|
3473
3508
|
* rows={logs}
|
|
3474
3509
|
* pagination
|
|
3475
|
-
*
|
|
3510
|
+
* pageSizeOptions={[25, 50, 100]}
|
|
3511
|
+
* initialState={{ pagination: { paginationModel: { page: 0, pageSize: 50 } } }}
|
|
3476
3512
|
* checkboxSelection
|
|
3477
3513
|
* />
|
|
3478
3514
|
*/
|