Skip to content

Commit f11a552

Browse files
committed
refactor: update severityToColor function to accept an object and adjust usage in components
1 parent e84d3c6 commit f11a552

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

src/lib/components/Vulnerability.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{:else if count === PendingValue}
1919
<Skeleton variant="circle" width={size} height={size} />
2020
{:else if count > 0}
21-
<VulnerabilityBadge text={String(count)} color={severityToColor(severity)} {size} />
21+
<VulnerabilityBadge text={String(count)} color={severityToColor({ severity: severity })} {size} />
2222
{:else}
2323
<code class="check">&check;</code>
2424
{/if}

src/lib/components/VulnerabilityBadges.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{#each categories as category (category)}
3333
<BodyShort
3434
class="vulnerability-count"
35-
style="background-color: {severityToColor(category)}"
35+
style="background-color: {severityToColor({ severity: category })}"
3636
>
3737
{summary[category]}
3838
</BodyShort>

src/lib/components/image/ImageVulnerabilities.svelte

+5-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,11 @@
204204
</Td>
205205
<Td><code>{v.package}</code></Td>
206206
<Td
207-
><code style="color: {severityToColor(v.severity.toLocaleLowerCase(), true)}"
208-
>{v.severity}</code
207+
><code
208+
style="color: {severityToColor({
209+
severity: v.severity.toLocaleLowerCase(),
210+
isText: true
211+
})}">{v.severity}</code
209212
></Td
210213
>
211214
<Td style="text-align: center">

src/lib/utils/vulnerabilities.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
export function severityToColor(severity: string, isText?: boolean): string {
1+
export function severityToColor({
2+
severity,
3+
isText
4+
}: {
5+
severity: string;
6+
isText?: boolean;
7+
}): string {
28
if (isText) {
39
switch (severity) {
410
case 'critical':

src/routes/team/[team]/vulnerabilities/+page.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import CircleProgressBar from '$lib/components/CircleProgressBar.svelte';
99
import SummaryCard from '$lib/components/SummaryCard.svelte';
1010
import Vulnerability from '$lib/components/Vulnerability.svelte';
11-
import WorkloadsWithSbom from '$lib/components/WorkloadsWithSBOM.svelte';
11+
import WorkloadsWithVulnerabilities from '$lib/components/WorkloadsWithVulnerabilities.svelte';
1212
import GraphErrors from '$lib/GraphErrors.svelte';
1313
import { Alert, Heading, HelpText, Select, Skeleton } from '@nais/ds-svelte-community';
1414
import {
@@ -152,7 +152,7 @@
152152
</SummaryCard>
153153
</Card>
154154
<Card columns={12}>
155-
<Heading level="3" size="small" spacing>Workloads with SBOM</Heading>
155+
<Heading level="3" size="medium" spacing>Workloads with vulnerabilities</Heading>
156156

157157
<div class="env-filter">
158158
<Select size="small" hideLabel={true} bind:value={selectedEnvironment} label="Environment">
@@ -168,7 +168,7 @@
168168
{/if}
169169
</Select>
170170
</div>
171-
<WorkloadsWithSbom team={teamSlug} environment={selectedEnvironment} />
171+
<WorkloadsWithVulnerabilities team={teamSlug} environment={selectedEnvironment} />
172172
</Card>
173173
</div>
174174
{/if}

0 commit comments

Comments
 (0)