Skip to content

Commit 5d0e839

Browse files
committed
fix: pagination
1 parent 2a50a47 commit 5d0e839

File tree

5 files changed

+163
-82
lines changed

5 files changed

+163
-82
lines changed

packages/main/plugins/Cardinality/TotalsPanel/CardinalityTotals.tsx

+19-77
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import { useCallback, useEffect, useState } from "react";
66
import { totalsMock } from "../api/mock";
77
import { cx } from "@emotion/css";
8-
import { PROCESS_HEADERS } from "./consts";
8+
import { PROCESS_HEADERS, NUMBER_COLS } from "./consts";
99
import { TotalRowStyle } from "./style";
1010
import useTheme from "@ui/theme/useTheme";
11-
import { TotalsRow } from "./TotalsRow";
1211
import { getMaintenance, useMaintenance } from "./useMaintenance";
1312
import "./array_helper.mjs";
14-
13+
import TotalsTable from "./TotalsTable";
1514
export default function CardinalityTotals({ isLoading }) {
1615
const Maintainance = useMaintenance();
1716

@@ -41,20 +40,12 @@ export default function CardinalityTotals({ isLoading }) {
4140

4241
const sortByProperty = useCallback(
4342
(column: string) => {
44-
const numberCols = [
45-
"series_created",
46-
"series_dropped",
47-
"to_sec",
48-
"from_sec",
49-
"created_sec",
50-
];
51-
5243
const columnName = column.split(" ").join("_").toLocaleLowerCase();
5344

5445
setTotals(() => {
5546
let items = [...Maintainance];
5647

57-
if (numberCols.includes(columnName)) {
48+
if (NUMBER_COLS.includes(columnName)) {
5849
items.sortColByNumber(columnName, sort);
5950
return paginateTotals(items);
6051
}
@@ -71,73 +62,24 @@ export default function CardinalityTotals({ isLoading }) {
7162
return (
7263
<div className={cx(TotalRowStyle(theme))}>
7364
<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"}
7568
</div>
7669

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+
)}
11283
</div>
11384
);
11485
}
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-
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import FastForwardOutlinedIcon from "@mui/icons-material/FastForwardOutlined";
2+
import FastRewindOutlinedIcon from "@mui/icons-material/FastRewindOutlined";
3+
import SkipNextOutlinedIcon from "@mui/icons-material/SkipNextOutlined";
4+
import SkipPreviousOutlinedIcon from "@mui/icons-material/SkipPreviousOutlined";
5+
6+
const TotalsPagination = ({
7+
page,
8+
totalPages,
9+
setPage,
10+
rowsPerPage,
11+
setRowsPerPage,
12+
}) => {
13+
return (
14+
<div className="table-footer">
15+
<button
16+
className={page === 0 ? "disabled" : ""}
17+
onClick={() => setPage(() => 0)}
18+
>
19+
<FastRewindOutlinedIcon
20+
style={{ height: "12px", width: "12px" }}
21+
/>{" "}
22+
First
23+
</button>
24+
<button
25+
className={page === 0 ? "disabled" : ""}
26+
onClick={() => setPage(() => Math.max(0, page - 1))}
27+
>
28+
<SkipPreviousOutlinedIcon
29+
style={{ height: "12px", width: "12px" }}
30+
/>{" "}
31+
Prev
32+
</button>
33+
<p>
34+
Page {page + 1} of {totalPages}
35+
</p>
36+
<button
37+
className={page === totalPages - 1 ? "disabled" : ""}
38+
onClick={() =>
39+
setPage(() => Math.min(totalPages - 1, page + 1))
40+
}
41+
>
42+
Next{" "}
43+
<SkipNextOutlinedIcon
44+
style={{ height: "12px", width: "12px" }}
45+
/>
46+
</button>
47+
<button
48+
className={page === totalPages - 1 ? "disabled" : ""}
49+
onClick={() => setPage(totalPages - 1)}
50+
>
51+
Last{" "}
52+
<FastForwardOutlinedIcon
53+
style={{ height: "12px", width: "12px" }}
54+
/>
55+
</button>
56+
</div>
57+
);
58+
};
59+
60+
export default TotalsPagination;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { TotalsRow } from "./TotalsRow";
2+
import TotalsPagination from "./Pagination";
3+
4+
const TotalsTable = ({
5+
headers,
6+
sortByProperty,
7+
isLoading,
8+
totals,
9+
page,
10+
setPage,
11+
rowsPerPage,
12+
setRowsPerPage,
13+
Maintainance,
14+
}) => {
15+
return (
16+
<>
17+
<div className="table">
18+
<div className="table-header">
19+
{headers?.map((header) => (
20+
<div
21+
key={header}
22+
onClick={() => sortByProperty(header)}
23+
className="cell"
24+
>
25+
{header}
26+
</div>
27+
))}
28+
</div>
29+
30+
<div className="table-body">
31+
{totals?.map((total, key) => (
32+
<TotalsRow
33+
key={key}
34+
isLoading={isLoading}
35+
headers={headers}
36+
total={total}
37+
/>
38+
))}
39+
</div>
40+
</div>
41+
42+
<TotalsPagination
43+
page={page}
44+
totalPages={Maintainance.length / rowsPerPage}
45+
setPage={setPage}
46+
rowsPerPage={rowsPerPage}
47+
setRowsPerPage={setRowsPerPage}
48+
/>
49+
</>
50+
);
51+
};
52+
53+
export default TotalsTable;

packages/main/plugins/Cardinality/TotalsPanel/consts.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ export const PROCESS_HEADERS = [
1010
"Logs",
1111
"Undo",
1212
];
13+
14+
export const NUMBER_COLS = [
15+
"series_created",
16+
"series_dropped",
17+
"to_sec",
18+
"from_sec",
19+
"created_sec",
20+
];

packages/main/plugins/Cardinality/TotalsPanel/style.tsx

+23-5
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,40 @@ export const TotalRowStyle = (theme: QrynTheme) => css`
6464
display: flex;
6565
font-size: 10px;
6666
text-transform: uppercase;
67-
align-items:center;
67+
align-items: center;
6868
gap: 4px;
69-
padding: 4px 0px;
69+
padding: 4px 12px;
7070
margin: 0px 4px;
71+
margin-top: 12px;
7172
border-radius: 3px;
7273
background: ${theme.shadow};
73-
74+
p {
75+
margin: 0px 12px;
76+
}
77+
.disabled {
78+
pointer-events: none;
79+
opacity: 0.5;
80+
}
7481
button {
7582
padding: 4px 12px;
7683
color: white;
7784
border: none;
78-
background: ${theme.primary};
85+
font-size: 10px;
86+
display: flex;
87+
align-items: center;
88+
justify-content: center;
89+
line-height: 0;
90+
gap: 4px;
91+
background: ${theme.shadow};
7992
border-radius: 3px;
80-
border-color: ${theme.primaryAccent};
93+
border: 1px solid ${theme.deep};
8194
cursor: pointer;
8295
outline: none;
96+
letter-spacing: 1px;
97+
98+
:hover {
99+
background: ${theme.deep};
100+
}
83101
}
84102
}
85103

0 commit comments

Comments
 (0)