5
5
import { useCallback , useEffect , useState } from "react" ;
6
6
import { totalsMock } from "../api/mock" ;
7
7
import { cx } from "@emotion/css" ;
8
- import { PROCESS_HEADERS } from "./consts" ;
8
+ import { PROCESS_HEADERS , NUMBER_COLS } from "./consts" ;
9
9
import { TotalRowStyle } from "./style" ;
10
10
import useTheme from "@ui/theme/useTheme" ;
11
- import { TotalsRow } from "./TotalsRow" ;
12
11
import { getMaintenance , useMaintenance } from "./useMaintenance" ;
13
12
import "./array_helper.mjs" ;
14
-
13
+ import TotalsTable from "./TotalsTable" ;
15
14
export default function CardinalityTotals ( { isLoading } ) {
16
15
const Maintainance = useMaintenance ( ) ;
17
16
@@ -41,20 +40,12 @@ export default function CardinalityTotals({ isLoading }) {
41
40
42
41
const sortByProperty = useCallback (
43
42
( column : string ) => {
44
- const numberCols = [
45
- "series_created" ,
46
- "series_dropped" ,
47
- "to_sec" ,
48
- "from_sec" ,
49
- "created_sec" ,
50
- ] ;
51
-
52
43
const columnName = column . split ( " " ) . join ( "_" ) . toLocaleLowerCase ( ) ;
53
44
54
45
setTotals ( ( ) => {
55
46
let items = [ ...Maintainance ] ;
56
47
57
- if ( numberCols . includes ( columnName ) ) {
48
+ if ( NUMBER_COLS . includes ( columnName ) ) {
58
49
items . sortColByNumber ( columnName , sort ) ;
59
50
return paginateTotals ( items ) ;
60
51
}
@@ -71,73 +62,24 @@ export default function CardinalityTotals({ isLoading }) {
71
62
return (
72
63
< div className = { cx ( TotalRowStyle ( theme ) ) } >
73
64
< div className = "total-rows-header" >
74
- Fingerprints in Maintainance mode
65
+ { totals ?. length > 0
66
+ ? "Fingerprints in Maintainance mode"
67
+ : "No Fingerprints in Maintainance mode" }
75
68
</ div >
76
69
77
- < div className = "table" >
78
- < div className = "table-header" >
79
- { PROCESS_HEADERS ?. map ( ( header ) => (
80
- < div
81
- key = { header }
82
- onClick = { ( ) => sortByProperty ( header ) }
83
- className = "cell"
84
- >
85
- { header }
86
- </ div >
87
- ) ) }
88
- </ div >
89
-
90
- < div className = "table-body" >
91
- { totals ?. length ? (
92
- totals ?. map ( ( total , key ) => (
93
- < TotalsRow
94
- key = { key }
95
- isLoading = { isLoading }
96
- headers = { PROCESS_HEADERS }
97
- total = { total }
98
- />
99
- ) )
100
- ) : (
101
- < > no totals </ >
102
- ) }
103
- </ div >
104
- </ div >
105
- < TotalsPagination
106
- page = { page }
107
- totalPages = { Maintainance . length / rowsPerPage }
108
- setPage = { setPage }
109
- rowsPerPage = { rowsPerPage }
110
- setRowsPerPage = { setRowsPerPage }
111
- />
70
+ { totals ?. length > 0 && (
71
+ < TotalsTable
72
+ headers = { PROCESS_HEADERS }
73
+ sortByProperty = { sortByProperty }
74
+ isLoading = { isLoading }
75
+ totals = { totals }
76
+ page = { page }
77
+ setPage = { setPage }
78
+ rowsPerPage = { rowsPerPage }
79
+ setRowsPerPage = { setRowsPerPage }
80
+ Maintainance = { Maintainance }
81
+ />
82
+ ) }
112
83
</ div >
113
84
) ;
114
85
}
115
-
116
- export const TotalsPagination = ( {
117
- page,
118
- totalPages,
119
- setPage,
120
- rowsPerPage,
121
- setRowsPerPage,
122
- } ) => {
123
- return (
124
- < div className = "table-footer" >
125
- < button onClick = { ( ) => setPage ( ( ) => 0 ) } > First</ button >
126
- < button onClick = { ( ) => setPage ( ( ) => Math . max ( 0 , page - 1 ) ) } >
127
- Prev
128
- </ button >
129
- < button
130
- onClick = { ( ) =>
131
- setPage ( ( ) => Math . min ( totalPages - 1 , page + 1 ) )
132
- }
133
- >
134
- Next
135
- </ button >
136
- < button onClick = { ( ) => setPage ( totalPages - 1 ) } > Last</ button >
137
-
138
- < p >
139
- Page { page + 1 } of { totalPages }
140
- </ p >
141
- </ div >
142
- ) ;
143
- } ;
0 commit comments