1 |
|
2 |
|
3 |
|
4 |
|
5 | type UseTablePaginationProps = {
|
6 | params?: {
|
7 | page?: string;
|
8 | perPage?: string;
|
9 | };
|
10 | |
11 |
|
12 |
|
13 | startPage?: number;
|
14 | |
15 |
|
16 |
|
17 | perPage?: number;
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | perPageOptions?: number[];
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | from?: (total: number, page: number, size: number, df: number) => number;
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | to?: (total: number, page: number, size: number, df: number) => number;
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | lastPage?: (total: number, size: number) => number;
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | disableFirst?: (total: number, page: number, df: number) => boolean;
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | disableLast?: (total: number, page: number, lp: number) => boolean;
|
83 | };
|
84 |
|
85 | type UseTablePagination = {
|
86 | total: number;
|
87 | page: number;
|
88 | from: number;
|
89 | to: number;
|
90 | lastPage: number;
|
91 | perPageOptions: number[];
|
92 | perPage: number;
|
93 | text: string;
|
94 | setPage: (value: number) => void;
|
95 | setPerPage: (value: number) => void;
|
96 | nextButton: () => React.DetailedHTMLProps<
|
97 | React.ButtonHTMLAttributes<HTMLButtonElement>,
|
98 | HTMLButtonElement
|
99 | >;
|
100 | backButton: () => React.DetailedHTMLProps<
|
101 | React.ButtonHTMLAttributes<HTMLButtonElement>,
|
102 | HTMLButtonElement
|
103 | >;
|
104 | firstButton: () => React.DetailedHTMLProps<
|
105 | React.ButtonHTMLAttributes<HTMLButtonElement>,
|
106 | HTMLButtonElement
|
107 | >;
|
108 | lastButton: () => React.DetailedHTMLProps<
|
109 | React.ButtonHTMLAttributes<HTMLButtonElement>,
|
110 | HTMLButtonElement
|
111 | >;
|
112 | onPerPageChange: (
|
113 | event?: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
114 | ) => void;
|
115 | };
|
116 |
|
117 | interface UseTableProps<T = any> {
|
118 | service: (event?: import(".").EventSend<T>) => T;
|
119 | selector: (resp: any) => any;
|
120 | total?: (resp: any) => number;
|
121 | replaceUrl?: boolean;
|
122 | cache?: {
|
123 | key?: string;
|
124 | |
125 |
|
126 |
|
127 |
|
128 | ttl?: number;
|
129 | |
130 |
|
131 |
|
132 |
|
133 | periodTime?: number;
|
134 | periodically?: boolean;
|
135 | };
|
136 | disabledOnDidMount?: boolean;
|
137 | sort?: {
|
138 | params?: {
|
139 | order?: string;
|
140 | orderBy?: string;
|
141 | };
|
142 | order?: "desc" | "asc";
|
143 | orderBy?: string;
|
144 | };
|
145 | deps?: any[];
|
146 | pagination?: UseTablePaginationProps;
|
147 | }
|
148 |
|
149 | type UseTable<T> = {
|
150 | isEmpty: boolean;
|
151 | loading: boolean;
|
152 | total: number;
|
153 | data: T[];
|
154 | order: "desc" | "asc";
|
155 | orderBy: string;
|
156 | query: (key?: string, defaultValue?: any) => any;
|
157 | setTotal: (value: number) => void;
|
158 | setQuery: (
|
159 | value:
|
160 | | Record<string, any>
|
161 | | ((value: Record<string, any>) => Record<string, any>)
|
162 | ) => void;
|
163 | onSort: (value: string) => void;
|
164 | reload: () => void;
|
165 | clear: (value?: { except?: string[]; only?: [string] }) => void;
|
166 | remove: (key: string, resetPage?: boolean) => void;
|
167 | add: (newValue: T, position?: "start" | "end" | number) => void;
|
168 | update: (condition: (data: T) => boolean, newValue: Partial<T>) => void;
|
169 | destroy: (condition: (data: T) => boolean) => void;
|
170 | has: (key: string) => boolean;
|
171 | cancel: () => void;
|
172 | pagination: UseTablePagination;
|
173 | };
|
174 |
|
175 | export default function useTable<T, S = unknown>(
|
176 | props: UseTableProps<S>
|
177 | ): UseTable<T>;
|