diff --git a/src/shared/common.js b/src/shared/common.js index 49b74ed98..8c1f13378 100644 --- a/src/shared/common.js +++ b/src/shared/common.js @@ -117,6 +117,30 @@ $common.formatAnalyzerLabel = function formatAnalyzerLabel(analyzer, vulnId, alt return `${analyzerLabel}`; }; +/** + * + * @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 @@ -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, diff --git a/src/views/portfolio/projects/ComponentVulnerabilities.vue b/src/views/portfolio/projects/ComponentVulnerabilities.vue index fb9528245..bbc7524b2 100644 --- a/src/views/portfolio/projects/ComponentVulnerabilities.vue +++ b/src/views/portfolio/projects/ComponentVulnerabilities.vue @@ -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'), diff --git a/src/views/portfolio/projects/ProjectFindings.vue b/src/views/portfolio/projects/ProjectFindings.vue index ff18f1a6a..1b4af3830 100644 --- a/src/views/portfolio/projects/ProjectFindings.vue +++ b/src/views/portfolio/projects/ProjectFindings.vue @@ -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: { @@ -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'), diff --git a/src/views/portfolio/projects/ProjectPolicyViolations.vue b/src/views/portfolio/projects/ProjectPolicyViolations.vue index 084d89bb2..5d13ac1ba 100644 --- a/src/views/portfolio/projects/ProjectPolicyViolations.vue +++ b/src/views/portfolio/projects/ProjectPolicyViolations.vue @@ -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'),