@eml-payments/ui-kit 1.8.7 → 1.8.8
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useImperativeHandle, forwardRef
|
|
2
|
+
import { useEffect, useImperativeHandle, forwardRef } from 'react';
|
|
3
3
|
import { useForm, Controller, useWatch } from 'react-hook-form';
|
|
4
4
|
import { DatePicker } from '../DatePicker';
|
|
5
5
|
import { FilterSelect } from './FilterSelect';
|
|
@@ -13,7 +13,6 @@ export const Filters = forwardRef(({ filters, defaultValues, onChange, onReset,
|
|
|
13
13
|
const { control, reset, setValue, watch } = useForm({
|
|
14
14
|
defaultValues,
|
|
15
15
|
});
|
|
16
|
-
const isInitialisedRef = useRef(false);
|
|
17
16
|
const values = useWatch({ control });
|
|
18
17
|
useImperativeHandle(ref, () => ({
|
|
19
18
|
reset: () => {
|
|
@@ -28,10 +27,6 @@ export const Filters = forwardRef(({ filters, defaultValues, onChange, onReset,
|
|
|
28
27
|
}));
|
|
29
28
|
useEffect(() => {
|
|
30
29
|
const subscription = watch((updatedValues) => {
|
|
31
|
-
if (!isInitialisedRef.current) {
|
|
32
|
-
isInitialisedRef.current = true;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
30
|
onChange === null || onChange === void 0 ? void 0 : onChange(updatedValues);
|
|
36
31
|
});
|
|
37
32
|
return () => subscription.unsubscribe();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { useSearchParams } from 'react-router-dom';
|
|
2
|
+
import { useLocation, useSearchParams } from 'react-router-dom';
|
|
3
3
|
function getPaginationParamKeys(tableId) {
|
|
4
4
|
if (tableId) {
|
|
5
5
|
return {
|
|
@@ -15,9 +15,14 @@ function getPaginationParamKeys(tableId) {
|
|
|
15
15
|
export function useUrlPaginationSync({ defaultPageSize, tableId, scoped = false, enabled = true, }) {
|
|
16
16
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
17
17
|
const searchParamsRef = useRef(searchParams);
|
|
18
|
+
const location = useLocation();
|
|
19
|
+
const locationStateRef = useRef(location.state);
|
|
18
20
|
useEffect(() => {
|
|
19
21
|
searchParamsRef.current = searchParams;
|
|
20
22
|
}, [searchParams]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
locationStateRef.current = location.state;
|
|
25
|
+
}, [location.state]);
|
|
21
26
|
const { pageNoKey, pageSizeKey } = useMemo(() => getPaginationParamKeys(scoped ? tableId : undefined), [tableId, scoped]);
|
|
22
27
|
const initialPageIndex = useMemo(() => {
|
|
23
28
|
if (!enabled) {
|
|
@@ -47,7 +52,7 @@ export function useUrlPaginationSync({ defaultPageSize, tableId, scoped = false,
|
|
|
47
52
|
const next = new URLSearchParams(current);
|
|
48
53
|
next.set(pageNoKey, nextPageNo);
|
|
49
54
|
next.set(pageSizeKey, nextPageSize);
|
|
50
|
-
setSearchParams(next, { replace: true });
|
|
55
|
+
setSearchParams(next, { replace: true, state: locationStateRef.current });
|
|
51
56
|
}, [enabled, setSearchParams, pageNoKey, pageSizeKey]);
|
|
52
57
|
useEffect(() => {
|
|
53
58
|
if (enabled) {
|
|
@@ -59,7 +64,7 @@ export function useUrlPaginationSync({ defaultPageSize, tableId, scoped = false,
|
|
|
59
64
|
const next = new URLSearchParams(searchParams);
|
|
60
65
|
next.delete(pageNoKey);
|
|
61
66
|
next.delete(pageSizeKey);
|
|
62
|
-
setSearchParams(next, { replace: true });
|
|
67
|
+
setSearchParams(next, { replace: true, state: locationStateRef.current });
|
|
63
68
|
}, [enabled, searchParams, setSearchParams, pageNoKey, pageSizeKey]);
|
|
64
69
|
// Ensure active table pagination params exist (also when param keys change).
|
|
65
70
|
useEffect(() => {
|