Commit d6696f81 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'sh-wip-fix-duplicate-env-xhr' into 'master'

Fix pagination and duplicate requests in environments page

Closes #58191

See merge request gitlab-org/gitlab-ce!25582
parents 079d471e 43ac2a96
...@@ -43,7 +43,11 @@ export default { ...@@ -43,7 +43,11 @@ export default {
saveData(resp) { saveData(resp) {
this.isLoading = false; this.isLoading = false;
if (_.isEqual(resp.config.params, this.requestData)) { // Prevent the absence of the nested flag from causing mismatches
const response = this.filterNilValues(resp.config.params);
const request = this.filterNilValues(this.requestData);
if (_.isEqual(response, request)) {
this.store.storeAvailableCount(resp.data.available_count); this.store.storeAvailableCount(resp.data.available_count);
this.store.storeStoppedCount(resp.data.stopped_count); this.store.storeStoppedCount(resp.data.stopped_count);
this.store.storeEnvironments(resp.data.environments); this.store.storeEnvironments(resp.data.environments);
...@@ -51,6 +55,10 @@ export default { ...@@ -51,6 +55,10 @@ export default {
} }
}, },
filterNilValues(obj) {
return _.omit(obj, value => _.isUndefined(value) || _.isNull(value));
},
/** /**
* Handles URL and query parameter changes. * Handles URL and query parameter changes.
* When the user uses the pagination or the tabs, * When the user uses the pagination or the tabs,
...@@ -64,10 +72,9 @@ export default { ...@@ -64,10 +72,9 @@ export default {
// fetch new data // fetch new data
return this.service return this.service
.fetchEnvironments(this.requestData) .fetchEnvironments(this.requestData)
.then(response => this.successCallback(response)) .then(response => {
.then(() => { this.successCallback(response);
// restart polling this.poll.enable({ data: this.requestData, response });
this.poll.restart({ data: this.requestData });
}) })
.catch(() => { .catch(() => {
this.errorCallback(); this.errorCallback();
......
---
title: Fix pagination and duplicate requests in environments page
merge_request: 25582
author:
type: fixed
...@@ -38,6 +38,23 @@ describe 'Environments page', :js do ...@@ -38,6 +38,23 @@ describe 'Environments page', :js do
end end
end end
describe 'with environments spanning multiple pages', :js do
before do
allow(Kaminari.config).to receive(:default_per_page).and_return(3)
create_list(:environment, 4, project: project, state: :available)
end
it 'should render second page of pipelines' do
visit_environments(project, scope: 'available')
find('.js-next-button').click
wait_for_requests
expect(page).to have_selector('.gl-pagination .page', count: 2)
expect(find('.gl-pagination .page-item.active .page-link').text).to eq("2")
end
end
describe 'in stopped tab page' do describe 'in stopped tab page' do
it 'should show no environments' do it 'should show no environments' do
visit_environments(project, scope: 'stopped') visit_environments(project, scope: 'stopped')
......
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