Skip to content
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

fix: dashboard - avoid rendering barchart when no sboms are available #269

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
226 changes: 122 additions & 104 deletions client/src/app/pages/home/components/MonitoringSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
DescriptionListDescription,
DescriptionListGroup,
DescriptionListTerm,
EmptyState,
EmptyStateBody,
EmptyStateHeader,
EmptyStateVariant,
Grid,
GridItem,
Stack,
Expand Down Expand Up @@ -116,117 +120,131 @@ export const MonitoringSection: React.FC = () => {
</TextContent>
</StackItem>
<StackItem>
<div style={{ height: 320 }}>
<Chart
ariaDesc="SBOM summary status"
domainPadding={{ x: [30, 25] }}
legendData={LEGENDS.map((legend) => {
const severity = severityList[legend.severity];
return { name: severity.name };
})}
legendPosition="bottom-left"
height={375}
name="sbom-summary-status"
padding={{
bottom: 75,
left: 330,
right: 50,
top: 50,
}}
themeColor={ChartThemeColor.multiOrdered}
width={700}
legendComponent={
<ChartLegend
y={10}
x={300}
{barchartSboms.length > 0 ? (
<div style={{ height: 320 }}>
<Chart
ariaDesc="SBOM summary status"
domainPadding={{ x: [30, 25] }}
legendData={LEGENDS.map((legend) => {
const severity = severityList[legend.severity];
return { name: severity.name };
})}
legendPosition="bottom-left"
height={375}
name="sbom-summary-status"
padding={{
bottom: 75,
left: 330,
right: 50,
top: 50,
}}
themeColor={ChartThemeColor.multiOrdered}
width={700}
legendComponent={
<ChartLegend
y={10}
x={300}
colorScale={LEGENDS.map((legend) => {
const severity = severityList[legend.severity];
return severity.color.value;
})}
/>
}
>
<ChartAxis
label="Products"
axisLabelComponent={
<ChartLabel dx={0} x={15} y={140} />
}
tickLabelComponent={
<ChartLabel
className="pf-v5-c-button pf-m-link pf-m-inline"
style={[{ fill: "#0066cc" }]}
events={{
onClick: (event) => {
const sbomName = (event.target as any)
.innerHTML as string | null;
const sbom = barchartSboms.find(
(item, index) => {
return (
generateSbomBarName(item, index) ===
sbomName
);
}
);
if (sbom) {
navigate(`/sboms/${sbom.id}`);
}
},
}}
/>
}
/>
<ChartAxis
dependentAxis
showGrid
tickValues={
showTickValues
? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
: undefined
}
label="Vulnerabilities by Severity"
fixLabelOverlap={true}
/>
<ChartStack
horizontal
colorScale={LEGENDS.map((legend) => {
const severity = severityList[legend.severity];
return severity.color.value;
})}
/>
}
>
<ChartAxis
label="Products"
axisLabelComponent={
<ChartLabel dx={0} x={15} y={140} />
}
tickLabelComponent={
<ChartLabel
className="pf-v5-c-button pf-m-link pf-m-inline"
style={[{ fill: "#0066cc" }]}
events={{
onClick: (event) => {
const sbomName = (event.target as any)
.innerHTML as string | null;
const sbom = barchartSboms.find(
(item, index) => {
return (
generateSbomBarName(item, index) ===
sbomName
);
}
);
if (sbom) {
navigate(`/sboms/${sbom.id}`);
>
{LEGENDS.map((legend) => {
const severityData = severityList[legend.severity];
return (
<ChartBar
key={legend.severity}
labelComponent={
<ChartTooltip constrainToVisibleArea />
}
},
}}
/>
}
/>
<ChartAxis
dependentAxis
showGrid
tickValues={
showTickValues
? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
: undefined
}
label="Vulnerabilities by Severity"
fixLabelOverlap={true}
/>
<ChartStack
horizontal
colorScale={LEGENDS.map((legend) => {
const severity = severityList[legend.severity];
return severity.color.value;
})}
>
{LEGENDS.map((legend) => {
const severityData = severityList[legend.severity];
return (
<ChartBar
key={legend.severity}
labelComponent={
<ChartTooltip constrainToVisibleArea />
}
data={barchartSbomsVulnerabilities.map(
(
{
summary: {
vulnerabilityStatus: { affected },
data={barchartSbomsVulnerabilities.map(
(
{
summary: {
vulnerabilityStatus: { affected },
},
},
},
index
) => {
const sbom = barchartSboms[index];
index
) => {
const sbom = barchartSboms[index];

const severity = legend.severity;
const count = affected.severities[severity];
return {
x: generateSbomBarName(sbom, index),
y: count,
label: `${severityData.name}: ${count}`,
};
}
)}
/>
);
})}
</ChartStack>
</Chart>
</div>
const severity = legend.severity;
const count = affected.severities[severity];
return {
x: generateSbomBarName(sbom, index),
y: count,
label: `${severityData.name}: ${count}`,
};
}
)}
/>
);
})}
</ChartStack>
</Chart>
</div>
) : (
<EmptyState variant={EmptyStateVariant.xs}>
<EmptyStateHeader
titleText="There is nothing here yet"
headingLevel="h4"
/>
<EmptyStateBody>
You can get started by uploading an SBOM. Once your
SBOMs are uploaded come back to this page to see your
overview.
</EmptyStateBody>
</EmptyState>
)}
</StackItem>
</Stack>
</LoadingWrapper>
Expand Down
Loading