Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyskoedijk committed Dec 18, 2024
1 parent 91dcd21 commit 874dfb9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
6 changes: 5 additions & 1 deletion ui/components/charts/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface Props {

interface State {
series: MakeOptional<BarSeriesType, 'type'>[];
total: number;
}

export class BarChart extends React.Component<Props, State> {
Expand All @@ -43,6 +44,7 @@ export class BarChart extends React.Component<Props, State> {
stack: d.stack,
...(d.color ? { color: d.color } : {}),
})),
total: props.data.reduce((accX, itemX) => accX + itemX.data.reduce((accY, itemY) => accY + itemY, 0), 0),
};
}

Expand All @@ -53,7 +55,9 @@ export class BarChart extends React.Component<Props, State> {
}

public render(): JSX.Element {
return (
return !this.state.total ? (
<div />
) : (
<div className={'bar-chart flex-column flex-center flex-grow ' + (this.props.className || '')}>
{this.props.title && <h3 className="title">{this.props.title}</h3>}
<MuiBarChart
Expand Down
4 changes: 3 additions & 1 deletion ui/components/charts/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export class PieChart extends React.Component<Props, State> {
}

public render(): JSX.Element {
return (
return !this.state.total ? (
<div />
) : (
<div className={'pie-chart flex-column flex-center flex-grow ' + (this.props.className || '')}>
{this.props.title && <h3 className="title">{this.props.title}</h3>}
<MuiPieChart
Expand Down
34 changes: 18 additions & 16 deletions ui/components/charts/Tile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';

import { IColor } from 'azure-devops-extension-api';
import { Tooltip } from 'azure-devops-ui/TooltipEx';
import { rgbToHex } from 'azure-devops-ui/Utilities/Color';

import './Tile.scss';
Expand Down Expand Up @@ -34,23 +35,24 @@ export class Tile extends React.Component<Props, State> {

public render(): JSX.Element {
return (
<div
className={
'tile text-on-communication-background flex-column flex-center padding-8' + (this.props.className || '')
}
style={{
backgroundColor: this.props.color ? rgbToHex(this.props.color) : undefined,
width: this.props.size || 160,
height: this.props.size || 160,
}}
title={`${this.props.title}: ${this.props.value}`}
>
{this.props.title && <h2 className="title text-ellipsis">{this.props.title}</h2>}
<div className="flex-column flex-center flex-grow">
<div className="value">{this.props.value.substring(0, 5)}</div>
<Tooltip text={`${this.props.title}: ${this.props.value}`}>
<div
className={
'tile text-on-communication-background flex-column flex-center padding-8' + (this.props.className || '')
}
style={{
backgroundColor: this.props.color ? rgbToHex(this.props.color) : undefined,
width: this.props.size || 160,
height: this.props.size || 160,
}}
>
{this.props.title && <h2 className="title text-ellipsis">{this.props.title}</h2>}
<div className="flex-column flex-center flex-grow">
<div className="value">{this.props.value.substring(0, 5)}</div>
</div>
{this.props.subtitle && <div className="subtitle text-ellipsis">{this.props.subtitle}</div>}
</div>
{this.props.subtitle && <div className="subtitle text-ellipsis">{this.props.subtitle}</div>}
</div>
</Tooltip>
);
}
}
4 changes: 3 additions & 1 deletion ui/components/sbom/SpdxSecurityTableCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ function renderAdvisoryCvssCell(
<div className="bolt-table-cell-content flex-row flex-wrap rhythm-horizontal-4">
<span>{tableItem.cvssScore} / 10</span>
<Link
tooltipProps={{ text: 'Learn more about how this score is calculated' }}
tooltipProps={{
text: 'Learn more about the Common Vulnerability Scoring System (CVSS) and how this score was calculated',
}}
className="bolt-table-link bolt-table-link-icon"
href={`https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator?vector=${tableItem.cvssVector}&version=${tableItem.cvssVersion}`}
target="_blank"
Expand Down
22 changes: 0 additions & 22 deletions ui/components/sbom/SpdxSummaryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,3 @@ function reduceAsMap<T, K extends keyof any, M>(
) as [K, number][];
return reduced.sort().map(([k, v]) => mapper(k, v));
}

function summariseAsMap<T, K extends keyof any, V extends keyof any, M>(
array: T[],
keySelector: (item: T) => K | K[],
valueSelector: (item: T) => V,
mapper?: (key: K, value: V) => M,
) {
const summarised = Object.entries(
array.reduce(
(acc, item) => {
const key = keySelector(item);
const keys = Array.isArray(key) ? key : [key];
keys.forEach((k) => {
acc[k] = valueSelector(item);
});
return acc;
},
{} as Record<K, V>,
),
) as [K, V][];
return summarised.sort().map(([k, v]) => (mapper ? mapper(k, v) : { label: k, value: v }));
}

0 comments on commit 874dfb9

Please sign in to comment.