diff --git a/ee/app/assets/javascripts/dependencies/components/dependencies_actions.vue b/ee/app/assets/javascripts/dependencies/components/dependencies_actions.vue index cb48796946243dd6115a0146b8561710a63dd4da..957d55d811b89aeefddf954ff48afc55faed49a6 100644 --- a/ee/app/assets/javascripts/dependencies/components/dependencies_actions.vue +++ b/ee/app/assets/javascripts/dependencies/components/dependencies_actions.vue @@ -4,6 +4,7 @@ import { GlSorting } from '@gitlab/ui'; import { mapActions, mapState } from 'vuex'; import { omit } from 'lodash'; import { __ } from '~/locale'; +import { setUrlParams, updateHistory } from '~/lib/utils/url_utility'; import GroupDependenciesFilteredSearch from 'ee/dependencies/components/filtered_search/group_dependencies_filtered_search.vue'; import { NAMESPACE_PROJECT } from '../constants'; import { DEPENDENCY_LIST_TYPES } from '../store/constants'; @@ -67,12 +68,17 @@ export default { methods: { ...mapActions({ setSortField(dispatch, field) { + this.clearCursorParam(); dispatch(`${this.namespace}/setSortField`, field); }, toggleSortOrder(dispatch) { + this.clearCursorParam(); dispatch(`${this.namespace}/toggleSortOrder`); }, }), + clearCursorParam() { + updateHistory({ url: setUrlParams({ cursor: null }) }); + }, }, }; </script> diff --git a/ee/app/assets/javascripts/dependencies/store/modules/list/actions.js b/ee/app/assets/javascripts/dependencies/store/modules/list/actions.js index 7e8b72e3d89325feaf31804853df3513db8a3c2b..b43c5462466ad7bf8e6c27e7b3289f2f78692d1a 100644 --- a/ee/app/assets/javascripts/dependencies/store/modules/list/actions.js +++ b/ee/app/assets/javascripts/dependencies/store/modules/list/actions.js @@ -91,12 +91,6 @@ const queryParametersFor = (state, params) => { ...params, }; - if (state.pageInfo.type === 'cursor' || (params && 'cursor' in params)) { - queryParams.cursor = params.cursor || state.pageInfo.currentCursor; - } else { - queryParams.page = params?.page || state.pageInfo.page || 1; - } - return queryParams; }; diff --git a/ee/spec/frontend/dependencies/components/dependencies_actions_spec.js b/ee/spec/frontend/dependencies/components/dependencies_actions_spec.js index b47f7060255fd09e7bae39ffc6426079eb41c16d..7014ac43b974dddb4fd5ff22275866ab443c7fe5 100644 --- a/ee/spec/frontend/dependencies/components/dependencies_actions_spec.js +++ b/ee/spec/frontend/dependencies/components/dependencies_actions_spec.js @@ -8,6 +8,7 @@ import { SORT_FIELDS_GROUP, SORT_FIELDS_PROJECT, } from 'ee/dependencies/store/modules/list/constants'; +import * as urlUtility from '~/lib/utils/url_utility'; import { TEST_HOST } from 'helpers/test_constants'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; @@ -43,6 +44,7 @@ describe('DependenciesActions component', () => { propsData: { namespace }, }); store.state[namespace].endpoint = `${TEST_HOST}/dependencies.json`; + jest.spyOn(urlUtility, 'updateHistory'); await nextTick(); }); @@ -78,6 +80,10 @@ describe('DependenciesActions component', () => { Object.keys(SORT_FIELDS_GROUP).map((field) => [`${namespace}/setSortField`, field]), ), ); + expect(urlUtility.updateHistory).toHaveBeenCalledTimes(4); + expect(urlUtility.updateHistory).toHaveBeenCalledWith({ + url: `${TEST_HOST}/`, + }); }); it('renders a filtered-search input', () => { @@ -114,5 +120,9 @@ describe('DependenciesActions component', () => { it('dispatches the toggleSortOrder action on clicking the sort order button', () => { findSorting().vm.$emit('sortDirectionChange'); expect(store.dispatch).toHaveBeenCalledWith(`${namespace}/toggleSortOrder`); + expect(urlUtility.updateHistory).toHaveBeenCalledTimes(1); + expect(urlUtility.updateHistory).toHaveBeenCalledWith({ + url: `${TEST_HOST}/`, + }); }); }); diff --git a/ee/spec/frontend/dependencies/store/modules/list/actions_spec.js b/ee/spec/frontend/dependencies/store/modules/list/actions_spec.js index 124ced717b4c6038040922a3ac1681f263680ba2..66daffb7a2aa4727004851acdaedba185d7e1cfe 100644 --- a/ee/spec/frontend/dependencies/store/modules/list/actions_spec.js +++ b/ee/spec/frontend/dependencies/store/modules/list/actions_spec.js @@ -238,7 +238,7 @@ describe('Dependencies actions', () => { }); describe('on success', () => { - describe('given no params', () => { + describe('given only page param', () => { beforeEach(() => { state.pageInfo = { ...pageInfo }; @@ -257,7 +257,7 @@ describe('Dependencies actions', () => { it('uses default sorting params from state', () => testAction( actions.fetchDependencies, - undefined, + { page: state.pageInfo.page }, state, [], [ @@ -298,7 +298,7 @@ describe('Dependencies actions', () => { it('fetches the results for the current cursor', () => { testAction( actions.fetchDependencies, - {}, + { cursor: state.pageInfo.currentCursor }, state, [], [