Commit 6e634c99 authored by Lukas Eipert's avatar Lukas Eipert

Trigger refetching of vulns. from moderator

Instead of piping the change through the components we re-trigger
fetching the vulnerabilities from the moderator.
parent 31b126c1
...@@ -71,27 +71,20 @@ export default { ...@@ -71,27 +71,20 @@ export default {
...mapActions('vulnerabilities', [ ...mapActions('vulnerabilities', [
'createIssue', 'createIssue',
'dismissVulnerability', 'dismissVulnerability',
'fetchVulnerabilities',
'fetchVulnerabilitiesCount', 'fetchVulnerabilitiesCount',
'fetchVulnerabilitiesHistory',
'revertDismissal', 'revertDismissal',
'setVulnerabilitiesCountEndpoint', 'setVulnerabilitiesCountEndpoint',
'setVulnerabilitiesEndpoint', 'setVulnerabilitiesEndpoint',
'setVulnerabilitiesHistoryEndpoint', 'setVulnerabilitiesHistoryEndpoint',
]), ]),
...mapActions('projects', ['setProjectsEndpoint', 'fetchProjects']), ...mapActions('projects', ['setProjectsEndpoint', 'fetchProjects']),
filterChange() {
this.fetchVulnerabilities(this.activeFilters);
this.fetchVulnerabilitiesCount(this.activeFilters);
this.fetchVulnerabilitiesHistory(this.activeFilters);
},
}, },
}; };
</script> </script>
<template> <template>
<div> <div>
<filters :dashboard-documentation="dashboardDocumentation" @change="filterChange" /> <filters :dashboard-documentation="dashboardDocumentation" />
<vulnerability-count-list /> <vulnerability-count-list />
<h4 class="my-4">{{ __('Vulnerability Chart') }}</h4> <h4 class="my-4">{{ __('Vulnerability Chart') }}</h4>
<vulnerability-chart /> <vulnerability-chart />
......
...@@ -40,7 +40,6 @@ export default { ...@@ -40,7 +40,6 @@ export default {
filterId: this.filterId, filterId: this.filterId,
optionId: option.id, optionId: option.id,
}); });
this.$emit('change');
}, },
isSelected(option) { isSelected(option) {
return this.selection.has(option.id); return this.selection.has(option.id);
......
...@@ -27,7 +27,6 @@ export default { ...@@ -27,7 +27,6 @@ export default {
class="col-sm-6 col-md-4 col-lg-2 p-2 js-filter" class="col-sm-6 col-md-4 col-lg-2 p-2 js-filter"
:filter-id="filter.id" :filter-id="filter.id"
:dashboard-documentation="dashboardDocumentation" :dashboard-documentation="dashboardDocumentation"
@change="$emit('change')"
/> />
</div> </div>
</div> </div>
......
...@@ -44,7 +44,7 @@ export default { ...@@ -44,7 +44,7 @@ export default {
}, },
}, },
created() { created() {
this.fetchVulnerabilities(); this.fetchVulnerabilities(this.activeFilters);
}, },
methods: { methods: {
...mapActions('vulnerabilities', ['fetchVulnerabilities', 'openModal']), ...mapActions('vulnerabilities', ['fetchVulnerabilities', 'openModal']),
......
...@@ -16,7 +16,6 @@ export default () => { ...@@ -16,7 +16,6 @@ export default () => {
}, },
}); });
configureModerator(store); configureModerator(store);
return store; return store;
......
import * as filtersMutationTypes from './modules/filters/mutation_types';
import * as projectsMutationTypes from './modules/projects/mutation_types'; import * as projectsMutationTypes from './modules/projects/mutation_types';
export default function configureModerator(store) { export default function configureModerator(store) {
...@@ -18,6 +19,13 @@ export default function configureModerator(store) { ...@@ -18,6 +19,13 @@ export default function configureModerator(store) {
], ],
}); });
break; break;
case `filters/${filtersMutationTypes.SET_FILTER}`: {
const activeFilters = store.getters['filters/activeFilters'];
store.dispatch('vulnerabilities/fetchVulnerabilities', activeFilters);
store.dispatch('vulnerabilities/fetchVulnerabilitiesCount', activeFilters);
store.dispatch('vulnerabilities/fetchVulnerabilitiesHistory', activeFilters);
break;
}
default: default:
} }
}); });
......
import createStore from 'ee/security_dashboard/store/index'; import createStore from 'ee/security_dashboard/store/index';
import * as projectsMutationTypes from 'ee/security_dashboard/store/modules/projects/mutation_types'; import * as projectsMutationTypes from 'ee/security_dashboard/store/modules/projects/mutation_types';
import * as filtersMutationTypes from 'ee/security_dashboard/store/modules/filters/mutation_types';
describe('moderator', () => { describe('moderator', () => {
let store; let store;
...@@ -15,6 +16,7 @@ describe('moderator', () => { ...@@ -15,6 +16,7 @@ describe('moderator', () => {
projects: [{ name: 'foo', id: 1, otherProp: 'foobar' }], projects: [{ name: 'foo', id: 1, otherProp: 'foobar' }],
}); });
expect(store.dispatch).toHaveBeenCalledTimes(1);
expect(store.dispatch).toHaveBeenCalledWith( expect(store.dispatch).toHaveBeenCalledWith(
'filters/setFilterOptions', 'filters/setFilterOptions',
Object({ Object({
...@@ -23,4 +25,26 @@ describe('moderator', () => { ...@@ -23,4 +25,26 @@ describe('moderator', () => {
}), }),
); );
}); });
it('triggers fetching vulnerabilities after filters change', () => {
spyOn(store, 'dispatch').and.returnValue();
const activeFilters = store.getters['filters/activeFilters'];
store.commit(`filters/${filtersMutationTypes.SET_FILTER}`, {});
expect(store.dispatch).toHaveBeenCalledTimes(3);
expect(store.dispatch).toHaveBeenCalledWith(
'vulnerabilities/fetchVulnerabilities',
activeFilters,
);
expect(store.dispatch).toHaveBeenCalledWith(
'vulnerabilities/fetchVulnerabilitiesCount',
activeFilters,
);
expect(store.dispatch).toHaveBeenCalledWith(
'vulnerabilities/fetchVulnerabilitiesHistory',
activeFilters,
);
});
}); });
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