Skip to content

Commit

Permalink
Refactored if statement for N/A values
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkishpolicy committed Dec 30, 2024
1 parent cbd704d commit 1afe5c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
12 changes: 4 additions & 8 deletions frontend/src/pages/Risk/VulnerabilityBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,7 @@ const VulnerabilityBarChart = (props: {
if (severityLevels.includes(d.id)) {
return d;
}
if (
d.id === null ||
d.id === undefined ||
d.id === 'Null' ||
d.id === 'N/a' ||
d.id === 'undefined' ||
d.id === ''
) {
if (!d.id || ['Null', 'N/a', 'undefined', ''].includes(d.id)) {
return { id: 'N/A', value: d.value };
} else {
return { id: 'Other', value: d.value };
Expand All @@ -125,6 +118,9 @@ const VulnerabilityBarChart = (props: {
return order.indexOf(a.id) - order.indexOf(b.id);
});

console.log('severities', data);
console.log('groupedData', groupedData);

useEffect(() => {
const label =
`${title} bar chart. ` +
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/pages/Vulnerabilities/Vulnerabilities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,14 @@ export const Vulnerabilities: React.FC<{ groupBy?: string }> = ({
'Other'
];

// To-Do: Create array(s) to handle permutations of null and N/A values

const formatSeverity = (severity?: any) => {
const titleCaseSev = titleCase(severity);
if (severityLevels.includes(titleCaseSev)) {
return titleCaseSev;
}

if (
titleCaseSev === null ||
titleCaseSev === undefined ||
titleCaseSev === 'Null' ||
titleCaseSev === 'N/a' ||
titleCaseSev === 'undefined' ||
titleCaseSev === ''
!titleCaseSev ||
['Null', 'N/a', 'undefined', ''].includes(titleCaseSev)
) {
return 'N/A';
} else {
Expand Down Expand Up @@ -369,6 +362,10 @@ export const Vulnerabilities: React.FC<{ groupBy?: string }> = ({
state: vuln.state + (vuln.substate ? ` (${vuln.substate})` : '')
};
});
const vulnSev = vulnerabilities.map((vuln) => vuln.severity);
console.log('vulnSev', vulnSev);
const vulRowsSev = vulRows.map((vuln) => vuln.severity);
console.log('vulRows', vulRowsSev);

const vulCols: GridColDef[] = [
{
Expand Down

0 comments on commit 1afe5c3

Please sign in to comment.