Commit 7690f878 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/pollMergeTrainsCountGraphql' into 'master'

Added polling to ready to merge widget state

See merge request gitlab-org/gitlab!57337
parents b368a45c 5922385f
......@@ -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 { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests';
import createFlash from '~/flash';
import { secondsToMilliseconds } from '~/lib/utils/datetime_utility';
import simplePoll from '~/lib/utils/simple_poll';
import { __ } from '~/locale';
import SmartInterval from '~/smart_interval';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import MergeRequest from '../../../merge_request';
import { AUTO_MERGE_STRATEGIES, DANGER, INFO, WARNING } from '../../constants';
......@@ -66,6 +68,10 @@ export default {
this.isSquashReadOnly = data.project.squashReadOnly;
this.squashCommitMessage = data.project.mergeRequest.defaultSquashCommitMessage;
this.loading = false;
if (this.state.mergeTrainsCount !== null) {
this.initPolling();
}
},
},
},
......@@ -291,8 +297,23 @@ export default {
if (this.glFeatures.mergeRequestWidgetGraphql) {
eventHub.$off('ApprovalUpdated', this.updateGraphqlState);
}
if (this.pollingInterval) {
this.pollingInterval.destroy();
}
},
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() {
return this.$apollo.queries.state.refetch();
},
......
......@@ -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
before do
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
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