Skip to content

Commit

Permalink
Merge pull request #65 from zythosec/readable-analysis-column
Browse files Browse the repository at this point in the history
Adds language specific analysis state values in tables
  • Loading branch information
stevespringett authored Aug 2, 2021
2 parents 6d75b38 + 7742d57 commit b272626
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
25 changes: 25 additions & 0 deletions src/shared/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ $common.formatAnalyzerLabel = function formatAnalyzerLabel(analyzer, vulnId, alt
return `<span class="label label-source label-analyzer" style="white-space:nowrap;">${analyzerLabel}</span>`;
};

/**
*
* @param {*} i18n - VueI18n instance with $t translate function available
* @returns a specialized label for an analysis state (NOT_SET, APPROVED, REJECTED, etc).
* It must have a corresponding entry in the locales files (e.g. src/locales/en.json)
* (not_set, approved, rejected, etc.)
*/
$common.makeAnalysisStateLabelFormatter = (i18n) => {
return function (value) {
switch (value) {
case 'NOT_SET':
case 'APPROVED':
case 'REJECTED':
case 'EXPLOITABLE':
case 'IN_TRIAGE':
case 'FALSE_POSITIVE':
case 'NOT_AFFECTED':
return i18n.$t(`message.${value.toLowerCase()}`)
default:
return null;
}
}
};

/**
* Given a UNIX timestamp, this function will return a formatted date.
* i.e. 15 Jan 2017
Expand Down Expand Up @@ -216,6 +240,7 @@ module.exports = {
formatViolationStateLabel: $common.formatViolationStateLabel,
formatCweLabel: $common.formatCweLabel,
formatAnalyzerLabel: $common.formatAnalyzerLabel,
makeAnalysisStateLabelFormatter: $common.makeAnalysisStateLabelFormatter,
formatTimestamp: $common.formatTimestamp,
concatenateComponentName: $common.concatenateComponentName,
valueWithDefault: $common.valueWithDefault,
Expand Down
4 changes: 1 addition & 3 deletions src/views/portfolio/projects/ComponentVulnerabilities.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@
sortable: false,
class: "tight",
visible: false,
formatter(value, row, index) {
return xssFilters.inHTMLData(common.valueWithDefault(value, ""));
}
formatter: common.makeAnalysisStateLabelFormatter(this),
},
{
title: this.$t('message.suppressed'),
Expand Down
6 changes: 2 additions & 4 deletions src/views/portfolio/projects/ProjectFindings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import bootstrapTableMixin from "../../../mixins/bootstrapTableMixin";
import xssFilters from "xss-filters";
import i18n from "../../../i18n";
import BootstrapToggle from 'vue-bootstrap-toggle'
import BootstrapToggle from 'vue-bootstrap-toggle';
export default {
props: {
Expand Down Expand Up @@ -121,9 +121,7 @@
title: this.$t('message.analysis'),
field: "analysis.state",
sortable: true,
formatter(value, row, index) {
return xssFilters.inHTMLData(common.valueWithDefault(value, ""));
}
formatter: common.makeAnalysisStateLabelFormatter(this),
},
{
title: this.$t('message.suppressed'),
Expand Down
4 changes: 1 addition & 3 deletions src/views/portfolio/projects/ProjectPolicyViolations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ export default {
title: this.$t('message.analysis'),
field: "analysis.analysisState",
sortable: false,
formatter(value, row, index) {
return xssFilters.inHTMLData(common.valueWithDefault(value, ""));
}
formatter: common.makeAnalysisStateLabelFormatter(this),
},
{
title: this.$t('message.suppressed'),
Expand Down

0 comments on commit b272626

Please sign in to comment.