listpage-next 0.0.128 → 0.0.129
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.
|
@@ -13,6 +13,11 @@ export interface ListPageProps<FilterValue = any, RecordValue extends Record<str
|
|
|
13
13
|
key: string;
|
|
14
14
|
render: FloatRender<RecordValue>;
|
|
15
15
|
}[];
|
|
16
|
+
state?: {
|
|
17
|
+
filterValues?: FilterValue;
|
|
18
|
+
pageSize?: number;
|
|
19
|
+
currentPage?: number;
|
|
20
|
+
};
|
|
16
21
|
initialValues?: {
|
|
17
22
|
filterValues?: FilterValue;
|
|
18
23
|
pageSize?: number;
|
|
@@ -5,7 +5,16 @@ export type TableRequest<FilterValue = any, RecordValue = any> = (pageParams: Ba
|
|
|
5
5
|
export type FloatRender<RecordValue extends Record<string, any> = any> = (props: FloatComponentProps<RecordValue>) => JSX.Element;
|
|
6
6
|
export type ListPageStorageOption<FilterValue = any, RecordValue extends Record<string, any> = any> = {
|
|
7
7
|
storageKey?: string;
|
|
8
|
-
initialValues
|
|
8
|
+
initialValues?: {
|
|
9
|
+
filterValues?: FilterValue;
|
|
10
|
+
pageSize?: number;
|
|
11
|
+
currentPage?: number;
|
|
12
|
+
};
|
|
13
|
+
state?: {
|
|
14
|
+
currentPage?: number;
|
|
15
|
+
pageSize?: number;
|
|
16
|
+
filterValues?: FilterValue;
|
|
17
|
+
};
|
|
9
18
|
request: TableRequest<FilterValue, RecordValue>;
|
|
10
19
|
floats: {
|
|
11
20
|
key: string;
|
|
@@ -46,8 +55,13 @@ export declare class ListPageStore<FilterValue = any, RecordValue extends Record
|
|
|
46
55
|
clearSelection(): void;
|
|
47
56
|
refreshTable(): void;
|
|
48
57
|
}
|
|
49
|
-
export declare const ListPageProvider: ({ children, initialValues, request, storageKey, floats, }: {
|
|
58
|
+
export declare const ListPageProvider: ({ children, initialValues, state, request, storageKey, floats, }: {
|
|
50
59
|
children: ReactNode;
|
|
60
|
+
state?: {
|
|
61
|
+
filterValues?: any;
|
|
62
|
+
pageSize?: number;
|
|
63
|
+
currentPage?: number;
|
|
64
|
+
};
|
|
51
65
|
initialValues?: {
|
|
52
66
|
filterValues?: any;
|
|
53
67
|
pageSize?: number;
|
|
@@ -12,15 +12,15 @@ class ListPageStore {
|
|
|
12
12
|
pagination;
|
|
13
13
|
selection;
|
|
14
14
|
constructor(options){
|
|
15
|
-
const { initialValues = {}, request, floats = [], storageKey } = options;
|
|
15
|
+
const { initialValues = {}, request, floats = [], storageKey, state } = options;
|
|
16
16
|
const defaultValue = getDefaultValue(storageKey);
|
|
17
17
|
this.storageKey = storageKey;
|
|
18
|
-
this.filters = initialValues.filterValues || {};
|
|
19
18
|
this.floats = floats;
|
|
19
|
+
this.filters = state?.filterValues || defaultValue.filterValues || initialValues.filterValues;
|
|
20
20
|
this.pagination = {
|
|
21
21
|
total: 0,
|
|
22
|
-
current:
|
|
23
|
-
pageSize:
|
|
22
|
+
current: state?.currentPage || defaultValue.currentPage || initialValues.currentPage,
|
|
23
|
+
pageSize: state?.pageSize || defaultValue.pageSize || initialValues.pageSize
|
|
24
24
|
};
|
|
25
25
|
this.selection = {
|
|
26
26
|
selectedRowKeys: [],
|
|
@@ -32,6 +32,10 @@ class ListPageStore {
|
|
|
32
32
|
submitFiltersChange(value = {}) {
|
|
33
33
|
this.filters = value;
|
|
34
34
|
this.pagination.current = 1;
|
|
35
|
+
setDefaultValue(this.storageKey, {
|
|
36
|
+
filterValues: value,
|
|
37
|
+
currentPage: 1
|
|
38
|
+
});
|
|
35
39
|
this.refreshTable();
|
|
36
40
|
}
|
|
37
41
|
showFloat(key, record, onCloseCallback) {
|
|
@@ -86,8 +90,9 @@ class ListPageStore {
|
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
const ListPageContext = /*#__PURE__*/ createContext({});
|
|
89
|
-
const ListPageProvider = ({ children, initialValues, request, storageKey, floats = [] })=>{
|
|
93
|
+
const ListPageProvider = ({ children, initialValues, state, request, storageKey, floats = [] })=>{
|
|
90
94
|
const store = useMemo(()=>new ListPageStore({
|
|
95
|
+
state,
|
|
91
96
|
initialValues,
|
|
92
97
|
request,
|
|
93
98
|
floats,
|
|
@@ -104,13 +109,15 @@ function useListPageStore() {
|
|
|
104
109
|
const getDefaultValue = (STORAGE_KEY)=>{
|
|
105
110
|
if (!STORAGE_KEY) return {
|
|
106
111
|
currentPage: 1,
|
|
107
|
-
pageSize: 10
|
|
112
|
+
pageSize: 10,
|
|
113
|
+
filterValues: void 0
|
|
108
114
|
};
|
|
109
115
|
const storageValue = localStorage.getItem(STORAGE_KEY);
|
|
110
116
|
const value = JSON.parse(storageValue ?? '{}');
|
|
111
117
|
return {
|
|
112
118
|
currentPage: value.currentPage || 1,
|
|
113
|
-
pageSize: value.pageSize || 10
|
|
119
|
+
pageSize: value.pageSize || 10,
|
|
120
|
+
filterValues: value.filterValues || void 0
|
|
114
121
|
};
|
|
115
122
|
};
|
|
116
123
|
const setDefaultValue = (STORAGE_KEY, value)=>{
|