Commit e0503130 authored by Jacopo's avatar Jacopo

Hide close MR button after merge without reloading page

After merging a MR the close button is hidden, without reloading the page.
parent e2b195b2
...@@ -127,6 +127,21 @@ import IssuablesHelper from './helpers/issuables_helper'; ...@@ -127,6 +127,21 @@ import IssuablesHelper from './helpers/issuables_helper';
$el.text(gl.text.addDelimiter(count)); $el.text(gl.text.addDelimiter(count));
}; };
MergeRequest.prototype.hideCloseButton = function() {
const el = document.querySelector('.merge-request .issuable-actions');
const closeDropdownItem = el.querySelector('li.close-item');
if (closeDropdownItem) {
closeDropdownItem.classList.add('hidden');
// Selects the next dropdown item
el.querySelector('li.report-item').click();
} else {
// No dropdown just hide the Close button
el.querySelector('.btn-close').classList.add('hidden');
}
// Dropdown for mobile screen
el.querySelector('li.js-close-item').classList.add('hidden');
};
return MergeRequest; return MergeRequest;
})(); })();
}).call(window); }).call(window);
...@@ -156,6 +156,7 @@ export default { ...@@ -156,6 +156,7 @@ export default {
eventHub.$emit('FetchActionsContent'); eventHub.$emit('FetchActionsContent');
if (window.mergeRequest) { if (window.mergeRequest) {
window.mergeRequest.updateStatusText('status-box-open', 'status-box-merged', 'Merged'); window.mergeRequest.updateStatusText('status-box-open', 'status-box-merged', 'Merged');
window.mergeRequest.hideCloseButton();
window.mergeRequest.decreaseCounter(); window.mergeRequest.decreaseCounter();
} }
stopPolling(); stopPolling();
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
- unless current_user == @merge_request.author - unless current_user == @merge_request.author
%li= link_to 'Report abuse', new_abuse_report_path(user_id: @merge_request.author.id, ref_url: merge_request_url(@merge_request)) %li= link_to 'Report abuse', new_abuse_report_path(user_id: @merge_request.author.id, ref_url: merge_request_url(@merge_request))
- if can_update_merge_request - if can_update_merge_request
%li{ class: merge_request_button_visibility(@merge_request, true) } %li{ class: [merge_request_button_visibility(@merge_request, true), 'js-close-item'] }
= link_to 'Close', merge_request_path(@merge_request, merge_request: { state_event: :close }), method: :put, title: 'Close merge request' = link_to 'Close', merge_request_path(@merge_request, merge_request: { state_event: :close }), method: :put, title: 'Close merge request'
%li{ class: merge_request_button_visibility(@merge_request, false) } %li{ class: merge_request_button_visibility(@merge_request, false) }
= link_to 'Reopen', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: 'reopen-mr-link', title: 'Reopen merge request' = link_to 'Reopen', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: 'reopen-mr-link', title: 'Reopen merge request'
......
---
title: Hide close MR button after merge without reloading page
merge_request: 14122
author: Jacopo Beschi @jacopo-beschi
type: added
...@@ -41,6 +41,12 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont ...@@ -41,6 +41,12 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
remove_repository(project) remove_repository(project)
end end
it 'merge_requests/merge_request_of_current_user.html.raw' do |example|
merge_request.update(author: admin)
render_merge_request(example.description, merge_request)
end
it 'merge_requests/merge_request_with_task_list.html.raw' do |example| it 'merge_requests/merge_request_with_task_list.html.raw' do |example|
create(:ci_build, :pending, pipeline: pipeline) create(:ci_build, :pending, pipeline: pipeline)
......
...@@ -58,5 +58,44 @@ import IssuablesHelper from '~/helpers/issuables_helper'; ...@@ -58,5 +58,44 @@ import IssuablesHelper from '~/helpers/issuables_helper';
expect(CloseReopenReportToggle.prototype.initDroplab).toHaveBeenCalled(); expect(CloseReopenReportToggle.prototype.initDroplab).toHaveBeenCalled();
}); });
}); });
describe('hideCloseButton', () => {
describe('merge request of another user', () => {
beforeEach(() => {
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
this.el = document.querySelector('.merge-request .issuable-actions');
const merge = new MergeRequest();
merge.hideCloseButton();
});
it('hides the dropdown close item and selects the next item', () => {
const closeItem = this.el.querySelector('li.close-item');
const smallCloseItem = this.el.querySelector('.js-close-item');
const reportItem = this.el.querySelector('li.report-item');
expect(closeItem).toHaveClass('hidden');
expect(smallCloseItem).toHaveClass('hidden');
expect(reportItem).toHaveClass('droplab-item-selected');
expect(reportItem).not.toHaveClass('hidden');
});
});
describe('merge request of current_user', () => {
beforeEach(() => {
loadFixtures('merge_requests/merge_request_of_current_user.html.raw');
this.el = document.querySelector('.merge-request .issuable-actions');
const merge = new MergeRequest();
merge.hideCloseButton();
});
it('hides the close button', () => {
const closeButton = this.el.querySelector('.btn-close');
const smallCloseItem = this.el.querySelector('.js-close-item');
expect(closeButton).toHaveClass('hidden');
expect(smallCloseItem).toHaveClass('hidden');
});
});
});
}); });
}).call(window); }).call(window);
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