Skip to content

Commit

Permalink
feat(web-app-template): Adhere to severe thresholds
Browse files Browse the repository at this point in the history
By default, display only those entries in the rule violations
and issues tables that are equal to or exceed the
`severeIssueThreshold` or `severeRuleViolationThreshold` set
in ORT's configuration.

Fixes #4453.

Signed-off-by: Thomas Steenbergen <[email protected]>
  • Loading branch information
tsteenbe committed Jan 30, 2025
1 parent ff3d741 commit 874b212
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
21 changes: 19 additions & 2 deletions plugins/reporters/web-app-template/src/components/IssuesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ import SeverityTag from './SeverityTag';
import { getColumnSearchProps } from './Shared';

// Generates the HTML to display issues as a table
const IssuesTable = ({ webAppOrtIssues = [], showExcludesColumn = true }) => {
const IssuesTable = ({
webAppOrtIssues = [],
showExcludesColumn = true,
severeThreshold
}) => {
// Convert issues as Antd only accepts vanilla objects as input
const issues = useMemo(
() => {
Expand All @@ -66,6 +70,19 @@ const IssuesTable = ({ webAppOrtIssues = [], showExcludesColumn = true }) => {
[]
);

let defaultSeverityIndex = [];
switch (severeThreshold) {
case 'ERROR':
defaultSeverityIndex = [0];
break;
case 'WARNING':
defaultSeverityIndex = [0, 1];
break;
case 'HINT':
defaultSeverityIndex = [0, 1, 2];
break;
}

/* === Table state handling === */

// State variable for displaying table in various pages
Expand All @@ -77,7 +94,7 @@ const IssuesTable = ({ webAppOrtIssues = [], showExcludesColumn = true }) => {
message: [],
packageId: [],
source: [],
severityIndex: []
severityIndex: defaultSeverityIndex
});

// State variable for sorting table columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ const ResultsSummary = ({ webAppOrtResult }) => {
<RuleViolationsTable
webAppRuleViolations={webAppOrtResult.ruleViolations}
showExcludesColumn={webAppOrtResult.hasExcludes()}
severeThreshold={webAppOrtResult.severeRuleViolationThreshold}
/>
)
},
Expand All @@ -439,6 +440,7 @@ const ResultsSummary = ({ webAppOrtResult }) => {
<IssuesTable
webAppOrtIssues={webAppOrtResult.issues}
showExcludesColumn={webAppOrtResult.hasExcludes()}
severeThreshold={webAppOrtResult.severeIssueThreshold}
/>
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ import SeverityTag from './SeverityTag';
import { getColumnSearchProps } from './Shared';

// Generates the HTML to display violations as a table
const RuleViolationsTable = ({ webAppRuleViolations = [], showExcludesColumn = true }) => {
const RuleViolationsTable = ({
webAppRuleViolations = [],
showExcludesColumn = true,
severeThreshold
}) => {
// Convert rule violations as Antd only accepts vanilla objects as input
const violations = useMemo(
() => {
Expand All @@ -66,6 +70,19 @@ const RuleViolationsTable = ({ webAppRuleViolations = [], showExcludesColumn = t
[]
);

let defaultSeverityIndex = [];
switch (severeThreshold) {
case 'ERROR':
defaultSeverityIndex = [0];
break;
case 'WARNING':
defaultSeverityIndex = [0, 1];
break;
case 'HINT':
defaultSeverityIndex = [0, 1, 2];
break;
}

/* === Table state handling === */

// State variable for displaying table in various pages
Expand All @@ -77,7 +94,7 @@ const RuleViolationsTable = ({ webAppRuleViolations = [], showExcludesColumn = t
message: [],
packageId: [],
rule: [],
severityIndex: []
severityIndex: defaultSeverityIndex
});

// State variable for sorting table columns
Expand Down Expand Up @@ -130,17 +147,17 @@ const RuleViolationsTable = ({ webAppRuleViolations = [], showExcludesColumn = t
if (webAppPackage) {
return webAppPackage.isExcluded
? (
<span className="ort-excludes">
<Tooltip
placement="right"
title={Array.from(webAppPackage.excludeReasons).join(', ')}
>
<FileExcelOutlined className="ort-excluded" />
</Tooltip>
</span>
<span className="ort-excludes">
<Tooltip
placement="right"
title={Array.from(webAppPackage.excludeReasons).join(', ')}
>
<FileExcelOutlined className="ort-excluded" />
</Tooltip>
</span>
)
: (
<FileAddOutlined />
<FileAddOutlined />
);
}

Expand Down

0 comments on commit 874b212

Please sign in to comment.