Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 84 additions & 58 deletions client/src/app/components/AIModelDetails/AIModelDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import type React from "react";
import React from "react";

import {
Alert,
Button,
Card,
CardBody,
CardTitle,
Content,
DescriptionList,
DescriptionListDescription,
DescriptionListGroup,
DescriptionListTerm,
Label,
Stack,
StackItem,
Tab,
Tabs,
TabTitleText,
} from "@patternfly/react-core";
import ExternalLinkAltIcon from "@patternfly/react-icons/dist/esm/icons/external-link-alt-icon";

import type { SbomModel } from "@app/client";

import { getModelProperties } from "./utils";
import { getModelProperties, parseSafetyRisks } from "./utils";

export interface ExternalReference {
type: string;
Expand All @@ -40,21 +42,23 @@ interface IAIModelDetailsProps {
}

export const AIModelDetails: React.FC<IAIModelDetailsProps> = ({ model }) => {
const [activeTabKey, setActiveTabKey] = React.useState("overview");
const props = getModelProperties(model.properties);
const externalRefs = parseExternalReferences(props.external_references);
const safetyRisks = parseSafetyRisks(props.safetyRiskAssessment);

return (
<Stack hasGutter>
<StackItem>
<Card isCompact>
<CardTitle>Identity & Purpose</CardTitle>
<CardBody>
<DescriptionList
isCompact
columnModifier={{
default: "2Col",
}}
>
<Tabs
isFilled
activeKey={activeTabKey}
onSelect={(_e, key) => setActiveTabKey(key as string)}
aria-label="AI model details tabs"
role="region"
>
<Tab eventKey="overview" title={<TabTitleText>Overview</TabTitleText>}>
<Stack hasGutter style={{ paddingTop: 16 }}>
<StackItem>
<DescriptionList isCompact columnModifier={{ default: "2Col" }}>
{props.typeOfModel && (
<DescriptionListGroup>
<DescriptionListTerm>Model type</DescriptionListTerm>
Expand Down Expand Up @@ -88,20 +92,41 @@ export const AIModelDetails: React.FC<IAIModelDetailsProps> = ({ model }) => {
</DescriptionListGroup>
)}
</DescriptionList>
</CardBody>
</Card>
</StackItem>
</StackItem>
{safetyRisks.length > 0 && (
<StackItem>
<Alert variant="warning" isInline title="Safety Risk Assessment">
<Stack hasGutter>
{safetyRisks.map((risk, index) => (
<StackItem key={index}>
Comment on lines +100 to +101

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Avoid using the array index as the React key for safety risks.

Using the array index as a key can cause incorrect component reuse when items are reordered, inserted, or removed. Prefer a stable unique key such as risk.name, or a composite like ${risk.name}-${index} if needed for uniqueness.

Suggested change
{safetyRisks.map((risk, index) => (
<StackItem key={index}>
{safetyRisks.map((risk, index) => (
<StackItem key={`${risk.name}-${index}`}>

<strong>{risk.name}</strong>
{risk.mitigationStrategy && (
<Content component="p">
Mitigation: {risk.mitigationStrategy}
</Content>
)}
</StackItem>
))}
</Stack>
</Alert>
</StackItem>
)}
{props.limitation && (
<StackItem>
<Content component="h4">Limitations</Content>
<Content component="p">{props.limitation}</Content>
</StackItem>
)}
</Stack>
</Tab>

<StackItem>
<Card isCompact>
<CardTitle>SBOM Metadata</CardTitle>
<CardBody>
<DescriptionList
isCompact
columnModifier={{
default: "2Col",
}}
>
<Tab
eventKey="metadata"
title={<TabTitleText>SBOM Metadata</TabTitleText>}
>
<Stack hasGutter style={{ paddingTop: 16 }}>
<StackItem>
<DescriptionList isCompact columnModifier={{ default: "2Col" }}>
{props.bomFormat && (
<DescriptionListGroup>
<DescriptionListTerm>Format</DescriptionListTerm>
Expand Down Expand Up @@ -135,15 +160,17 @@ export const AIModelDetails: React.FC<IAIModelDetailsProps> = ({ model }) => {
</DescriptionListGroup>
)}
</DescriptionList>
</CardBody>
</Card>
</StackItem>
</StackItem>
</Stack>
</Tab>

{externalRefs.length > 0 && (
<StackItem>
<Card isCompact>
<CardTitle>External References</CardTitle>
<CardBody>
<Tab
eventKey="references"
title={<TabTitleText>References</TabTitleText>}
>
<Stack hasGutter style={{ paddingTop: 16 }}>
{externalRefs.length > 0 && (
<StackItem>
<DescriptionList isCompact>
{externalRefs.map((ref) => (
<DescriptionListGroup key={`${ref.type}-${ref.url}`}>
Expand All @@ -160,26 +187,25 @@ export const AIModelDetails: React.FC<IAIModelDetailsProps> = ({ model }) => {
</DescriptionListGroup>
))}
</DescriptionList>
</CardBody>
</Card>
</StackItem>
)}

{props.downloadLocation && (
<StackItem>
<Button
variant="secondary"
component="a"
href={props.downloadLocation}
target="_blank"
rel="noopener noreferrer"
icon={<ExternalLinkAltIcon />}
iconPosition="end"
>
Download
</Button>
</StackItem>
)}
</Stack>
</StackItem>
)}
{props.downloadLocation && (
<StackItem>
<Button
variant="secondary"
component="a"
href={props.downloadLocation}
target="_blank"
rel="noopener noreferrer"
icon={<ExternalLinkAltIcon />}
iconPosition="end"
>
Download
</Button>
</StackItem>
)}
</Stack>
</Tab>
</Tabs>
);
};
15 changes: 14 additions & 1 deletion client/src/app/components/AIModelDetails/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export interface SafetyRisk {
name: string;
mitigationStrategy?: string;
}

export interface ModelProperties {
version?: string;
licenses?: string;
Expand All @@ -10,7 +15,7 @@ export interface ModelProperties {
downloadLocation?: string;
external_references?: string;
limitation?: string;
safetyRiskAssessment?: string;
safetyRiskAssessment?: string | SafetyRisk[];
}

export const getModelProperties = (properties: unknown): ModelProperties => {
Expand All @@ -19,3 +24,11 @@ export const getModelProperties = (properties: unknown): ModelProperties => {
}
return {};
};

export const parseSafetyRisks = (
value?: string | SafetyRisk[],
): SafetyRisk[] => {
if (!value) return [];
if (Array.isArray(value)) return value;
return [{ name: value }];
};