Commit a52f1b6f authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '263819-update-severity-counts-after-bulk-update' into 'master'

Refetch count list when vulnerabilities are updated

See merge request gitlab-org/gitlab!56116
parents 4cb4ac66 828a4d18
...@@ -3,6 +3,7 @@ import { GlButton, GlAlert } from '@gitlab/ui'; ...@@ -3,6 +3,7 @@ import { GlButton, GlAlert } from '@gitlab/ui';
import vulnerabilityStateMutations from 'ee/security_dashboard/graphql/mutate_vulnerability_state'; import vulnerabilityStateMutations from 'ee/security_dashboard/graphql/mutate_vulnerability_state';
import { __, s__, n__ } from '~/locale'; import { __, s__, n__ } from '~/locale';
import toast from '~/vue_shared/plugins/global_toast'; import toast from '~/vue_shared/plugins/global_toast';
import eventHub from '../utils/event_hub';
import StatusDropdown from './status_dropdown.vue'; import StatusDropdown from './status_dropdown.vue';
export default { export default {
...@@ -72,6 +73,7 @@ export default { ...@@ -72,6 +73,7 @@ export default {
return Promise.all(promises).then(() => { return Promise.all(promises).then(() => {
if (fulfilledCount > 0) { if (fulfilledCount > 0) {
toast(this.$options.i18n.vulnerabilitiesUpdated(fulfilledCount)); toast(this.$options.i18n.vulnerabilitiesUpdated(fulfilledCount));
eventHub.$emit('vulnerabilities-updated', this);
} }
if (rejected.length > 0) { if (rejected.length > 0) {
......
<script> <script>
import { vulnerabilitiesSeverityCountScopes } from '../constants'; import { vulnerabilitiesSeverityCountScopes } from '../constants';
import vulnerabilitySeveritiesCountQuery from '../graphql/queries/vulnerability_severities_count.query.graphql'; import vulnerabilitySeveritiesCountQuery from '../graphql/queries/vulnerability_severities_count.query.graphql';
import eventHub from '../utils/event_hub';
import VulnerabilityCountListLayout from './vulnerability_count_list_layout.vue'; import VulnerabilityCountListLayout from './vulnerability_count_list_layout.vue';
export default { export default {
...@@ -35,6 +36,11 @@ export default { ...@@ -35,6 +36,11 @@ export default {
return this.$apollo.queries.vulnerabilitiesCount.loading; return this.$apollo.queries.vulnerabilitiesCount.loading;
}, },
}, },
created() {
eventHub.$on('vulnerabilities-updated', () =>
this.$apollo.queries.vulnerabilitiesCount.refetch(),
);
},
apollo: { apollo: {
vulnerabilitiesCount: { vulnerabilitiesCount: {
query: vulnerabilitySeveritiesCountQuery, query: vulnerabilitySeveritiesCountQuery,
......
import createEventHub from '~/helpers/event_hub_factory';
export default createEventHub();
---
title: Refetch count list when vulnerabilities are updated
merge_request: 56116
author:
type: fixed
...@@ -4,6 +4,7 @@ import VueApollo from 'vue-apollo'; ...@@ -4,6 +4,7 @@ import VueApollo from 'vue-apollo';
import SelectionSummary from 'ee/security_dashboard/components/selection_summary.vue'; import SelectionSummary from 'ee/security_dashboard/components/selection_summary.vue';
import StatusDropdown from 'ee/security_dashboard/components/status_dropdown.vue'; import StatusDropdown from 'ee/security_dashboard/components/status_dropdown.vue';
import vulnerabilityStateMutations from 'ee/security_dashboard/graphql/mutate_vulnerability_state'; import vulnerabilityStateMutations from 'ee/security_dashboard/graphql/mutate_vulnerability_state';
import eventHub from 'ee/security_dashboard/utils/event_hub';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import toast from '~/vue_shared/plugins/global_toast'; import toast from '~/vue_shared/plugins/global_toast';
...@@ -184,6 +185,14 @@ describe('Selection Summary component', () => { ...@@ -184,6 +185,14 @@ describe('Selection Summary component', () => {
await submitForm(); await submitForm();
expect(toast).toHaveBeenLastCalledWith('3 vulnerabilities updated'); expect(toast).toHaveBeenLastCalledWith('3 vulnerabilities updated');
}); });
it(`emits an event for the event hub - ${action}`, async () => {
const spy = jest.fn();
eventHub.$on('vulnerabilities-updated', spy);
await submitForm();
expect(spy).toHaveBeenCalled();
});
}); });
}); });
}); });
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import VulnerabilityCountList from 'ee/security_dashboard/components/vulnerability_count_list.vue'; import VulnerabilityCountList from 'ee/security_dashboard/components/vulnerability_count_list.vue';
import VulnerabilityCountListLayout from 'ee/security_dashboard/components/vulnerability_count_list_layout.vue'; import VulnerabilityCountListLayout from 'ee/security_dashboard/components/vulnerability_count_list_layout.vue';
import eventHub from 'ee/security_dashboard/utils/event_hub';
describe('Vulnerabilities count list component', () => { describe('Vulnerabilities count list component', () => {
let wrapper; let wrapper;
let refetchSpy;
const findVulnerabilityLayout = () => wrapper.find(VulnerabilityCountListLayout); const findVulnerabilityLayout = () => wrapper.find(VulnerabilityCountListLayout);
const createWrapper = ({ query = { isLoading: false }, props = { scope: 'project' } } = {}) => { const createWrapper = ({ query = { isLoading: false }, props = { scope: 'project' } } = {}) => {
refetchSpy = jest.fn();
return shallowMount(VulnerabilityCountList, { return shallowMount(VulnerabilityCountList, {
propsData: props, propsData: props,
mocks: { mocks: {
$apollo: { queries: { vulnerabilitiesCount: query } }, $apollo: { queries: { vulnerabilitiesCount: { ...query, refetch: refetchSpy } } },
}, },
}); });
}; };
...@@ -56,6 +60,11 @@ describe('Vulnerabilities count list component', () => { ...@@ -56,6 +60,11 @@ describe('Vulnerabilities count list component', () => {
unknown: 4, unknown: 4,
}); });
}); });
it('refetches the query when vulnerabilities-updated event is triggered', () => {
eventHub.$emit('vulnerabilities-updated', wrapper.vm);
expect(refetchSpy).toHaveBeenCalled();
});
}); });
describe.each` describe.each`
......
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