@eml-payments/ui-kit 1.7.6 → 1.7.7

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.
@@ -10,7 +10,7 @@ export function useStandardTableController(props) {
10
10
  // sorting / grouping
11
11
  sorting, onSortingChange, grouping, enableAccordion,
12
12
  // search
13
- searchQuery, minSearchLength = 3, tableActionsDropdown, } = props;
13
+ searchQuery, minSearchLength = 3, isSearchActive, tableActionsDropdown, } = props;
14
14
  // Keep previous data while loading to prevent UI jumps on page change
15
15
  const prevDataRef = useRef([]);
16
16
  // Always cache the latest non-empty data
@@ -48,12 +48,28 @@ export function useStandardTableController(props) {
48
48
  });
49
49
  const [pageIndex, setPageIndex] = useState(initialPageIndex);
50
50
  const [pageSize, setPageSize] = useState(initialPageSize);
51
+ const prevIsSearchActiveRef = useRef(Boolean(isSearchActive));
52
+ const prevSearchQueryRef = useRef(searchQuery);
51
53
  useEffect(() => {
52
54
  setPageIndex(initialPageIndex);
53
55
  }, [initialPageIndex]);
54
56
  useEffect(() => {
55
57
  setPageSize(initialPageSize);
56
58
  }, [initialPageSize]);
59
+ // Reset pagination to first page when search becomes active
60
+ // or when the active search query changes
61
+ useEffect(() => {
62
+ const isSearchActiveNow = Boolean(isSearchActive);
63
+ const searchQueryChanged = prevSearchQueryRef.current !== searchQuery;
64
+ const becameSearchActive = !prevIsSearchActiveRef.current && isSearchActiveNow;
65
+ const queryChangedWhileActive = searchQueryChanged && isSearchActiveNow;
66
+ if ((becameSearchActive || queryChangedWhileActive) && pageIndex !== 0) {
67
+ setPageIndex(0);
68
+ syncToUrl(0, pageSize);
69
+ }
70
+ prevIsSearchActiveRef.current = isSearchActiveNow;
71
+ prevSearchQueryRef.current = searchQuery;
72
+ }, [isSearchActive, searchQuery, pageIndex, pageSize, syncToUrl]);
57
73
  const [internalSorting, setInternalSorting] = useState(sorting !== null && sorting !== void 0 ? sorting : []);
58
74
  const [expanded, setExpanded] = useState(true);
59
75
  const stableGrouping = useMemo(() => grouping !== null && grouping !== void 0 ? grouping : [], [grouping]);
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useMemo } from 'react';
1
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
2
2
  import { useSearchParams } from 'react-router-dom';
3
3
  function getPaginationParamKeys(tableId) {
4
4
  if (tableId) {
@@ -14,6 +14,10 @@ function getPaginationParamKeys(tableId) {
14
14
  }
15
15
  export function useUrlPaginationSync({ defaultPageSize, tableId, scoped = false, enabled = true, }) {
16
16
  const [searchParams, setSearchParams] = useSearchParams();
17
+ const searchParamsRef = useRef(searchParams);
18
+ useEffect(() => {
19
+ searchParamsRef.current = searchParams;
20
+ }, [searchParams]);
17
21
  const { pageNoKey, pageSizeKey } = useMemo(() => getPaginationParamKeys(scoped ? tableId : undefined), [tableId, scoped]);
18
22
  const initialPageIndex = useMemo(() => {
19
23
  if (!enabled) {
@@ -34,11 +38,17 @@ export function useUrlPaginationSync({ defaultPageSize, tableId, scoped = false,
34
38
  if (!enabled) {
35
39
  return;
36
40
  }
37
- const next = new URLSearchParams(searchParams);
38
- next.set(pageNoKey, String(pageIndex + 1)); // 1-based
39
- next.set(pageSizeKey, String(pageSize));
41
+ const current = searchParamsRef.current;
42
+ const nextPageNo = String(pageIndex + 1); // 1-based
43
+ const nextPageSize = String(pageSize);
44
+ if (current.get(pageNoKey) === nextPageNo && current.get(pageSizeKey) === nextPageSize) {
45
+ return;
46
+ }
47
+ const next = new URLSearchParams(current);
48
+ next.set(pageNoKey, nextPageNo);
49
+ next.set(pageSizeKey, nextPageSize);
40
50
  setSearchParams(next, { replace: true });
41
- }, [enabled, searchParams, setSearchParams, pageNoKey, pageSizeKey]);
51
+ }, [enabled, setSearchParams, pageNoKey, pageSizeKey]);
42
52
  useEffect(() => {
43
53
  if (enabled) {
44
54
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eml-payments/ui-kit",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "private": false,
5
5
  "description": "ARLO UIKit",
6
6
  "homepage": "https://github.com/EML-Payments/arlo.npm.uikit#readme",