From 79e600eb8e4b3cd50d08ba953acf9c761c3555b4 Mon Sep 17 00:00:00 2001 From: Thomas Steenbergen Date: Thu, 30 Jan 2025 01:27:58 +0100 Subject: [PATCH] feat(web-app-template): Adhere to severe thresholds 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 --- .../src/components/IssuesTable.jsx | 21 +++++++++- .../src/components/ResultsSummary.jsx | 2 + .../src/components/RuleViolationsTable.jsx | 39 +++++++++++++------ 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/plugins/reporters/web-app-template/src/components/IssuesTable.jsx b/plugins/reporters/web-app-template/src/components/IssuesTable.jsx index 300579facb86c..4ad0a8049a62b 100644 --- a/plugins/reporters/web-app-template/src/components/IssuesTable.jsx +++ b/plugins/reporters/web-app-template/src/components/IssuesTable.jsx @@ -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( () => { @@ -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 @@ -77,7 +94,7 @@ const IssuesTable = ({ webAppOrtIssues = [], showExcludesColumn = true }) => { message: [], packageId: [], source: [], - severityIndex: [] + severityIndex: defaultSeverityIndex }); // State variable for sorting table columns diff --git a/plugins/reporters/web-app-template/src/components/ResultsSummary.jsx b/plugins/reporters/web-app-template/src/components/ResultsSummary.jsx index 0c669e8971e21..e2232d4f8901e 100644 --- a/plugins/reporters/web-app-template/src/components/ResultsSummary.jsx +++ b/plugins/reporters/web-app-template/src/components/ResultsSummary.jsx @@ -418,6 +418,7 @@ const ResultsSummary = ({ webAppOrtResult }) => { ) }, @@ -439,6 +440,7 @@ const ResultsSummary = ({ webAppOrtResult }) => { ) }, diff --git a/plugins/reporters/web-app-template/src/components/RuleViolationsTable.jsx b/plugins/reporters/web-app-template/src/components/RuleViolationsTable.jsx index 01b8c29b9a5d8..ae5c894925b4d 100644 --- a/plugins/reporters/web-app-template/src/components/RuleViolationsTable.jsx +++ b/plugins/reporters/web-app-template/src/components/RuleViolationsTable.jsx @@ -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( () => { @@ -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 @@ -77,7 +94,7 @@ const RuleViolationsTable = ({ webAppRuleViolations = [], showExcludesColumn = t message: [], packageId: [], rule: [], - severityIndex: [] + severityIndex: defaultSeverityIndex }); // State variable for sorting table columns @@ -130,17 +147,17 @@ const RuleViolationsTable = ({ webAppRuleViolations = [], showExcludesColumn = t if (webAppPackage) { return webAppPackage.isExcluded ? ( - - - - - + + + + + ) : ( - + ); }