@@ -3,23 +3,23 @@ import { Fragment, useCallback } from 'react';
3
3
import {
4
4
AutocompleteInput ,
5
5
BooleanField ,
6
+ Count ,
6
7
DatagridConfigurable ,
7
8
DateField ,
8
9
DateInput ,
10
+ ExportButton ,
11
+ FilterButton ,
9
12
List ,
10
13
NullableBooleanInput ,
11
14
NumberField ,
12
- ReferenceInput ,
13
15
ReferenceField ,
16
+ ReferenceInput ,
14
17
SearchInput ,
18
+ SelectColumnsButton ,
15
19
TextField ,
16
20
TextInput ,
17
- useGetList ,
18
- useListContext ,
19
21
TopToolbar ,
20
- SelectColumnsButton ,
21
- FilterButton ,
22
- ExportButton ,
22
+ useListContext ,
23
23
} from 'react-admin' ;
24
24
import { useMediaQuery , Divider , Tabs , Tab , Theme } from '@mui/material' ;
25
25
@@ -72,37 +72,12 @@ const tabs = [
72
72
{ id : 'cancelled' , name : 'cancelled' } ,
73
73
] ;
74
74
75
- const useGetTotals = ( filterValues : any ) => {
76
- const { total : totalOrdered } = useGetList ( 'commands' , {
77
- pagination : { perPage : 1 , page : 1 } ,
78
- sort : { field : 'id' , order : 'ASC' } ,
79
- filter : { ...filterValues , status : 'ordered' } ,
80
- } ) ;
81
- const { total : totalDelivered } = useGetList ( 'commands' , {
82
- pagination : { perPage : 1 , page : 1 } ,
83
- sort : { field : 'id' , order : 'ASC' } ,
84
- filter : { ...filterValues , status : 'delivered' } ,
85
- } ) ;
86
- const { total : totalCancelled } = useGetList ( 'commands' , {
87
- pagination : { perPage : 1 , page : 1 } ,
88
- sort : { field : 'id' , order : 'ASC' } ,
89
- filter : { ...filterValues , status : 'cancelled' } ,
90
- } ) ;
91
-
92
- return {
93
- ordered : totalOrdered ,
94
- delivered : totalDelivered ,
95
- cancelled : totalCancelled ,
96
- } ;
97
- } ;
98
-
99
75
const TabbedDatagrid = ( ) => {
100
76
const listContext = useListContext ( ) ;
101
77
const { filterValues, setFilters, displayedFilters } = listContext ;
102
78
const isXSmall = useMediaQuery < Theme > ( theme =>
103
79
theme . breakpoints . down ( 'sm' )
104
80
) ;
105
- const totals = useGetTotals ( filterValues ) as any ;
106
81
107
82
const handleChange = useCallback (
108
83
( event : React . ChangeEvent < { } > , value : any ) => {
@@ -129,9 +104,17 @@ const TabbedDatagrid = () => {
129
104
< Tab
130
105
key = { choice . id }
131
106
label = {
132
- totals [ choice . name ]
133
- ? `${ choice . name } (${ totals [ choice . name ] } )`
134
- : choice . name
107
+ < span >
108
+ { choice . name } (
109
+ < Count
110
+ filter = { {
111
+ ...filterValues ,
112
+ status : choice . name ,
113
+ } }
114
+ sx = { { lineHeight : 'inherit' } }
115
+ />
116
+ )
117
+ </ span >
135
118
}
136
119
value = { choice . id }
137
120
/>
0 commit comments