@campxdev/shared 1.11.37 → 1.11.39

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.11.37",
3
+ "version": "1.11.39",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -53,6 +53,7 @@ interface TableProps<T> {
53
53
  onSort?: (sort: any) => void
54
54
  dense?: boolean
55
55
  showTotal?: boolean
56
+ showNoDataIllustration?: boolean
56
57
  sx?: Record<string, SxProps<Theme>>
57
58
  totalColumns?: number[]
58
59
  showTotalInFirstCellOfTotalRow?: boolean
@@ -68,6 +69,7 @@ export default function Table<T>({
68
69
  onSort,
69
70
  dense = false,
70
71
  showTotal = false,
72
+ showNoDataIllustration = true,
71
73
  sx,
72
74
  totalColumns,
73
75
  showTotalInFirstCellOfTotalRow,
@@ -258,7 +260,9 @@ export default function Table<T>({
258
260
  </TableBody>
259
261
  ) : (
260
262
  <>
261
- <NoRecordsFound colLength={columns?.length} />
263
+ {showNoDataIllustration ? (
264
+ <NoRecordsFound colLength={columns?.length} />
265
+ ) : null}
262
266
  </>
263
267
  )}
264
268
  </>
@@ -5,6 +5,7 @@ import {
5
5
  IconButton,
6
6
  ListItemIcon,
7
7
  MenuItem,
8
+ Stack,
8
9
  Table,
9
10
  TableCell,
10
11
  TableHead,
@@ -12,8 +13,9 @@ import {
12
13
  TextField,
13
14
  Typography,
14
15
  } from '@mui/material'
15
- import { useEffect, useMemo, useState } from 'react'
16
+ import { useCallback, useEffect, useMemo, useState } from 'react'
16
17
  import { usePagination, useRowSelect, useTable } from 'react-table'
18
+ import { debounce } from '../../../utils/debounce'
17
19
  import TableStats from '../common/TableStats'
18
20
  import { SortAscIcon, SortDescIcon, SortIcon } from '../common/icons'
19
21
  import {
@@ -141,6 +143,12 @@ export default function ReactTable({
141
143
  hooks.visibleColumns.push((columns) => [selectColumn, ...columns])
142
144
  },
143
145
  )
146
+ const [pageInput, setPageInput] = useState<string>(String(pageIndex + 1))
147
+
148
+ const debouncedHandlePagination = useCallback(
149
+ debounce((e, value) => handlePagination(e, value), 500),
150
+ [],
151
+ )
144
152
 
145
153
  const handleSortClick = (sortBykey) => {
146
154
  setSort((prev) => {
@@ -238,35 +246,38 @@ export default function ReactTable({
238
246
  page={pageIndex + 1}
239
247
  totalCount={pageCount}
240
248
  />
241
- <StyledPagination
242
- variant="outlined"
243
- shape="rounded"
244
- onChange={handlePagination}
245
- count={Math.ceil(pageCount / pageSize)}
246
- page={pageIndex + 1}
247
- />
248
- {pagination.handlePageInput && (
249
- <Box
250
- sx={{
251
- '& .MuiBox-root': {
252
- display: 'flex',
253
- alignItems: 'center',
254
- gap: '5px',
255
- },
256
- }}
257
- >
258
- <TextField
259
- variant="outlined"
260
- label={'Page :'}
261
- size="small"
262
- value={pageIndex + 1}
263
- onChange={(e) =>
264
- pagination.handlePageInput(Number(e.target.value))
265
- }
266
- sx={{ width: '80px' }}
267
- />
268
- </Box>
269
- )}
249
+ <Stack direction={'row'} gap={2} alignItems={'center'}>
250
+ <StyledPagination
251
+ variant="outlined"
252
+ shape="rounded"
253
+ onChange={handlePagination}
254
+ count={Math.ceil(pageCount / pageSize)}
255
+ page={pageIndex + 1}
256
+ />
257
+ {pagination.handlePageInput && (
258
+ <Box
259
+ sx={{
260
+ '& .MuiBox-root': {
261
+ display: 'flex',
262
+ alignItems: 'center',
263
+ gap: '5px',
264
+ },
265
+ }}
266
+ >
267
+ <TextField
268
+ variant="outlined"
269
+ label={'Page :'}
270
+ size="small"
271
+ value={pageInput}
272
+ onChange={(e) => {
273
+ setPageInput(e.target.value)
274
+ debouncedHandlePagination(e, Number(e.target.value))
275
+ }}
276
+ sx={{ width: '80px' }}
277
+ />
278
+ </Box>
279
+ )}
280
+ </Stack>
270
281
  <Limit pageSize={pageSize} setPageSize={setPageSize} />
271
282
  </StyledTableFooter>
272
283
  )}
@@ -25,7 +25,7 @@ export interface TableProps {
25
25
  totalCount: number
26
26
  onChange: (offset: number) => void
27
27
  onChangeLimit?: (v: number) => void
28
- handlePageInput?: (v: number) => void
28
+ handlePageInput?: boolean
29
29
  }
30
30
  select?: {
31
31
  enable: boolean
@@ -0,0 +1,11 @@
1
+ export function debounce(func, wait) {
2
+ let timeout
3
+ return function executedFunction(...args) {
4
+ const later = () => {
5
+ clearTimeout(timeout)
6
+ func(...args)
7
+ }
8
+ clearTimeout(timeout)
9
+ timeout = setTimeout(later, wait)
10
+ }
11
+ }