Commit 5922385f authored by Phil Hughes's avatar Phil Hughes

Added polling to ready to merge widget state

Adds polling to get the updated merge trains count
parent aded595a
...@@ -16,8 +16,10 @@ import readyToMergeMixin from 'ee_else_ce/vue_merge_request_widget/mixins/ready_ ...@@ -16,8 +16,10 @@ import readyToMergeMixin from 'ee_else_ce/vue_merge_request_widget/mixins/ready_
import readyToMergeQuery from 'ee_else_ce/vue_merge_request_widget/queries/states/ready_to_merge.query.graphql'; import readyToMergeQuery from 'ee_else_ce/vue_merge_request_widget/queries/states/ready_to_merge.query.graphql';
import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests'; import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { secondsToMilliseconds } from '~/lib/utils/datetime_utility';
import simplePoll from '~/lib/utils/simple_poll'; import simplePoll from '~/lib/utils/simple_poll';
import { __ } from '~/locale'; import { __ } from '~/locale';
import SmartInterval from '~/smart_interval';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import MergeRequest from '../../../merge_request'; import MergeRequest from '../../../merge_request';
import { AUTO_MERGE_STRATEGIES, DANGER, INFO, WARNING } from '../../constants'; import { AUTO_MERGE_STRATEGIES, DANGER, INFO, WARNING } from '../../constants';
...@@ -66,6 +68,10 @@ export default { ...@@ -66,6 +68,10 @@ export default {
this.isSquashReadOnly = data.project.squashReadOnly; this.isSquashReadOnly = data.project.squashReadOnly;
this.squashCommitMessage = data.project.mergeRequest.defaultSquashCommitMessage; this.squashCommitMessage = data.project.mergeRequest.defaultSquashCommitMessage;
this.loading = false; this.loading = false;
if (this.state.mergeTrainsCount !== null) {
this.initPolling();
}
}, },
}, },
}, },
...@@ -291,8 +297,23 @@ export default { ...@@ -291,8 +297,23 @@ export default {
if (this.glFeatures.mergeRequestWidgetGraphql) { if (this.glFeatures.mergeRequestWidgetGraphql) {
eventHub.$off('ApprovalUpdated', this.updateGraphqlState); eventHub.$off('ApprovalUpdated', this.updateGraphqlState);
} }
if (this.pollingInterval) {
this.pollingInterval.destroy();
}
}, },
methods: { methods: {
initPolling() {
const startingPollInterval = secondsToMilliseconds(5);
this.pollingInterval = new SmartInterval({
callback: () => this.$apollo.queries.state.refetch(),
startingInterval: startingPollInterval,
maxInterval: startingPollInterval + secondsToMilliseconds(4 * 60),
hiddenInterval: secondsToMilliseconds(6 * 60),
incrementByFactorOf: 2,
});
},
updateGraphqlState() { updateGraphqlState() {
return this.$apollo.queries.state.refetch(); return this.$apollo.queries.state.refetch();
}, },
......
...@@ -85,12 +85,6 @@ RSpec.describe 'User adds a merge request to a merge train', :js do ...@@ -85,12 +85,6 @@ RSpec.describe 'User adds a merge request to a merge train', :js do
context "when user clicks 'Remove from merge train' button" do context "when user clicks 'Remove from merge train' button" do
before do before do
click_link 'Remove from merge train' click_link 'Remove from merge train'
# Currently, this page shows "Add to merge train" button instead of "Start merge train",
# even though the merge train is empty.
# This likely is caused by the stale cache in client side. Frontend
# would need to refresh the mergiability data, specifically `stateData.mergeTrainsCount` periodically e.g. polling.
# As a workaround, we're doing a hard reload by executing `visit` here.
visit project_merge_request_path(project, merge_request)
end end
it 'cancels automatic merge' do it 'cancels automatic merge' do
......
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