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 { getParameterValues } from '~/lib/utils/url_utility';
import { parseBoolean } from '~/lib/utils/common_utils';
import * as types from './mutation_types';
export const setFilter = ({ commit }, payload) => {
......@@ -26,11 +25,9 @@ export const lockFilter = ({ commit }, payload) => {
};
export const setHideDismissedToggleInitialState = ({ commit }) => {
const [urlParam] = getParameterValues('hide_dismissed');
if (typeof urlParam !== 'undefined') {
const parsedParam = parseBoolean(urlParam);
commit(types.SET_TOGGLE_VALUE, { key: 'hide_dismissed', value: parsedParam });
}
const [urlParam] = getParameterValues('scope');
const showDismissed = urlParam === 'all';
commit(types.SET_TOGGLE_VALUE, { key: 'hide_dismissed', value: !showDismissed });
};
export const setToggleValue = ({ commit }, { key, value }) => {
......
......@@ -34,7 +34,7 @@ export const activeFilters = state => {
// 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
if (gon.features && gon.features.hideDismissedVulnerabilities) {
filters.hide_dismissed = state.hide_dismissed;
filters.scope = state.hide_dismissed ? 'dismissed' : 'all';
}
return filters;
};
......
......@@ -17,6 +17,7 @@ export default {
return { ...filter, selection };
});
state.hide_dismissed = payload.scope !== 'all';
},
[types.SET_FILTER](state, payload) {
const { filterId, optionId } = payload;
......
......@@ -16,7 +16,7 @@
empty_state_svg_path: image_path('illustrations/security-dashboard-empty-state.svg'),
pipeline_id: pipeline.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') } }
- else
#js-security-report-app{ data: { head_blob_path: blob_path,
......
......@@ -180,15 +180,15 @@ describe('Security Dashboard app', () => {
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();
expect(wrapper.vm.$store.state.filters.hide_dismissed).toBe(true);
});
it('shows dismissed vulnerabilities if param is specified in URL', () => {
getParameterValues.mockImplementation(() => [false]);
createComponent();
expect(wrapper.vm.$store.state.filters.hide_dismissed).toBe(false);
expect(wrapper.vm.$store.state.filters.hide_dismissed).toBe(expected);
});
});
});
......@@ -73,32 +73,43 @@ describe('filters actions', () => {
});
describe('setHideDismissedToggleInitialState', () => {
it('should not do anything if hide_dismissed param is not present', done => {
spyOnDependency(module, 'getParameterValues').and.returnValue([]);
const state = createState();
testAction(actions.setHideDismissedToggleInitialState, {}, state, [], [], done);
});
it('should commit the SET_TOGGLE_VALUE mutation if hide_dismissed param is present', done => {
const state = createState();
spyOnDependency(module, 'getParameterValues').and.returnValue([false]);
testAction(
actions.setHideDismissedToggleInitialState,
{},
state,
[
{
type: types.SET_TOGGLE_VALUE,
payload: {
key: 'hide_dismissed',
value: false,
[
{
description: 'should set hide_dismissed to true if scope param is not present',
returnValue: [],
hideDismissedValue: true,
},
{
description: 'should set hide_dismissed to false if scope param is "all"',
returnValue: ['all'],
hideDismissedValue: false,
},
{
description: 'should set hide_dismissed to true if scope param is "dismissed"',
returnValue: ['dismissed'],
hideDismissedValue: true,
},
].forEach(testCase => {
it(testCase.description, done => {
spyOnDependency(module, 'getParameterValues').and.returnValue(testCase.returnValue);
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