Skip to content

Commit b272626

Browse files
Merge pull request #65 from zythosec/readable-analysis-column
Adds language specific analysis state values in tables
2 parents 6d75b38 + 7742d57 commit b272626

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

src/shared/common.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,30 @@ $common.formatAnalyzerLabel = function formatAnalyzerLabel(analyzer, vulnId, alt
117117
return `<span class="label label-source label-analyzer" style="white-space:nowrap;">${analyzerLabel}</span>`;
118118
};
119119

120+
/**
121+
*
122+
* @param {*} i18n - VueI18n instance with $t translate function available
123+
* @returns a specialized label for an analysis state (NOT_SET, APPROVED, REJECTED, etc).
124+
* It must have a corresponding entry in the locales files (e.g. src/locales/en.json)
125+
* (not_set, approved, rejected, etc.)
126+
*/
127+
$common.makeAnalysisStateLabelFormatter = (i18n) => {
128+
return function (value) {
129+
switch (value) {
130+
case 'NOT_SET':
131+
case 'APPROVED':
132+
case 'REJECTED':
133+
case 'EXPLOITABLE':
134+
case 'IN_TRIAGE':
135+
case 'FALSE_POSITIVE':
136+
case 'NOT_AFFECTED':
137+
return i18n.$t(`message.${value.toLowerCase()}`)
138+
default:
139+
return null;
140+
}
141+
}
142+
};
143+
120144
/**
121145
* Given a UNIX timestamp, this function will return a formatted date.
122146
* i.e. 15 Jan 2017
@@ -216,6 +240,7 @@ module.exports = {
216240
formatViolationStateLabel: $common.formatViolationStateLabel,
217241
formatCweLabel: $common.formatCweLabel,
218242
formatAnalyzerLabel: $common.formatAnalyzerLabel,
243+
makeAnalysisStateLabelFormatter: $common.makeAnalysisStateLabelFormatter,
219244
formatTimestamp: $common.formatTimestamp,
220245
concatenateComponentName: $common.concatenateComponentName,
221246
valueWithDefault: $common.valueWithDefault,

src/views/portfolio/projects/ComponentVulnerabilities.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@
7373
sortable: false,
7474
class: "tight",
7575
visible: false,
76-
formatter(value, row, index) {
77-
return xssFilters.inHTMLData(common.valueWithDefault(value, ""));
78-
}
76+
formatter: common.makeAnalysisStateLabelFormatter(this),
7977
},
8078
{
8179
title: this.$t('message.suppressed'),

src/views/portfolio/projects/ProjectFindings.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import bootstrapTableMixin from "../../../mixins/bootstrapTableMixin";
2525
import xssFilters from "xss-filters";
2626
import i18n from "../../../i18n";
27-
import BootstrapToggle from 'vue-bootstrap-toggle'
27+
import BootstrapToggle from 'vue-bootstrap-toggle';
2828
2929
export default {
3030
props: {
@@ -121,9 +121,7 @@
121121
title: this.$t('message.analysis'),
122122
field: "analysis.state",
123123
sortable: true,
124-
formatter(value, row, index) {
125-
return xssFilters.inHTMLData(common.valueWithDefault(value, ""));
126-
}
124+
formatter: common.makeAnalysisStateLabelFormatter(this),
127125
},
128126
{
129127
title: this.$t('message.suppressed'),

src/views/portfolio/projects/ProjectPolicyViolations.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ export default {
9797
title: this.$t('message.analysis'),
9898
field: "analysis.analysisState",
9999
sortable: false,
100-
formatter(value, row, index) {
101-
return xssFilters.inHTMLData(common.valueWithDefault(value, ""));
102-
}
100+
formatter: common.makeAnalysisStateLabelFormatter(this),
103101
},
104102
{
105103
title: this.$t('message.suppressed'),

0 commit comments

Comments
 (0)