Commit a782146b authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '229645-project-extra-identifiers' into 'master'

Show count of extra identifiers in project dash

See merge request gitlab-org/gitlab!37256
parents 3304ace8 1d0b0975
<script> <script>
import { difference } from 'lodash'; import { difference } from 'lodash';
import { s__, __, sprintf } from '~/locale'; import { s__, __, sprintf } from '~/locale';
import { GlFormCheckbox, GlLink, GlSkeletonLoading, GlTable } from '@gitlab/ui'; import { GlFormCheckbox, GlLink, GlSkeletonLoading, GlSprintf, GlTable } from '@gitlab/ui';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import RemediatedBadge from 'ee/vulnerabilities/components/remediated_badge.vue'; import RemediatedBadge from 'ee/vulnerabilities/components/remediated_badge.vue';
import FiltersProducedNoResults from 'ee/security_dashboard/components/empty_states/filters_produced_no_results.vue'; import FiltersProducedNoResults from 'ee/security_dashboard/components/empty_states/filters_produced_no_results.vue';
...@@ -25,6 +25,7 @@ export default { ...@@ -25,6 +25,7 @@ export default {
GlFormCheckbox, GlFormCheckbox,
GlLink, GlLink,
GlSkeletonLoading, GlSkeletonLoading,
GlSprintf,
GlTable, GlTable,
IssueLink, IssueLink,
LocalStorageSync, LocalStorageSync,
...@@ -195,6 +196,9 @@ export default { ...@@ -195,6 +196,9 @@ export default {
deselectAllVulnerabilities() { deselectAllVulnerabilities() {
this.selectedVulnerabilities = {}; this.selectedVulnerabilities = {};
}, },
extraIdentifierCount(identifiers) {
return identifiers?.length - 1;
},
primaryIdentifier(identifiers) { primaryIdentifier(identifiers) {
return getPrimaryIdentifier(identifiers, 'externalType'); return getPrimaryIdentifier(identifiers, 'externalType');
}, },
...@@ -210,6 +214,9 @@ export default { ...@@ -210,6 +214,9 @@ export default {
return acc; return acc;
}, {}); }, {});
}, },
shouldShowExtraIdentifierCount(identifiers) {
return identifiers?.length > 1;
},
shouldShowVulnerabilityPath(item) { shouldShowVulnerabilityPath(item) {
return Boolean(item.location.image || item.location.file); return Boolean(item.location.image || item.location.file);
}, },
...@@ -333,9 +340,20 @@ export default { ...@@ -333,9 +340,20 @@ export default {
</template> </template>
<template #cell(identifier)="{ item }"> <template #cell(identifier)="{ item }">
<span data-testid="vulnerability-identifier"> <div data-testid="vulnerability-identifier">
{{ primaryIdentifier(item.identifiers) }} {{ primaryIdentifier(item.identifiers) }}
</span> </div>
<div
v-if="shouldShowExtraIdentifierCount(item.identifiers)"
data-testid="vulnerability-more-identifiers"
class="gl-text-gray-500"
>
<gl-sprintf :message="__('+ %{count} more')">
<template #count>
{{ extraIdentifierCount(item.identifiers) }}
</template>
</gl-sprintf>
</div>
</template> </template>
<template #cell(reportType)="{ item }"> <template #cell(reportType)="{ item }">
......
---
title: Show count of extra identifiers in project dashboard
merge_request: 37256
author:
type: changed
...@@ -51,6 +51,7 @@ export const generateVulnerabilities = () => [ ...@@ -51,6 +51,7 @@ export const generateVulnerabilities = () => [
}, },
{ {
id: 'id_2', id: 'id_2',
identifiers: [],
title: 'Vulnerability 2', title: 'Vulnerability 2',
severity: 'high', severity: 'high',
state: 'opened', state: 'opened',
......
...@@ -11,6 +11,7 @@ import VulnerabilityList, { ...@@ -11,6 +11,7 @@ import VulnerabilityList, {
import FiltersProducedNoResults from 'ee/security_dashboard/components/empty_states/filters_produced_no_results.vue'; import FiltersProducedNoResults from 'ee/security_dashboard/components/empty_states/filters_produced_no_results.vue';
import DashboardHasNoVulnerabilities from 'ee/security_dashboard/components/empty_states/dashboard_has_no_vulnerabilities.vue'; import DashboardHasNoVulnerabilities from 'ee/security_dashboard/components/empty_states/dashboard_has_no_vulnerabilities.vue';
import { generateVulnerabilities, vulnerabilities } from './mock_data'; import { generateVulnerabilities, vulnerabilities } from './mock_data';
import { trimText } from 'helpers/text_helper';
describe('Vulnerability list component', () => { describe('Vulnerability list component', () => {
useLocalStorageSpy(); useLocalStorageSpy();
...@@ -163,9 +164,12 @@ describe('Vulnerability list component', () => { ...@@ -163,9 +164,12 @@ describe('Vulnerability list component', () => {
expect(cellText).not.toContain('(line: '); expect(cellText).not.toContain('(line: ');
}); });
it('should not display the vulnerability identifier', () => { it('should not display the vulnerability identifier cell', () => {
const cell = findDataCell('vulnerability-identifier'); const identifier = findDataCell('vulnerability-identifier');
expect(cell.exists()).toBe(false); expect(identifier.exists()).toBe(false);
const extraIdentifierCount = findDataCell('vulnerability-more-identifiers');
expect(extraIdentifierCount.exists()).toBe(false);
}); });
it('should not display the vulnerability report type', () => { it('should not display the vulnerability report type', () => {
...@@ -208,11 +212,18 @@ describe('Vulnerability list component', () => { ...@@ -208,11 +212,18 @@ describe('Vulnerability list component', () => {
expect(cellText).toEqual(location.file); expect(cellText).toEqual(location.file);
}); });
it('should correctly render the identifier', () => { it('should correctly render the identifier cell', () => {
const cells = findDataCells('vulnerability-identifier'); const identifiers = findDataCells('vulnerability-identifier');
const extraIdentifierCounts = findDataCells('vulnerability-more-identifiers');
const firstIdentifiers = newVulnerabilities[0].identifiers;
expect(identifiers.at(0).text()).toBe(firstIdentifiers[0].name);
expect(trimText(extraIdentifierCounts.at(0).text())).toContain(
`${firstIdentifiers.length - 1} more`,
);
expect(cells.at(0).text()).toBe(newVulnerabilities[0].identifiers[0].name); expect(identifiers.at(1).text()).toBe(newVulnerabilities[1].identifiers[0].name);
expect(cells.at(1).text()).toBe(newVulnerabilities[1].identifiers[0].name); expect(extraIdentifierCounts).toHaveLength(1);
}); });
it('should display the vulnerability report type', () => { it('should display the vulnerability report type', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment