Commit 1afc225a authored by Fatih Acet's avatar Fatih Acet

Merge branch '9102-update-hide-dismissed-param' into 'master'

Use scope param instead of hide_dismissed

See merge request gitlab-org/gitlab!16834
parents ff600b84 00ac7fe2
---
title: Use scope param instead of hide_dismissed
merge_request: 16834
author:
type: changed
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import { getParameterValues } from '~/lib/utils/url_utility'; import { getParameterValues } from '~/lib/utils/url_utility';
import { parseBoolean } from '~/lib/utils/common_utils';
import * as types from './mutation_types'; import * as types from './mutation_types';
export const setFilter = ({ commit }, payload) => { export const setFilter = ({ commit }, payload) => {
...@@ -26,11 +25,9 @@ export const lockFilter = ({ commit }, payload) => { ...@@ -26,11 +25,9 @@ export const lockFilter = ({ commit }, payload) => {
}; };
export const setHideDismissedToggleInitialState = ({ commit }) => { export const setHideDismissedToggleInitialState = ({ commit }) => {
const [urlParam] = getParameterValues('hide_dismissed'); const [urlParam] = getParameterValues('scope');
if (typeof urlParam !== 'undefined') { const showDismissed = urlParam === 'all';
const parsedParam = parseBoolean(urlParam); commit(types.SET_TOGGLE_VALUE, { key: 'hide_dismissed', value: !showDismissed });
commit(types.SET_TOGGLE_VALUE, { key: 'hide_dismissed', value: parsedParam });
}
}; };
export const setToggleValue = ({ commit }, { key, value }) => { export const setToggleValue = ({ commit }, { key, value }) => {
......
...@@ -34,7 +34,7 @@ export const activeFilters = state => { ...@@ -34,7 +34,7 @@ export const activeFilters = state => {
// hide_dismissed is hardcoded as it currently is an edge-case, more info in the MR: // hide_dismissed is hardcoded as it currently is an edge-case, more info in the MR:
// https://gitlab.com/gitlab-org/gitlab/merge_requests/15333#note_208301144 // https://gitlab.com/gitlab-org/gitlab/merge_requests/15333#note_208301144
if (gon.features && gon.features.hideDismissedVulnerabilities) { if (gon.features && gon.features.hideDismissedVulnerabilities) {
filters.hide_dismissed = state.hide_dismissed; filters.scope = state.hide_dismissed ? 'dismissed' : 'all';
} }
return filters; return filters;
}; };
......
...@@ -17,6 +17,7 @@ export default { ...@@ -17,6 +17,7 @@ export default {
return { ...filter, selection }; return { ...filter, selection };
}); });
state.hide_dismissed = payload.scope !== 'all';
}, },
[types.SET_FILTER](state, payload) { [types.SET_FILTER](state, payload) {
const { filterId, optionId } = payload; const { filterId, optionId } = payload;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
empty_state_svg_path: image_path('illustrations/security-dashboard-empty-state.svg'), empty_state_svg_path: image_path('illustrations/security-dashboard-empty-state.svg'),
pipeline_id: pipeline.id, pipeline_id: pipeline.id,
project_id: project.id, project_id: project.id,
vulnerabilities_endpoint: expose_path(api_v4_projects_vulnerabilities_path(id: project.id, params: { pipeline_id: pipeline.id, scope: 'all' })), vulnerabilities_endpoint: expose_path(api_v4_projects_vulnerabilities_path(id: project.id, params: { pipeline_id: pipeline.id, scope: 'dismissed' })),
vulnerability_feedback_help_path: help_page_path('user/application_security/index') } } vulnerability_feedback_help_path: help_page_path('user/application_security/index') } }
- else - else
#js-security-report-app{ data: { head_blob_path: blob_path, #js-security-report-app{ data: { head_blob_path: blob_path,
......
...@@ -180,15 +180,15 @@ describe('Security Dashboard app', () => { ...@@ -180,15 +180,15 @@ describe('Security Dashboard app', () => {
getParameterValues.mockRestore(); getParameterValues.mockRestore();
}); });
it('hides dismissed vulnerabilities by default', () => { it.each`
description | getParameterValuesReturnValue | expected
${'hides dismissed vulnerabilities by default'} | ${[]} | ${true}
${'shows dismissed vulnerabilities if scope param is "all"'} | ${['all']} | ${false}
${'hides dismissed vulnerabilities if scope param is "dismissed"'} | ${['dismissed']} | ${true}
`('$description', ({ getParameterValuesReturnValue, expected }) => {
getParameterValues.mockImplementation(() => getParameterValuesReturnValue);
createComponent(); createComponent();
expect(wrapper.vm.$store.state.filters.hide_dismissed).toBe(true); expect(wrapper.vm.$store.state.filters.hide_dismissed).toBe(expected);
});
it('shows dismissed vulnerabilities if param is specified in URL', () => {
getParameterValues.mockImplementation(() => [false]);
createComponent();
expect(wrapper.vm.$store.state.filters.hide_dismissed).toBe(false);
}); });
}); });
}); });
...@@ -73,32 +73,43 @@ describe('filters actions', () => { ...@@ -73,32 +73,43 @@ describe('filters actions', () => {
}); });
describe('setHideDismissedToggleInitialState', () => { describe('setHideDismissedToggleInitialState', () => {
it('should not do anything if hide_dismissed param is not present', done => { [
spyOnDependency(module, 'getParameterValues').and.returnValue([]); {
const state = createState(); description: 'should set hide_dismissed to true if scope param is not present',
testAction(actions.setHideDismissedToggleInitialState, {}, state, [], [], done); returnValue: [],
}); hideDismissedValue: true,
},
it('should commit the SET_TOGGLE_VALUE mutation if hide_dismissed param is present', done => { {
const state = createState(); description: 'should set hide_dismissed to false if scope param is "all"',
spyOnDependency(module, 'getParameterValues').and.returnValue([false]); returnValue: ['all'],
hideDismissedValue: false,
testAction( },
actions.setHideDismissedToggleInitialState, {
{}, description: 'should set hide_dismissed to true if scope param is "dismissed"',
state, returnValue: ['dismissed'],
[ hideDismissedValue: true,
{ },
type: types.SET_TOGGLE_VALUE, ].forEach(testCase => {
payload: { it(testCase.description, done => {
key: 'hide_dismissed', spyOnDependency(module, 'getParameterValues').and.returnValue(testCase.returnValue);
value: false, const state = createState();
testAction(
actions.setHideDismissedToggleInitialState,
{},
state,
[
{
type: types.SET_TOGGLE_VALUE,
payload: {
key: 'hide_dismissed',
value: testCase.hideDismissedValue,
},
}, },
}, ],
], [],
[], done,
done, );
); });
}); });
}); });
......
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