From 5d0e839052462767d7bc608e9784330cde813b97 Mon Sep 17 00:00:00 2001 From: jacovinus Date: Tue, 23 Jan 2024 18:45:39 +0100 Subject: [PATCH] fix: pagination --- .../TotalsPanel/CardinalityTotals.tsx | 96 ++++--------------- .../Cardinality/TotalsPanel/Pagination.tsx | 60 ++++++++++++ .../Cardinality/TotalsPanel/TotalsTable.tsx | 53 ++++++++++ .../Cardinality/TotalsPanel/consts.tsx | 8 ++ .../plugins/Cardinality/TotalsPanel/style.tsx | 28 +++++- 5 files changed, 163 insertions(+), 82 deletions(-) create mode 100644 packages/main/plugins/Cardinality/TotalsPanel/Pagination.tsx create mode 100644 packages/main/plugins/Cardinality/TotalsPanel/TotalsTable.tsx diff --git a/packages/main/plugins/Cardinality/TotalsPanel/CardinalityTotals.tsx b/packages/main/plugins/Cardinality/TotalsPanel/CardinalityTotals.tsx index 74e47277..ee6fda17 100644 --- a/packages/main/plugins/Cardinality/TotalsPanel/CardinalityTotals.tsx +++ b/packages/main/plugins/Cardinality/TotalsPanel/CardinalityTotals.tsx @@ -5,13 +5,12 @@ import { useCallback, useEffect, useState } from "react"; import { totalsMock } from "../api/mock"; import { cx } from "@emotion/css"; -import { PROCESS_HEADERS } from "./consts"; +import { PROCESS_HEADERS, NUMBER_COLS } from "./consts"; import { TotalRowStyle } from "./style"; import useTheme from "@ui/theme/useTheme"; -import { TotalsRow } from "./TotalsRow"; import { getMaintenance, useMaintenance } from "./useMaintenance"; import "./array_helper.mjs"; - +import TotalsTable from "./TotalsTable"; export default function CardinalityTotals({ isLoading }) { const Maintainance = useMaintenance(); @@ -41,20 +40,12 @@ export default function CardinalityTotals({ isLoading }) { const sortByProperty = useCallback( (column: string) => { - const numberCols = [ - "series_created", - "series_dropped", - "to_sec", - "from_sec", - "created_sec", - ]; - const columnName = column.split(" ").join("_").toLocaleLowerCase(); setTotals(() => { let items = [...Maintainance]; - if (numberCols.includes(columnName)) { + if (NUMBER_COLS.includes(columnName)) { items.sortColByNumber(columnName, sort); return paginateTotals(items); } @@ -71,73 +62,24 @@ export default function CardinalityTotals({ isLoading }) { return (
- Fingerprints in Maintainance mode + {totals?.length > 0 + ? "Fingerprints in Maintainance mode" + : "No Fingerprints in Maintainance mode"}
-
-
- {PROCESS_HEADERS?.map((header) => ( -
sortByProperty(header)} - className="cell" - > - {header} -
- ))} -
- -
- {totals?.length ? ( - totals?.map((total, key) => ( - - )) - ) : ( - <> no totals - )} -
-
- + {totals?.length > 0 && ( + + )}
); } - -export const TotalsPagination = ({ - page, - totalPages, - setPage, - rowsPerPage, - setRowsPerPage, -}) => { - return ( -
- - - - - -

- Page {page + 1} of {totalPages} -

-
- ); -}; diff --git a/packages/main/plugins/Cardinality/TotalsPanel/Pagination.tsx b/packages/main/plugins/Cardinality/TotalsPanel/Pagination.tsx new file mode 100644 index 00000000..20785d7f --- /dev/null +++ b/packages/main/plugins/Cardinality/TotalsPanel/Pagination.tsx @@ -0,0 +1,60 @@ +import FastForwardOutlinedIcon from "@mui/icons-material/FastForwardOutlined"; +import FastRewindOutlinedIcon from "@mui/icons-material/FastRewindOutlined"; +import SkipNextOutlinedIcon from "@mui/icons-material/SkipNextOutlined"; +import SkipPreviousOutlinedIcon from "@mui/icons-material/SkipPreviousOutlined"; + +const TotalsPagination = ({ + page, + totalPages, + setPage, + rowsPerPage, + setRowsPerPage, +}) => { + return ( +
+ + +

+ Page {page + 1} of {totalPages} +

+ + +
+ ); +}; + +export default TotalsPagination; diff --git a/packages/main/plugins/Cardinality/TotalsPanel/TotalsTable.tsx b/packages/main/plugins/Cardinality/TotalsPanel/TotalsTable.tsx new file mode 100644 index 00000000..4019273d --- /dev/null +++ b/packages/main/plugins/Cardinality/TotalsPanel/TotalsTable.tsx @@ -0,0 +1,53 @@ +import { TotalsRow } from "./TotalsRow"; +import TotalsPagination from "./Pagination"; + +const TotalsTable = ({ + headers, + sortByProperty, + isLoading, + totals, + page, + setPage, + rowsPerPage, + setRowsPerPage, + Maintainance, +}) => { + return ( + <> +
+
+ {headers?.map((header) => ( +
sortByProperty(header)} + className="cell" + > + {header} +
+ ))} +
+ +
+ {totals?.map((total, key) => ( + + ))} +
+
+ + + + ); +}; + +export default TotalsTable; diff --git a/packages/main/plugins/Cardinality/TotalsPanel/consts.tsx b/packages/main/plugins/Cardinality/TotalsPanel/consts.tsx index 89432070..9e385101 100644 --- a/packages/main/plugins/Cardinality/TotalsPanel/consts.tsx +++ b/packages/main/plugins/Cardinality/TotalsPanel/consts.tsx @@ -10,3 +10,11 @@ export const PROCESS_HEADERS = [ "Logs", "Undo", ]; + +export const NUMBER_COLS = [ + "series_created", + "series_dropped", + "to_sec", + "from_sec", + "created_sec", +]; diff --git a/packages/main/plugins/Cardinality/TotalsPanel/style.tsx b/packages/main/plugins/Cardinality/TotalsPanel/style.tsx index 64ab0677..e29e702a 100644 --- a/packages/main/plugins/Cardinality/TotalsPanel/style.tsx +++ b/packages/main/plugins/Cardinality/TotalsPanel/style.tsx @@ -64,22 +64,40 @@ export const TotalRowStyle = (theme: QrynTheme) => css` display: flex; font-size: 10px; text-transform: uppercase; - align-items:center; + align-items: center; gap: 4px; - padding: 4px 0px; + padding: 4px 12px; margin: 0px 4px; + margin-top: 12px; border-radius: 3px; background: ${theme.shadow}; - + p { + margin: 0px 12px; + } + .disabled { + pointer-events: none; + opacity: 0.5; + } button { padding: 4px 12px; color: white; border: none; - background: ${theme.primary}; + font-size: 10px; + display: flex; + align-items: center; + justify-content: center; + line-height: 0; + gap: 4px; + background: ${theme.shadow}; border-radius: 3px; - border-color: ${theme.primaryAccent}; + border: 1px solid ${theme.deep}; cursor: pointer; outline: none; + letter-spacing: 1px; + + :hover { + background: ${theme.deep}; + } } }