Commit d2171720 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '345158-roadmap-prevent-reloading-daterange-change' into 'master'

Roadmap - Prevent page reload when changing daterange in settings

See merge request gitlab-org/gitlab!79701
parents 18d9234f 01fa6af4
...@@ -4,7 +4,6 @@ import { mapState, mapActions } from 'vuex'; ...@@ -4,7 +4,6 @@ import { mapState, mapActions } from 'vuex';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { DATE_RANGES } from '../constants';
import EpicsListEmpty from './epics_list_empty.vue'; import EpicsListEmpty from './epics_list_empty.vue';
import RoadmapFilters from './roadmap_filters.vue'; import RoadmapFilters from './roadmap_filters.vue';
import RoadmapSettings from './roadmap_settings.vue'; import RoadmapSettings from './roadmap_settings.vue';
...@@ -20,15 +19,6 @@ export default { ...@@ -20,15 +19,6 @@ export default {
}, },
mixins: [glFeatureFlagMixin()], mixins: [glFeatureFlagMixin()],
props: { props: {
timeframeRangeType: {
type: String,
required: false,
default: DATE_RANGES.CURRENT_QUARTER,
},
presetType: {
type: String,
required: true,
},
emptyStateIllustrationPath: { emptyStateIllustrationPath: {
type: String, type: String,
required: true, required: true,
...@@ -52,6 +42,8 @@ export default { ...@@ -52,6 +42,8 @@ export default {
'isChildEpics', 'isChildEpics',
'hasFiltersApplied', 'hasFiltersApplied',
'filterParams', 'filterParams',
'presetType',
'timeframeRangeType',
]), ]),
showFilteredSearchbar() { showFilteredSearchbar() {
if (this.epicsFetchResultEmpty) { if (this.epicsFetchResultEmpty) {
......
<script> <script>
import { GlFormGroup, GlFormRadioGroup, GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlFormGroup, GlFormRadioGroup, GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { visitUrl, mergeUrlParams } from '~/lib/utils/url_utility';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import { PRESET_TYPES, DATE_RANGES } from '../constants'; import { PRESET_TYPES, DATE_RANGES } from '../constants';
...@@ -59,6 +58,7 @@ export default { ...@@ -59,6 +58,7 @@ export default {
}, },
}, },
methods: { methods: {
...mapActions(['setDaterange', 'fetchEpics', 'fetchMilestones']),
handleDaterangeSelect(value) { handleDaterangeSelect(value) {
this.selectedDaterange = value; this.selectedDaterange = value;
}, },
...@@ -67,24 +67,19 @@ export default { ...@@ -67,24 +67,19 @@ export default {
}, },
handleDaterangeDropdownClose() { handleDaterangeDropdownClose() {
if (this.initialSelectedDaterange !== this.selectedDaterange) { if (this.initialSelectedDaterange !== this.selectedDaterange) {
visitUrl( this.setDaterange({
mergeUrlParams( timeframeRangeType: this.selectedDaterange,
{ presetType: getPresetTypeForTimeframeRangeType(this.selectedDaterange),
timeframe_range_type: this.selectedDaterange, });
layout: getPresetTypeForTimeframeRangeType(this.selectedDaterange), this.fetchEpics();
}, this.fetchMilestones();
window.location.href,
),
);
} }
}, },
handleRoadmapLayoutChange(presetType) { handleRoadmapLayoutChange(presetType) {
visitUrl( if (presetType !== this.presetType) {
mergeUrlParams( this.setDaterange({ timeframeRangeType: this.selectedDaterange, presetType });
{ timeframe_range_type: this.selectedDaterange, layout: presetType }, this.fetchEpics();
window.location.href, }
),
);
}, },
}, },
i18n: { i18n: {
......
...@@ -129,8 +129,6 @@ export default () => { ...@@ -129,8 +129,6 @@ export default () => {
render(createElement) { render(createElement) {
return createElement('roadmap-app', { return createElement('roadmap-app', {
props: { props: {
timeframeRangeType: this.timeframeRangeType,
presetType: this.presetType,
emptyStateIllustrationPath: this.emptyStateIllustrationPath, emptyStateIllustrationPath: this.emptyStateIllustrationPath,
}, },
}); });
......
...@@ -319,6 +319,9 @@ export const setBufferSize = ({ commit }, bufferSize) => commit(types.SET_BUFFER ...@@ -319,6 +319,9 @@ export const setBufferSize = ({ commit }, bufferSize) => commit(types.SET_BUFFER
export const setEpicsState = ({ commit }, epicsState) => commit(types.SET_EPICS_STATE, epicsState); export const setEpicsState = ({ commit }, epicsState) => commit(types.SET_EPICS_STATE, epicsState);
export const setDaterange = ({ commit }, { timeframeRangeType, presetType }) =>
commit(types.SET_DATERANGE, { timeframeRangeType, presetType });
export const setFilterParams = ({ commit }, filterParams) => export const setFilterParams = ({ commit }, filterParams) =>
commit(types.SET_FILTER_PARAMS, filterParams); commit(types.SET_FILTER_PARAMS, filterParams);
......
...@@ -29,5 +29,6 @@ export const RECEIVE_MILESTONES_FAILURE = 'RECEIVE_MILESTONES_FAILURE'; ...@@ -29,5 +29,6 @@ export const RECEIVE_MILESTONES_FAILURE = 'RECEIVE_MILESTONES_FAILURE';
export const SET_BUFFER_SIZE = 'SET_BUFFER_SIZE'; export const SET_BUFFER_SIZE = 'SET_BUFFER_SIZE';
export const SET_EPICS_STATE = 'SET_EPICS_STATE'; export const SET_EPICS_STATE = 'SET_EPICS_STATE';
export const SET_DATERANGE = 'SET_DATERANGE';
export const SET_FILTER_PARAMS = 'SET_FILTER_PARAMS'; export const SET_FILTER_PARAMS = 'SET_FILTER_PARAMS';
export const SET_SORTED_BY = 'SET_SORTED_BY'; export const SET_SORTED_BY = 'SET_SORTED_BY';
import Vue from 'vue'; import Vue from 'vue';
import { getTimeframeForRangeType } from '../utils/roadmap_utils';
import * as types from './mutation_types'; import * as types from './mutation_types';
const resetEpics = (state) => { const resetEpics = (state) => {
...@@ -93,6 +94,8 @@ export default { ...@@ -93,6 +94,8 @@ export default {
}, },
[types.REQUEST_MILESTONES](state) { [types.REQUEST_MILESTONES](state) {
state.milestonesFetchInProgress = true; state.milestonesFetchInProgress = true;
state.milestones = [];
state.milestoneIds = [];
}, },
[types.RECEIVE_MILESTONES_SUCCESS](state, milestones) { [types.RECEIVE_MILESTONES_SUCCESS](state, milestones) {
state.milestonesFetchInProgress = false; state.milestonesFetchInProgress = false;
...@@ -122,6 +125,16 @@ export default { ...@@ -122,6 +125,16 @@ export default {
resetEpics(state); resetEpics(state);
}, },
[types.SET_DATERANGE](state, { timeframeRangeType, presetType }) {
state.timeframeRangeType = timeframeRangeType;
state.presetType = presetType;
state.timeframe = getTimeframeForRangeType({
timeframeRangeType,
presetType,
});
resetEpics(state);
},
[types.SET_SORTED_BY](state, sortedBy) { [types.SET_SORTED_BY](state, sortedBy) {
state.childrenEpics = {}; state.childrenEpics = {};
state.sortedBy = sortedBy; state.sortedBy = sortedBy;
......
...@@ -167,8 +167,6 @@ RSpec.describe 'group epic roadmap', :js do ...@@ -167,8 +167,6 @@ RSpec.describe 'group epic roadmap', :js do
page.find('[data-testid="daterange-dropdown"] button.dropdown-toggle').click page.find('[data-testid="daterange-dropdown"] button.dropdown-toggle').click
click_button(range_type) click_button(range_type)
end end
open_settings_sidebar
end end
it 'renders daterange filtering dropdown with "This quarter" selected by default no layout presets available', :aggregate_failures do it 'renders daterange filtering dropdown with "This quarter" selected by default no layout presets available', :aggregate_failures do
......
...@@ -30,6 +30,7 @@ describe('RoadmapApp', () => { ...@@ -30,6 +30,7 @@ describe('RoadmapApp', () => {
const epics = [mockFormattedEpic]; const epics = [mockFormattedEpic];
const hasFiltersApplied = true; const hasFiltersApplied = true;
const presetType = PRESET_TYPES.MONTHS; const presetType = PRESET_TYPES.MONTHS;
const timeframeRangeType = DATE_RANGES.CURRENT_YEAR;
const timeframe = getTimeframeForRangeType({ const timeframe = getTimeframeForRangeType({
timeframeRangeType: DATE_RANGES.CURRENT_YEAR, timeframeRangeType: DATE_RANGES.CURRENT_YEAR,
presetType: PRESET_TYPES.MONTHS, presetType: PRESET_TYPES.MONTHS,
...@@ -40,7 +41,6 @@ describe('RoadmapApp', () => { ...@@ -40,7 +41,6 @@ describe('RoadmapApp', () => {
return shallowMountExtended(RoadmapApp, { return shallowMountExtended(RoadmapApp, {
propsData: { propsData: {
emptyStateIllustrationPath, emptyStateIllustrationPath,
presetType,
}, },
provide: { provide: {
groupFullPath: 'gitlab-org', groupFullPath: 'gitlab-org',
...@@ -64,6 +64,7 @@ describe('RoadmapApp', () => { ...@@ -64,6 +64,7 @@ describe('RoadmapApp', () => {
hasFiltersApplied, hasFiltersApplied,
filterQueryString: '', filterQueryString: '',
basePath, basePath,
timeframeRangeType,
}); });
}); });
......
...@@ -487,14 +487,14 @@ describe('Roadmap Vuex Actions', () => { ...@@ -487,14 +487,14 @@ describe('Roadmap Vuex Actions', () => {
beforeEach(() => { beforeEach(() => {
mockState = { mockState = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
milestonessState: 'active', milestonesState: 'active',
presetType: PRESET_TYPES.MONTHS, presetType: PRESET_TYPES.MONTHS,
timeframe: mockTimeframeMonths, timeframe: mockTimeframeMonths,
}; };
expectedVariables = { expectedVariables = {
fullPath: 'gitlab-org', fullPath: 'gitlab-org',
state: mockState.milestonessState, state: mockState.milestonesState,
timeframe: { timeframe: {
start: '2018-01-01', start: '2018-01-01',
end: '2018-12-31', end: '2018-12-31',
...@@ -644,4 +644,21 @@ describe('Roadmap Vuex Actions', () => { ...@@ -644,4 +644,21 @@ describe('Roadmap Vuex Actions', () => {
); );
}); });
}); });
describe('setDaterange', () => {
it('should set epicsState in store state', () => {
return testAction(
actions.setDaterange,
{ timeframeRangeType: 'CURRENT_YEAR', presetType: 'MONTHS' },
state,
[
{
type: types.SET_DATERANGE,
payload: { timeframeRangeType: 'CURRENT_YEAR', presetType: 'MONTHS' },
},
],
[],
);
});
});
}); });
...@@ -2,6 +2,7 @@ import * as types from 'ee/roadmap/store/mutation_types'; ...@@ -2,6 +2,7 @@ import * as types from 'ee/roadmap/store/mutation_types';
import mutations from 'ee/roadmap/store/mutations'; import mutations from 'ee/roadmap/store/mutations';
import defaultState from 'ee/roadmap/store/state'; import defaultState from 'ee/roadmap/store/state';
import { getTimeframeForRangeType } from 'ee/roadmap/utils/roadmap_utils';
import { import {
mockGroupId, mockGroupId,
...@@ -303,6 +304,28 @@ describe('Roadmap Store Mutations', () => { ...@@ -303,6 +304,28 @@ describe('Roadmap Store Mutations', () => {
}); });
}); });
describe('SET_DATERANGE', () => {
it('Should set `timeframeRangeType`, `presetType` and `timeframe` to the state and reset existing epics', () => {
const timeframeRangeType = 'CURRENT_YEAR';
const presetType = 'MONTHS';
setEpicMockData(state);
mutations[types.SET_DATERANGE](state, { timeframeRangeType, presetType });
expect(state).toMatchObject({
timeframeRangeType,
presetType,
timeframe: getTimeframeForRangeType({
timeframeRangeType,
presetType,
}),
epics: [],
childrenFlags: {},
epicIds: [],
});
});
});
describe('SET_SORTED_BY', () => { describe('SET_SORTED_BY', () => {
it('Should set `sortedBy` to the state and reset existing parent epics and children epics', () => { it('Should set `sortedBy` to the state and reset existing parent epics and children epics', () => {
const sortedBy = 'start_date_asc'; const sortedBy = 'start_date_asc';
......
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