@megha-ui/react 1.2.751 → 1.2.754

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 { DataRow } from "../types/grid";
2
- export declare const usePagination: (sortedData: DataRow[], defaultRowsPerPage: number, currentPageProp: number | undefined, getCurrentPage: (page: number) => void) => {
2
+ export declare const usePagination: (sortedData: DataRow[], defaultRowsPerPage: number, currentPageProp: number | undefined, getCurrentPage: (page: number) => void, totalPages: number) => {
3
3
  paginatedData: DataRow[];
4
4
  currentPage: number;
5
5
  handleChangePage: (page: number) => void;
@@ -1,15 +1,14 @@
1
1
  import { useState, useMemo, useEffect } from "react";
2
- export const usePagination = (sortedData, defaultRowsPerPage, currentPageProp, getCurrentPage) => {
2
+ export const usePagination = (sortedData, defaultRowsPerPage, currentPageProp, getCurrentPage, totalPages) => {
3
3
  const [currentPage, setCurrentPage] = useState(1);
4
4
  const [rowsPerPage, setRowsPerPage] = useState(10);
5
5
  useEffect(() => {
6
- if (currentPageProp !== undefined) {
6
+ if (currentPageProp !== undefined && currentPageProp >= 1 && currentPageProp <= totalPages) {
7
7
  setCurrentPage(currentPageProp);
8
8
  }
9
9
  else {
10
10
  setCurrentPage(1);
11
11
  }
12
- console.log("Current page prop:", currentPageProp);
13
12
  }, [currentPageProp]);
14
13
  useEffect(() => {
15
14
  setRowsPerPage(defaultRowsPerPage);
@@ -532,8 +532,9 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
532
532
  setSummariseKeys(_summariseKeys);
533
533
  setSummariseDetails(newSummariseDetails);
534
534
  };
535
+ const [totalPages, setTotalPages] = useState(0);
535
536
  const { sortedData, handleSort, sortQueries, setSortQueries } = useSort(filteredData, gridColumns, uniqueSearch, multiSorting, withAscii);
536
- const { paginatedData, currentPage, handleChangePage, handleChangeRowsPerPage, rowsPerPage, } = usePagination(sortedData, defaultRowsPerPage, propCurrentPage, getCurrentPage);
537
+ const { paginatedData, currentPage, handleChangePage, handleChangeRowsPerPage, rowsPerPage, } = usePagination(sortedData, defaultRowsPerPage, propCurrentPage, getCurrentPage, totalPages);
537
538
  useEffect(() => {
538
539
  const keys = Object.keys(summariseKeys);
539
540
  if (keys.length > 0 && summariseAvailable) {
@@ -546,7 +547,6 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
546
547
  setSelectedRows: setSelectedCheckbox,
547
548
  });
548
549
  const [hasVerticalScroll, setHasVerticalScroll] = useState(false);
549
- const [totalPages, setTotalPages] = useState(0);
550
550
  const [rowOpened, setRowOpened] = useState([]);
551
551
  const gridRef = useRef(null);
552
552
  const entrieGridRef = useRef(null);
@@ -857,7 +857,6 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
857
857
  };
858
858
  }, [sortedData, paginate, paginatedData]);
859
859
  useEffect(() => {
860
- handleChangePage(1);
861
860
  setTotalPages(getTotalPages(sortedData.length, rowsPerPage));
862
861
  }, [data, sortQueries, rowsPerPage, sortedData.length]);
863
862
  const isScrollAlmostAtEnd = (element, threshold = 100) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megha-ui/react",
3
- "version": "1.2.751",
3
+ "version": "1.2.754",
4
4
  "description": "A collection of reusable UI components for React applications, built with TypeScript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",