forked from guacsec/trustify-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(risk-assessment): assessment results view and query hooks #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mrizzi
wants to merge
13
commits into
NIST
Choose a base branch
from
JIRAPLAY-1380
base: NIST
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f9bd36a
feat(risk-assessment): add assessment results view and query hooks
mrizzi 810c407
fix(risk-assessment): replace window.location.reload with React Query…
mrizzi abab1dc
fix(risk-assessment): align query hooks and types with backend API
mrizzi a6967ac
fix(risk-assessment): align results view with Figma mockup design
mrizzi 9663c09
fix(risk-assessment): preserve nav active state and button enabled st…
mrizzi f26d59d
fix(risk-assessment): invalidate assessment query after document upload
mrizzi 5c063a7
fix(risk-assessment): use circular step number indicators in wizard nav
mrizzi 3d2b760
fix(risk-assessment): select most recent assessment instead of oldest
mrizzi c2cf0d5
refactor(risk-assessment): per-category content rendering in wizard
mrizzi ec19d80
fix(risk-assessment): use explicit white color for active step number
mrizzi 1c6172e
fix(risk-assessment): format criterion keys as readable labels
mrizzi 2a6436e
fix(risk-assessment): use report endpoint for Download Assessment button
mrizzi 4173995
fix(risk-assessment): display overall completeness percentage instead…
mrizzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
client/src/app/pages/sbom-group-details/components/assessment-results.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import type React from "react"; | ||
|
|
||
| import { | ||
| Button, | ||
| Card, | ||
| CardBody, | ||
| CardTitle, | ||
| Content, | ||
| Flex, | ||
| FlexItem, | ||
| Stack, | ||
| StackItem, | ||
| } from "@patternfly/react-core"; | ||
|
|
||
| import type { | ||
| CategoryResult, | ||
| RiskAssessmentResults, | ||
| } from "@app/queries/risk-assessments"; | ||
| import { useDownloadAssessmentReport } from "@app/queries/risk-assessments"; | ||
|
|
||
| import type { AssessmentCategory } from "./assessment-category-step"; | ||
| import { CriteriaSummaryTable } from "./criteria-summary-table"; | ||
|
|
||
| interface AssessmentCategoryResultsProps { | ||
| /** The assessment ID for document download. */ | ||
| assessmentId: string; | ||
| /** The category definition (key, name, description). */ | ||
| category: AssessmentCategory; | ||
| /** The per-category result data including criteria. */ | ||
| categoryResult: CategoryResult; | ||
| /** The full results for scoring lookup. */ | ||
| overallResults: RiskAssessmentResults; | ||
| onStartNewAssessment: () => void; | ||
| } | ||
|
|
||
| /** Displays per-category score card and criteria summary for a processed category. */ | ||
| export const AssessmentCategoryResults: React.FC< | ||
| AssessmentCategoryResultsProps | ||
| > = ({ | ||
| assessmentId, | ||
| category: _category, | ||
| categoryResult, | ||
| overallResults, | ||
| onStartNewAssessment, | ||
| }) => { | ||
| const { download } = useDownloadAssessmentReport(assessmentId); | ||
|
|
||
| const scorePercent = overallResults.overallScore; | ||
| const riskLevel = overallResults.scoring?.overall.riskLevel; | ||
|
|
||
| return ( | ||
| <Stack hasGutter> | ||
| <StackItem> | ||
| <Card> | ||
| <CardTitle>Overall Score</CardTitle> | ||
| <CardBody> | ||
| <Stack hasGutter> | ||
| <StackItem> | ||
| <Content component="p"> | ||
| <span | ||
| style={{ | ||
| fontSize: "var(--pf-t--global--font--size--2xl)", | ||
| fontWeight: "var(--pf-t--global--font--weight--bold)", | ||
| }} | ||
| > | ||
| {scorePercent != null | ||
| ? `${Math.round(scorePercent)}%` | ||
| : "\u2014"} | ||
| </span> | ||
| {riskLevel && ( | ||
| <span | ||
| style={{ | ||
| marginLeft: "var(--pf-t--global--spacer--sm)", | ||
| }} | ||
| > | ||
| ({riskLevel}) | ||
| </span> | ||
| )} | ||
| </Content> | ||
| </StackItem> | ||
| <StackItem> | ||
| <Flex gap={{ default: "gapSm" }}> | ||
| <FlexItem> | ||
| <Button variant="secondary" onClick={onStartNewAssessment}> | ||
| Start New Assessment | ||
| </Button> | ||
| </FlexItem> | ||
| <FlexItem> | ||
| <Button variant="primary" onClick={download}> | ||
| Download Assessment | ||
| </Button> | ||
| </FlexItem> | ||
| </Flex> | ||
| </StackItem> | ||
| </Stack> | ||
| </CardBody> | ||
| </Card> | ||
| </StackItem> | ||
| {categoryResult.criteria.length > 0 && ( | ||
| <StackItem> | ||
| <Card> | ||
| <CardTitle>Criteria Summary</CardTitle> | ||
| <CardBody> | ||
| <CriteriaSummaryTable criteria={categoryResult.criteria} /> | ||
| </CardBody> | ||
| </Card> | ||
| </StackItem> | ||
| )} | ||
| </Stack> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
client/src/app/pages/sbom-group-details/components/criteria-summary-table.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import type React from "react"; | ||
|
|
||
| import { Flex, FlexItem, Label } from "@patternfly/react-core"; | ||
| import CheckCircleIcon from "@patternfly/react-icons/dist/esm/icons/check-circle-icon"; | ||
| import ExclamationCircleIcon from "@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon"; | ||
| import ExclamationTriangleIcon from "@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon"; | ||
| import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table"; | ||
|
|
||
| import type { CriterionResult } from "@app/queries/risk-assessments"; | ||
|
|
||
| interface CriteriaSummaryTableProps { | ||
| criteria: CriterionResult[]; | ||
| } | ||
|
|
||
| /** Format a snake_case criterion key into a readable label. */ | ||
| const formatCriterionLabel = (key: string) => { | ||
| return key.replace(/_/g, " ").replace(/^\w/, (c) => c.toUpperCase()); | ||
| }; | ||
|
|
||
| /** Map a completeness string to a PatternFly Label color. */ | ||
| const completenessColor = (value: string) => { | ||
| switch (value) { | ||
| case "complete": | ||
| return "green"; | ||
| case "partial": | ||
| return "blue"; | ||
| case "missing": | ||
| return "yellow"; | ||
| default: | ||
| return "grey"; | ||
| } | ||
| }; | ||
|
|
||
| /** Render a risk level with an appropriate status icon. */ | ||
| const RiskLevelDisplay: React.FC<{ value: string }> = ({ value }) => { | ||
| const lower = value.toLowerCase(); | ||
|
|
||
| let icon: React.ReactNode; | ||
| if (lower === "very high" || lower === "high") { | ||
| icon = ( | ||
| <ExclamationCircleIcon color="var(--pf-t--global--color--status--danger--default)" /> | ||
| ); | ||
| } else if (lower === "moderate") { | ||
| icon = ( | ||
| <ExclamationTriangleIcon color="var(--pf-t--global--color--status--warning--default)" /> | ||
| ); | ||
| } else { | ||
| icon = ( | ||
| <CheckCircleIcon color="var(--pf-t--global--color--status--success--default)" /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Flex | ||
| gap={{ default: "gapSm" }} | ||
| alignItems={{ default: "alignItemsCenter" }} | ||
| flexWrap={{ default: "nowrap" }} | ||
| > | ||
| <FlexItem>{icon}</FlexItem> | ||
| <FlexItem>{formatCriterionLabel(value)}</FlexItem> | ||
| </Flex> | ||
| ); | ||
| }; | ||
|
|
||
| export const CriteriaSummaryTable: React.FC<CriteriaSummaryTableProps> = ({ | ||
| criteria, | ||
| }) => { | ||
| return ( | ||
| <Table aria-label="Criteria summary table" variant="compact"> | ||
| <Thead> | ||
| <Tr> | ||
| <Th>Criterion</Th> | ||
| <Th>Completeness</Th> | ||
| <Th>Risk Level</Th> | ||
| <Th>Score</Th> | ||
| </Tr> | ||
| </Thead> | ||
| <Tbody> | ||
| {criteria.map((item) => ( | ||
| <Tr key={item.id}> | ||
| <Td dataLabel="Criterion"> | ||
| {formatCriterionLabel(item.criterion)} | ||
| </Td> | ||
| <Td dataLabel="Completeness"> | ||
| <Label color={completenessColor(item.completeness)}> | ||
| {formatCriterionLabel(item.completeness)} | ||
| </Label> | ||
| </Td> | ||
| <Td dataLabel="Risk Level"> | ||
| <RiskLevelDisplay value={item.riskLevel} /> | ||
| </Td> | ||
| <Td dataLabel="Score">{item.score}</Td> | ||
| </Tr> | ||
| ))} | ||
| </Tbody> | ||
| </Table> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.