@applica-software-guru/react-admin 1.5.359 → 1.5.362-alpha1

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/dist/style.css.gz CHANGED
Binary file
package/package.json CHANGED
@@ -108,5 +108,5 @@
108
108
  "type": "module",
109
109
  "types": "dist/index.d.ts",
110
110
  "typings": "dist/index.d.ts",
111
- "version": "1.5.359"
111
+ "version": "1.5.362-alpha1"
112
112
  }
@@ -4,6 +4,7 @@ import {
4
4
  ComponentPropType,
5
5
  ListPaginationContextValue,
6
6
  sanitizeListRestProps,
7
+ useListContext,
7
8
  useListPaginationContext,
8
9
  useResourceDefinition,
9
10
  useTranslate
@@ -16,6 +17,8 @@ import { PaginationActions, PaginationActionsProps } from './PaginationActions';
16
17
  const Pagination: FC<PaginationProps> = memo((props) => {
17
18
  const { rowsPerPageOptions = DefaultRowsPerPageOptions, actions, limit = null, ...rest } = props;
18
19
  const { isLoading, hasNextPage, page, perPage, total, setPage, setPerPage } = useListPaginationContext(props);
20
+ // Recupera i dati della pagina corrente
21
+ const { data } = useListContext();
19
22
  const translate = useTranslate();
20
23
  const isSmall = useMediaQuery((theme: Theme) => theme.breakpoints.down('md'));
21
24
  const [currentPage, setCurrentPage] = useState(page - 1); // Stato per la UI
@@ -33,7 +36,12 @@ const Pagination: FC<PaginationProps> = memo((props) => {
33
36
  setIsSelectedPage(false);
34
37
  }, [page]);
35
38
 
39
+ // Modalità infinito: total === -1
36
40
  const totalPages = useMemo(() => {
41
+ if (total === -1) {
42
+ // In modalità infinito, non conosciamo il totale
43
+ return undefined;
44
+ }
37
45
  return total != null ? Math.ceil(total / perPage) : undefined;
38
46
  }, [perPage, total]);
39
47
 
@@ -55,12 +63,30 @@ const Pagination: FC<PaginationProps> = memo((props) => {
55
63
  }
56
64
 
57
65
  event.preventDefault();
58
- if (page < 0 || (totalPages !== undefined && page > totalPages - 1)) {
59
- throw new Error(
60
- translate('ra.navigation.page_out_of_boundaries', {
61
- page: page + 1
62
- })
63
- );
66
+ // Modalità infinito: total === -1
67
+ if (total === -1) {
68
+ // Puoi andare indietro se page >= 0
69
+ // Puoi andare avanti solo se la pagina attuale ha rowsPerPage record
70
+ const canGoForward = data && Array.isArray(data) && data.length === perPage;
71
+ if (page < 0) {
72
+ throw new Error(
73
+ translate('ra.navigation.page_out_of_boundaries', {
74
+ page: page + 1
75
+ })
76
+ );
77
+ }
78
+ if (page > currentPage && !canGoForward) {
79
+ // Non puoi andare avanti se la risposta è minore di rowsPerPage
80
+ return;
81
+ }
82
+ } else {
83
+ if (page < 0 || (totalPages !== undefined && page > totalPages - 1)) {
84
+ throw new Error(
85
+ translate('ra.navigation.page_out_of_boundaries', {
86
+ page: page + 1
87
+ })
88
+ );
89
+ }
64
90
  }
65
91
 
66
92
  const arrowSelected =
@@ -84,7 +110,7 @@ const Pagination: FC<PaginationProps> = memo((props) => {
84
110
  setPage(page + 1);
85
111
  }
86
112
  },
87
- [debouncedPageChange, setPage, translate, totalPages, setIsSelectedPage]
113
+ [debouncedPageChange, setPage, translate, totalPages, setIsSelectedPage, total, data, perPage, currentPage]
88
114
  );
89
115
 
90
116
  const handlePerPageChange = useCallback(
@@ -176,7 +202,7 @@ const Pagination: FC<PaginationProps> = memo((props) => {
176
202
  // @ts-ignore
177
203
  ActionsComponent={ActionsComponent}
178
204
  nextIconButtonProps={{
179
- disabled: !hasNextPage
205
+ disabled: total === -1 ? !(data && Array.isArray(data) && data.length === perPage) : !hasNextPage
180
206
  }}
181
207
  component="span"
182
208
  labelRowsPerPage={translate('ra.navigation.page_rows_per_page')}
@@ -1,16 +1,22 @@
1
1
  import { FC, memo } from 'react';
2
2
  import { styled } from '@mui/material/styles';
3
3
  import { Pagination, PaginationProps } from '@mui/material';
4
+ import { useListContext, useTranslate } from 'ra-core';
4
5
  import PropTypes from 'prop-types';
5
- import { useTranslate } from 'ra-core';
6
6
 
7
7
  const PaginationActions: FC<PaginationActionsProps> = memo((props) => {
8
8
  const { page, rowsPerPage, count, onPageChange, size = 'small', className, ...rest } = props;
9
+ const { data } = useListContext();
9
10
  const translate = useTranslate();
10
11
 
11
12
  const nbPages = Math.ceil(count / rowsPerPage) || 1;
12
13
 
13
- if (nbPages === 1) {
14
+ // Modalità infinito: total === -1
15
+ const isInfinite = count === -1;
16
+ // Disabilita avanti se i record sono meno di rowsPerPage
17
+ const disableNext = isInfinite ? !(data && Array.isArray(data) && data.length === rowsPerPage) : page + 1 >= nbPages;
18
+
19
+ if (nbPages === 1 && !isInfinite) {
14
20
  return <Root className={className} />;
15
21
  }
16
22
 
@@ -33,13 +39,22 @@ const PaginationActions: FC<PaginationActionsProps> = memo((props) => {
33
39
  <Root className={className}>
34
40
  <Pagination
35
41
  size={size}
36
- count={nbPages}
37
- // <TablePagination>, the parent, uses 0-based pagination
38
- // while <Pagination> uses 1-based pagination
42
+ count={isInfinite ? page + 2 : nbPages}
39
43
  page={page + 1}
40
- onChange={(e: any, page) => onPageChange(e, page - 1)}
44
+ onChange={(e: any, newPage) => {
45
+ // Disabilita avanti in modalità infinito
46
+ if (isInfinite && newPage - 1 > page && disableNext) return;
47
+ onPageChange(e, newPage - 1);
48
+ }}
41
49
  {...sanitizeRestProps(rest)}
42
50
  getItemAriaLabel={getItemAriaLabel}
51
+ renderItem={(item) => {
52
+ // Disabilita il bottone avanti in modalità infinito
53
+ if (isInfinite && item.type === 'next') {
54
+ return { ...item, disabled: disableNext };
55
+ }
56
+ return item;
57
+ }}
43
58
  />
44
59
  </Root>
45
60
  );
@@ -1,11 +1,12 @@
1
- import { LabeledInput } from '@/components/ra-inputs/LabeledInput';
1
+ import { LabeledInput, LabeledInputProps } from '@/components/ra-inputs/LabeledInput';
2
2
  import { styled } from '@mui/material/styles';
3
- import { AutocompleteInputProps, AutocompleteInput as RaAutocompleteInput } from 'react-admin';
3
+ import {
4
+ AutocompleteInput as RaAutocompleteInput,
5
+ AutocompleteInputProps as RaAutocompleteInputProps
6
+ } from 'react-admin';
4
7
 
5
- // @ts-ignore
6
- const StyledAutocompleteInput = styled(RaAutocompleteInput, {
7
- name: 'StyledAutocompleteInput',
8
- root: 'root'
8
+ const StyledAutocompleteInput = styled(RaAutocompleteInput as any, {
9
+ name: 'StyledAutocompleteInput'
9
10
  })(({ label }) => ({
10
11
  '& legend': {
11
12
  width: label === false ? 0 : 'auto'
@@ -15,6 +16,8 @@ const StyledAutocompleteInput = styled(RaAutocompleteInput, {
15
16
  }
16
17
  }));
17
18
 
19
+ type AutocompleteInputProps = RaAutocompleteInputProps & LabeledInputProps;
20
+
18
21
  function AutocompleteInput({ size = 'small', ...props }: AutocompleteInputProps): JSX.Element {
19
22
  // Sanitize props removing "perPage":
20
23
  // @ts-ignore