@redsift/table-pro 12.6.1 → 12.6.3
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
|
@@ -750,16 +750,40 @@ const clearAllVersionStorage = (id, maxVersion) => {
|
|
|
750
750
|
clearPreviousVersionStorage(id, versions);
|
|
751
751
|
};
|
|
752
752
|
|
|
753
|
+
/** Options for `resetStatefulDataGridState` and `resetColumnVisibility`. */
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* The query string a reset strips: `getSearch()` when given, otherwise the
|
|
757
|
+
* browser's live URL, otherwise the `search` fallback.
|
|
758
|
+
*/
|
|
759
|
+
const readLiveSearch = _ref2 => {
|
|
760
|
+
let {
|
|
761
|
+
search,
|
|
762
|
+
getSearch
|
|
763
|
+
} = _ref2;
|
|
764
|
+
if (getSearch) {
|
|
765
|
+
return getSearch();
|
|
766
|
+
}
|
|
767
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
768
|
+
return window.location.search;
|
|
769
|
+
}
|
|
770
|
+
return search !== null && search !== void 0 ? search : '';
|
|
771
|
+
};
|
|
772
|
+
|
|
753
773
|
/**
|
|
754
774
|
* Fully reset a `StatefulDataGrid` — clear localStorage for the given versions
|
|
755
775
|
* and strip all grid-owned URL params (`_*` and `v=`), preserving any non-grid params.
|
|
756
776
|
*
|
|
757
|
-
* The
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
* is only used in non-browser environments (SSR, unit tests without
|
|
777
|
+
* The strip always operates on the live URL, because consumers typically call
|
|
778
|
+
* this from a component whose captured `search` snapshot may be stale — for
|
|
779
|
+
* example when the grid has just written its own keys to the URL via the
|
|
780
|
+
* router adapter but the parent hasn't re-rendered yet. The live URL is
|
|
781
|
+
* `getSearch()` when given, otherwise `window.location.search`. The supplied
|
|
782
|
+
* `search` is only used in non-browser environments (SSR, unit tests without
|
|
783
|
+
* jsdom).
|
|
784
|
+
*
|
|
785
|
+
* Under a browser router `window.location` is the router's URL. Under a memory
|
|
786
|
+
* history it is not, so pass `getSearch` (see `StatefulDataGridResetOptions`).
|
|
763
787
|
*
|
|
764
788
|
* The write is performed via `historyReplace(newSearch, { authoritative: true })`.
|
|
765
789
|
* Adapters with delta/coalescing logic (e.g. `createReactRouterV5Adapter`)
|
|
@@ -772,17 +796,26 @@ const clearAllVersionStorage = (id, maxVersion) => {
|
|
|
772
796
|
* const { search, historyReplace } = useMyRouter();
|
|
773
797
|
* resetStatefulDataGridState({ id: 'myGrid', versions: [0, 1, 2], search, historyReplace });
|
|
774
798
|
* ```
|
|
799
|
+
*
|
|
800
|
+
* Under a memory history, with `createReactRouterV5Adapter`:
|
|
801
|
+
* ```ts
|
|
802
|
+
* const { pathname, getSearch, historyReplace } = useRouter();
|
|
803
|
+
* resetStatefulDataGridState({ id: pathname, versions: [0, 1], getSearch, historyReplace });
|
|
804
|
+
* ```
|
|
775
805
|
*/
|
|
776
|
-
const resetStatefulDataGridState =
|
|
806
|
+
const resetStatefulDataGridState = _ref3 => {
|
|
777
807
|
let {
|
|
778
808
|
id,
|
|
779
809
|
versions,
|
|
780
810
|
search,
|
|
811
|
+
getSearch,
|
|
781
812
|
historyReplace
|
|
782
|
-
} =
|
|
813
|
+
} = _ref3;
|
|
783
814
|
clearPreviousVersionStorage(id, versions);
|
|
784
|
-
const
|
|
785
|
-
|
|
815
|
+
const params = new URLSearchParams(readLiveSearch({
|
|
816
|
+
search,
|
|
817
|
+
getSearch
|
|
818
|
+
}));
|
|
786
819
|
const keysToDelete = [];
|
|
787
820
|
params.forEach((_value, key) => {
|
|
788
821
|
if (key.startsWith('_') || key === 'v') {
|
|
@@ -810,9 +843,10 @@ const resetStatefulDataGridState = _ref2 => {
|
|
|
810
843
|
* params alone it will not clobber a filter the caller is writing in the same
|
|
811
844
|
* transition.
|
|
812
845
|
*
|
|
813
|
-
* Like `resetStatefulDataGridState`, the URL strip
|
|
814
|
-
*
|
|
815
|
-
*
|
|
846
|
+
* Like `resetStatefulDataGridState`, the URL strip operates on the live URL
|
|
847
|
+
* (the caller's captured snapshot may be stale): `getSearch()` when given,
|
|
848
|
+
* otherwise `window.location.search`. Pass `getSearch` under a memory history.
|
|
849
|
+
* It writes via `historyReplace(newSearch, { authoritative: true })`.
|
|
816
850
|
*
|
|
817
851
|
* This clears the *persisted* state only. The caller is responsible for
|
|
818
852
|
* resetting the *live* grid in the same tick:
|
|
@@ -821,13 +855,14 @@ const resetStatefulDataGridState = _ref2 => {
|
|
|
821
855
|
* apiRef.current?.setColumnVisibilityModel?.({});
|
|
822
856
|
* ```
|
|
823
857
|
*/
|
|
824
|
-
const resetColumnVisibility =
|
|
858
|
+
const resetColumnVisibility = _ref4 => {
|
|
825
859
|
let {
|
|
826
860
|
id,
|
|
827
861
|
versions,
|
|
828
862
|
search,
|
|
863
|
+
getSearch,
|
|
829
864
|
historyReplace
|
|
830
|
-
} =
|
|
865
|
+
} = _ref4;
|
|
831
866
|
for (const version of versions) {
|
|
832
867
|
try {
|
|
833
868
|
window.localStorage.removeItem(buildStorageKey({
|
|
@@ -839,8 +874,10 @@ const resetColumnVisibility = _ref3 => {
|
|
|
839
874
|
// Ignore — storage may be unavailable (SSR, Safari private mode).
|
|
840
875
|
}
|
|
841
876
|
}
|
|
842
|
-
const
|
|
843
|
-
|
|
877
|
+
const params = new URLSearchParams(readLiveSearch({
|
|
878
|
+
search,
|
|
879
|
+
getSearch
|
|
880
|
+
}));
|
|
844
881
|
params.delete('_columnVisibility');
|
|
845
882
|
historyReplace(params.toString(), {
|
|
846
883
|
authoritative: true
|
|
@@ -2914,16 +2951,25 @@ const COMPONENT_NAME = 'DataGrid';
|
|
|
2914
2951
|
const CLASSNAME = 'redsift-datagrid';
|
|
2915
2952
|
|
|
2916
2953
|
/**
|
|
2917
|
-
* StatefulDataGrid extends DataGrid with automatic state persistence to localStorage.
|
|
2918
|
-
*
|
|
2919
|
-
*
|
|
2954
|
+
* StatefulDataGrid extends DataGrid with automatic state persistence to the URL and localStorage.
|
|
2955
|
+
* Filters, sorting, pagination, column visibility, column order, pinned
|
|
2956
|
+
* columns and density are written to the URL query string and to localStorage;
|
|
2957
|
+
* column widths are kept in localStorage only. On load the URL wins, then
|
|
2958
|
+
* localStorage, then `initialState`, so state survives page refreshes and a
|
|
2959
|
+
* copied URL reopens the same view.
|
|
2920
2960
|
*
|
|
2921
|
-
* Use when users need persistent table preferences
|
|
2961
|
+
* Use when users need persistent table preferences or shareable filtered views.
|
|
2962
|
+
* Requires a `useRouter` hook returning `{ pathname, search, historyReplace }`
|
|
2963
|
+
* (`createReactRouterV5Adapter` builds one from a React Router v5 `history`).
|
|
2964
|
+
* State is stored in localStorage under the `pathname` it returns, and
|
|
2965
|
+
* versioned by `localStorageVersion` (a number, default `1`).
|
|
2922
2966
|
*
|
|
2923
2967
|
* @example
|
|
2924
|
-
* // Basic stateful grid (
|
|
2968
|
+
* // Basic stateful grid (URL + localStorage)
|
|
2969
|
+
* const useRouter = createReactRouterV5Adapter(history);
|
|
2970
|
+
*
|
|
2925
2971
|
* <StatefulDataGrid
|
|
2926
|
-
*
|
|
2972
|
+
* useRouter={useRouter}
|
|
2927
2973
|
* columns={columns}
|
|
2928
2974
|
* rows={users}
|
|
2929
2975
|
* pagination
|
|
@@ -2932,34 +2978,24 @@ const CLASSNAME = 'redsift-datagrid';
|
|
|
2932
2978
|
* @example
|
|
2933
2979
|
* // With version migration (clears old preferences)
|
|
2934
2980
|
* <StatefulDataGrid
|
|
2935
|
-
*
|
|
2936
|
-
* localStorageVersion=
|
|
2937
|
-
* previousLocalStorageVersions={[
|
|
2981
|
+
* useRouter={useRouter}
|
|
2982
|
+
* localStorageVersion={2}
|
|
2983
|
+
* previousLocalStorageVersions={[1]}
|
|
2938
2984
|
* columns={columns}
|
|
2939
2985
|
* rows={reports}
|
|
2940
2986
|
* />
|
|
2941
2987
|
*
|
|
2942
2988
|
* @example
|
|
2943
|
-
* // With URL state sync (shareable filtered views)
|
|
2944
|
-
* <StatefulDataGrid
|
|
2945
|
-
* localStorageKey="domains-table"
|
|
2946
|
-
* useRouter={true}
|
|
2947
|
-
* columns={columns}
|
|
2948
|
-
* rows={domains}
|
|
2949
|
-
* pagination
|
|
2950
|
-
* />
|
|
2951
|
-
*
|
|
2952
|
-
* @example
|
|
2953
2989
|
* // All features combined
|
|
2954
2990
|
* <StatefulDataGrid
|
|
2955
|
-
*
|
|
2956
|
-
* localStorageVersion=
|
|
2957
|
-
* previousLocalStorageVersions={[
|
|
2958
|
-
* useRouter={true}
|
|
2991
|
+
* useRouter={useRouter}
|
|
2992
|
+
* localStorageVersion={3}
|
|
2993
|
+
* previousLocalStorageVersions={[1, 2]}
|
|
2959
2994
|
* columns={columns}
|
|
2960
2995
|
* rows={logs}
|
|
2961
2996
|
* pagination
|
|
2962
|
-
*
|
|
2997
|
+
* pageSizeOptions={[25, 50, 100]}
|
|
2998
|
+
* initialState={{ pagination: { paginationModel: { page: 0, pageSize: 50 } } }}
|
|
2963
2999
|
* checkboxSelection
|
|
2964
3000
|
* />
|
|
2965
3001
|
*/
|