diff --git a/reports/src/ThemeContext.tsx b/reports/src/ThemeContext.tsx index 9c7380f..0a9f1bb 100644 --- a/reports/src/ThemeContext.tsx +++ b/reports/src/ThemeContext.tsx @@ -6,11 +6,13 @@ import { Theme, ThemeProvider, createTheme, + useMediaQuery, } from "@mui/material"; import { PropsWithChildren, createContext, useContext, + useEffect, useMemo, useState, } from "react"; @@ -29,8 +31,15 @@ export const useTheme = () => useContext(ThemeContext); export const CustomThemeProvider = ({ children, }: PropsWithChildren) => { + const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)"); + const [mode, setMode] = useState("light"); + useEffect( + () => setMode(prefersDarkMode ? "dark" : "light"), + [prefersDarkMode] + ); + const theme = useMemo( () => createTheme({ diff --git a/reports/src/capability/CapabilityTable.tsx b/reports/src/capability/CapabilityTable.tsx index 300a315..a8ce5aa 100644 --- a/reports/src/capability/CapabilityTable.tsx +++ b/reports/src/capability/CapabilityTable.tsx @@ -3,29 +3,26 @@ import { Accordion, AccordionDetails, AccordionSummary, - AppBar, Box, Breadcrumbs, Chip, Dialog, DialogContent, - IconButton, Link, - Toolbar, Typography, } from "@mui/material"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; -import Brightness4Icon from "@mui/icons-material/Brightness4"; -import Brightness7Icon from "@mui/icons-material/Brightness7"; import { Capability, Check, Requirement } from "./capabilityTypes"; import { useEffect, useState } from "react"; import { useMatches } from "react-router-dom"; import { ReactNode } from "react"; -import { useTheme } from "../ThemeContext"; +import { Report } from "./capabilityTypes"; +import { CapabilityTableHeader } from "./CapabilityTableHeader"; type CapabilityTableProps = { capability: Capability; + report: Report; }; export const CheckLabel = ({ @@ -212,14 +209,7 @@ export const CapabilityRows = ({ capability }: { capability: Capability }) => { : []; const allRows = [...requirements, ...childTable]; - return [ - - - {capability.name} ({capability.participant_id}) - - , - ...allRows, - ]; + return [...allRows]; }; export const CapabilityDebug = ({ capability }: { capability: Capability }) => { @@ -247,23 +237,16 @@ function CapabilityBreadcrumbs() { return {crumbs}; } -export const CapabilityTable = ({ capability }: CapabilityTableProps) => { - const { colorMode, toggleColorMode } = useTheme(); +export const CapabilityTable = ({ + capability, + report, +}: CapabilityTableProps) => { if (!capability) { return Capability not found; } return ( <> - - - - InterUSS report explorer - - - {colorMode === "dark" ? : } - - - + { - diff --git a/reports/src/capability/CapabilityTableHeader.tsx b/reports/src/capability/CapabilityTableHeader.tsx new file mode 100644 index 0000000..ca5f3b2 --- /dev/null +++ b/reports/src/capability/CapabilityTableHeader.tsx @@ -0,0 +1,96 @@ +import { + AppBar, + Toolbar, + Typography, + FormControl, + InputLabel, + Select, + MenuItem, + IconButton, + SelectChangeEvent, +} from "@mui/material"; +import Brightness4Icon from "@mui/icons-material/Brightness4"; +import Brightness7Icon from "@mui/icons-material/Brightness7"; +import { Capability, Report } from "./capabilityTypes"; +import { useTheme } from "../ThemeContext"; +import { useLocation, useNavigate } from "react-router-dom"; + +type CapabilityTableHeaderProps = { + capability: Capability; + report: Report; +}; + +export const CapabilityTableHeader = ({ + capability, + report, +}: CapabilityTableHeaderProps) => { + const { colorMode, toggleColorMode } = useTheme(); + const location = useLocation(); + const navigate = useNavigate(); + const ussp = parseInt(location.pathname.split("/")[1]) || 0; + + const handleUsspSelect = (event: SelectChangeEvent) => { + console.log(event.target.value); + const id = event.target.value; + navigate(`/${id}`); + }; + return ( + + + + {report.name} - {capability.name} + + ({ + color: theme.palette.primary.contrastText, + bgColor: theme.palette.primary.main, + })} + > + ({ + color: theme.palette.primary.contrastText, + "&.Mui-focused": { + color: theme.palette.primary.contrastText, + }, + })} + > + USSP + + + + + + {colorMode === "dark" ? : } + + + + ); +}; diff --git a/reports/src/capability/capabilityTypes.ts b/reports/src/capability/capabilityTypes.ts index a026b7f..525a900 100644 --- a/reports/src/capability/capabilityTypes.ts +++ b/reports/src/capability/capabilityTypes.ts @@ -5,20 +5,20 @@ export type Check = { scenario: { name: string; docUrl: string; - } + }; case: { name: string; docUrl: string; - } + }; step: { name: string; docUrl: string; - } + }; name: string; - result: CheckResult + result: CheckResult; details: object; // Switch to a JSON path -} +}; export type Requirement = { name: string; @@ -35,4 +35,6 @@ export type Capability = { export type Report = { capability: Capability; + participants?: string[]; + name?: string; }; diff --git a/reports/src/capability/reportNavigation.tsx b/reports/src/capability/reportNavigation.tsx index 87b195d..3f9c178 100644 --- a/reports/src/capability/reportNavigation.tsx +++ b/reports/src/capability/reportNavigation.tsx @@ -2,6 +2,7 @@ import { Link } from "@mui/material"; import { Link as RouterLink, RouteObject } from "react-router-dom"; import { Capability } from "./capabilityTypes"; import { CapabilityTable } from "./CapabilityTable"; +import { Report } from "./capabilityTypes"; export const joinRoutes = (root: string, child: string): string => { const cleanChild = child.replace(/^\/+/g, ""); // remove leading slash @@ -20,12 +21,18 @@ export const joinRoutes = (root: string, child: string): string => { export const getNavFromCapability = ( capability: Capability, + report: Report, path: string = "/", fullPath: string = "/" ): RouteObject[] => { const children = capability.childCapabilities.flatMap((c, i) => - getNavFromCapability(c, `${i}`, joinRoutes(fullPath, i.toString())) + getNavFromCapability( + c, + report, + `${i}`, + joinRoutes(fullPath, i.toString()) + ) ) || []; return [ { @@ -40,7 +47,7 @@ export const getNavFromCapability = ( children: [ { index: true, - element: , + element: , }, ...children, ], diff --git a/reports/src/capability/reportParser.ts b/reports/src/capability/reportParser.ts index 3021b23..6cabd77 100644 --- a/reports/src/capability/reportParser.ts +++ b/reports/src/capability/reportParser.ts @@ -10,7 +10,7 @@ import { ReportsReportTestSuiteActionReport, ReportsReportTestSuiteReport, } from "../types/TestRunReport"; -import {NotImplementedError} from "../utils/Errors"; +import { NotImplementedError } from "../utils/Errors"; import { Capability, Check, @@ -242,6 +242,10 @@ const parseActions = ( const _parseReport = (report: ReportsReportTestSuiteActionReport): Report => { if (report.test_suite) { return { + name: report.test_suite.name, + participants: report.test_suite.capability_evaluations.map( + (c) => c.participant_id + ), capability: { name: "root", childCapabilities: parseActions(report), diff --git a/reports/src/capability/useReport.tsx b/reports/src/capability/useReport.tsx index 091303c..7ed3c07 100644 --- a/reports/src/capability/useReport.tsx +++ b/reports/src/capability/useReport.tsx @@ -22,7 +22,9 @@ export const useReport = ({ }: UseReportProps): UseReportReturn => { const [loading, setLoading] = useState(true); const [error, setError] = useState(); - const [report, setReport] = useState(_report); + const [report, setReport] = useState( + _report + ); useEffect(() => { if (_report) { @@ -35,11 +37,10 @@ export const useReport = ({ try { const res = await fetch(reportUrl); if (res.status === 404) { - throw new Error("Report not found") + throw new Error("Report not found"); } const json = await res.json(); setReport(json as ReportsReportTestRunReport); - } catch (err) { console.error(err); setError(JSON.stringify(err)); @@ -55,8 +56,11 @@ export const useReport = ({ [report] ); const nav = useMemo( - () => (parsedReport ? getNavFromCapability(parsedReport.capability) : []), + () => + parsedReport + ? getNavFromCapability(parsedReport.capability, parsedReport) + : [], [parsedReport] ); - return {loading, error, report, nav}; + return { loading, error, report, nav }; };
Capability Requirement Test Check