@megha-ui/react 1.2.749 → 1.2.751

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) => {
2
+ export declare const usePagination: (sortedData: DataRow[], defaultRowsPerPage: number, currentPageProp: number | undefined, getCurrentPage: (page: number) => void) => {
3
3
  paginatedData: DataRow[];
4
4
  currentPage: number;
5
5
  handleChangePage: (page: number) => void;
@@ -1,10 +1,15 @@
1
1
  import { useState, useMemo, useEffect } from "react";
2
- export const usePagination = (sortedData, defaultRowsPerPage, currentPageProp) => {
3
- const [currentPage, setCurrentPage] = useState(currentPageProp);
2
+ export const usePagination = (sortedData, defaultRowsPerPage, currentPageProp, getCurrentPage) => {
3
+ const [currentPage, setCurrentPage] = useState(1);
4
4
  const [rowsPerPage, setRowsPerPage] = useState(10);
5
5
  useEffect(() => {
6
- console.log("Current page prop changed:", currentPageProp);
7
- setCurrentPage(currentPageProp);
6
+ if (currentPageProp !== undefined) {
7
+ setCurrentPage(currentPageProp);
8
+ }
9
+ else {
10
+ setCurrentPage(1);
11
+ }
12
+ console.log("Current page prop:", currentPageProp);
8
13
  }, [currentPageProp]);
9
14
  useEffect(() => {
10
15
  setRowsPerPage(defaultRowsPerPage);
@@ -15,6 +20,7 @@ export const usePagination = (sortedData, defaultRowsPerPage, currentPageProp) =
15
20
  }, [sortedData, currentPage, rowsPerPage]);
16
21
  const handleChangePage = (page) => {
17
22
  setCurrentPage(page);
23
+ getCurrentPage(page);
18
24
  };
19
25
  const handleChangeRowsPerPage = (value) => {
20
26
  setRowsPerPage(parseInt(value.toString(), 10));
@@ -42,7 +42,7 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
42
42
  // Card wrapper props
43
43
  withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, subHeader, cardFooter, getCurrentPage = (page) => {
44
44
  console.log("Current page:", page);
45
- }, currentPage: propCurrentPage = 1, }) => {
45
+ }, currentPage: propCurrentPage, }) => {
46
46
  var _a, _b, _c, _d;
47
47
  const [searchQueries, setSearchQueries] = useState({});
48
48
  const [chips, setChips] = useState([]);
@@ -533,10 +533,7 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
533
533
  setSummariseDetails(newSummariseDetails);
534
534
  };
535
535
  const { sortedData, handleSort, sortQueries, setSortQueries } = useSort(filteredData, gridColumns, uniqueSearch, multiSorting, withAscii);
536
- const { paginatedData, currentPage, handleChangePage, handleChangeRowsPerPage, rowsPerPage, } = usePagination(sortedData, defaultRowsPerPage, propCurrentPage);
537
- useEffect(() => {
538
- getCurrentPage(currentPage);
539
- }, [currentPage]);
536
+ const { paginatedData, currentPage, handleChangePage, handleChangeRowsPerPage, rowsPerPage, } = usePagination(sortedData, defaultRowsPerPage, propCurrentPage, getCurrentPage);
540
537
  useEffect(() => {
541
538
  const keys = Object.keys(summariseKeys);
542
539
  if (keys.length > 0 && summariseAvailable) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megha-ui/react",
3
- "version": "1.2.749",
3
+ "version": "1.2.751",
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",