diff --git a/src/components/Statistics/DomainStatistics.tsx b/src/components/Statistics/DomainStatistics.tsx index d8a7fea5d9..202df51bfb 100644 --- a/src/components/Statistics/DomainStatistics.tsx +++ b/src/components/Statistics/DomainStatistics.tsx @@ -1,10 +1,17 @@ -import { Card, Grid, ListItem, List } from "@mui/material"; +import { + Paper, + Table, + TableBody, + TableContainer, + TableHead, + TableRow, +} from "@mui/material"; import { ReactElement, useState, useEffect } from "react"; -import { SemanticDomainCount, SemanticDomainTreeNode } from "api/models"; +import { SemanticDomainCount } from "api/models"; import { getSemanticDomainCounts } from "backend"; import * as LocalStorage from "backend/localStorage"; -import { ColumnHead, TableCell } from "components/Statistics/TableCells"; +import { Cell, HeadCell } from "components/Statistics/TableCells"; interface DomainStatisticsProps { lang: string; @@ -38,40 +45,25 @@ export default function DomainStatistics( } return ( - - - - - - - - - - + + + + + + + + + + {statisticsList.map((t) => ( - + + + + + ))} - - - - ); -} - -function TableRow(props: { - dom: SemanticDomainTreeNode; - count: number; -}): ReactElement { - return ( - - - - - - - + +
+
); } diff --git a/src/components/Statistics/Statistics.tsx b/src/components/Statistics/Statistics.tsx index 7de76f12a4..ab725b9d4e 100644 --- a/src/components/Statistics/Statistics.tsx +++ b/src/components/Statistics/Statistics.tsx @@ -1,6 +1,6 @@ import { Divider, - Grid, + Grid2, ListItemButton, ListItemText, Typography, @@ -65,24 +65,6 @@ export default function Statistics(): ReactElement { } } - function handleDisplay(): ReactElement[] { - return [ - - - {t("statistics.title", { val: currentProject?.name })} - - , - - - {t(`statistics.view.${viewName}`)} - - , - - {componentToDisplay(viewName as viewEnum)} - , - ]; - } - function handleButton(): ReactElement { return ( @@ -118,23 +100,28 @@ export default function Statistics(): ReactElement { } return ( - - - {handleButton()} - - + {handleButton()} + + - {handleDisplay()} - - + + {t("statistics.title", { val: currentProject?.name })} + + + {t(`statistics.view.${viewName}`)} + + {componentToDisplay(viewName as viewEnum)} + + + - - + + ); } diff --git a/src/components/Statistics/TableCells.tsx b/src/components/Statistics/TableCells.tsx index 0c698852de..5b08307735 100644 --- a/src/components/Statistics/TableCells.tsx +++ b/src/components/Statistics/TableCells.tsx @@ -1,38 +1,21 @@ -import { Grid, Typography } from "@mui/material"; +import { TableCell, Typography } from "@mui/material"; import { ReactElement } from "react"; import { useTranslation } from "react-i18next"; -export function ColumnHead(props: { titleId: string }): ReactElement { +export function HeadCell(props: { titleId: string }): ReactElement { const { t } = useTranslation(); + return ( - + {t(props.titleId)} - + ); } -export function TableCell(props: { - text?: string | number | null; -}): ReactElement { +export function Cell(props: { text?: string | number | null }): ReactElement { return ( - + {props.text} - + ); } diff --git a/src/components/Statistics/UserStatistics.tsx b/src/components/Statistics/UserStatistics.tsx index 6af69c91d8..69212b2b30 100644 --- a/src/components/Statistics/UserStatistics.tsx +++ b/src/components/Statistics/UserStatistics.tsx @@ -1,10 +1,17 @@ -import { Card, Grid, ListItem, List } from "@mui/material"; +import { + Paper, + Table, + TableBody, + TableContainer, + TableHead, + TableRow, +} from "@mui/material"; import { ReactElement, useState, useEffect } from "react"; import { SemanticDomainUserCount } from "api/models"; import { getSemanticDomainUserCount } from "backend"; import * as LocalStorage from "backend/localStorage"; -import { ColumnHead, TableCell } from "components/Statistics/TableCells"; +import { Cell, HeadCell } from "components/Statistics/TableCells"; export default function UserStatistics(): ReactElement { const [domainUserCountList, setDomainUserCountList] = useState< @@ -28,33 +35,25 @@ export default function UserStatistics(): ReactElement { } return ( - - - - - - - - - - + + + + + + + + + + {domainUserCountList.map((t) => ( - + + + + + ))} - - - - ); -} - -function TableRow(props: { counts: SemanticDomainUserCount }): ReactElement { - return ( - - - - - - - + +
+
); } diff --git a/src/components/Statistics/tests/DomainStatistics.test.tsx b/src/components/Statistics/tests/DomainStatistics.test.tsx index 1cb640243a..7976e67cee 100644 --- a/src/components/Statistics/tests/DomainStatistics.test.tsx +++ b/src/components/Statistics/tests/DomainStatistics.test.tsx @@ -43,8 +43,8 @@ describe("DomainStatistics", () => { expect(mockGetProjectId).toHaveBeenCalled(); }); - test("all list items are present", async () => { - const listItems = screen.queryAllByRole("listitem"); - expect(listItems.length).toEqual(mockSemanticDomainCountArray.length); + test("all rows are present", async () => { + const expectedRowCount = mockSemanticDomainCountArray.length + 1; // +1 for the header row + expect(screen.queryAllByRole("row")).toHaveLength(expectedRowCount); }); }); diff --git a/src/components/Statistics/tests/Statistics.test.tsx b/src/components/Statistics/tests/Statistics.test.tsx index 741a9739c9..9f983ca06a 100644 --- a/src/components/Statistics/tests/Statistics.test.tsx +++ b/src/components/Statistics/tests/Statistics.test.tsx @@ -35,7 +35,7 @@ beforeEach(async () => { render( - {" "} + ); diff --git a/src/components/Statistics/tests/UserStatistics.test.tsx b/src/components/Statistics/tests/UserStatistics.test.tsx index 3f30f1f360..fcff5be8ff 100644 --- a/src/components/Statistics/tests/UserStatistics.test.tsx +++ b/src/components/Statistics/tests/UserStatistics.test.tsx @@ -42,8 +42,8 @@ describe("UserStatistics", () => { expect(mockGetProjectId).toHaveBeenCalled(); }); - test("all list items are present", async () => { - const listItems = screen.queryAllByRole("listitem"); - expect(listItems.length).toEqual(mockSemanticDomainUserCountArray.length); + test("all rows are present", async () => { + const expectedRowCount = mockSemanticDomainUserCountArray.length + 1; // +1 for the header row + expect(screen.queryAllByRole("row")).toHaveLength(expectedRowCount); }); });