Commit 639adaf7 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'sh-add-path-lock-confirmation' into 'master'

Add a confirmation prompt to lock and unlock path locks

See merge request gitlab-org/gitlab!44849
parents 8df02215 389a16d1
---
title: Add a confirmation prompt to lock and unlock path locks
merge_request: 44849
author:
type: other
import $ from 'jquery'; import $ from 'jquery';
import { deprecatedCreateFlash as flash } from '~/flash'; import { deprecatedCreateFlash as flash } from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { __ } from '~/locale'; import { sprintf, __ } from '~/locale';
export default function initPathLocks(url, path) { export default function initPathLocks(url, path) {
$('a.path-lock').on('click', (e) => { $('a.path-lock').on('click', (e) => {
e.preventDefault(); e.preventDefault();
const { dataset } = e.target;
const message =
dataset.state === 'lock'
? __('Are you sure you want to lock %{path}?')
: __('Are you sure you want to unlock %{path}?');
// eslint-disable-next-line no-alert
if (!window.confirm(sprintf(message, { path }))) {
return;
}
axios axios
.post(url, { .post(url, {
path, path,
......
...@@ -7,13 +7,24 @@ export default () => { ...@@ -7,13 +7,24 @@ export default () => {
const { router, data } = initTree(); const { router, data } = initTree();
if (data.pathLocksAvailable) { if (data.pathLocksAvailable) {
const toggleBtn = document.querySelector('.js-path-lock'); const toggleBtn = document.querySelector('a.js-path-lock');
if (!toggleBtn) return; if (!toggleBtn) return;
toggleBtn.addEventListener('click', (e) => { toggleBtn.addEventListener('click', (e) => {
e.preventDefault(); e.preventDefault();
const { dataset } = e.target;
const message =
dataset.state === 'lock'
? __('Are you sure you want to lock this directory?')
: __('Are you sure you want to unlock this directory?');
// eslint-disable-next-line no-alert
if (!window.confirm(message)) {
return;
}
toggleBtn.setAttribute('disabled', 'disabled'); toggleBtn.setAttribute('disabled', 'disabled');
axios axios
......
...@@ -23,7 +23,7 @@ RSpec.describe 'Path Locks', :js do ...@@ -23,7 +23,7 @@ RSpec.describe 'Path Locks', :js do
click_link "encoding" click_link "encoding"
end end
find('.js-path-lock').click accept_confirm(text: 'Are you sure you want to lock this directory?') { find('.js-path-lock').click }
expect(page).to have_link('Unlock') expect(page).to have_link('Unlock')
end end
...@@ -36,7 +36,7 @@ RSpec.describe 'Path Locks', :js do ...@@ -36,7 +36,7 @@ RSpec.describe 'Path Locks', :js do
end end
within '.file-actions' do within '.file-actions' do
click_link "Lock" accept_confirm(text: 'Are you sure you want to lock VERSION?') { click_link "Lock" }
expect(page).to have_link('Unlock') expect(page).to have_link('Unlock')
end end
...@@ -48,13 +48,13 @@ RSpec.describe 'Path Locks', :js do ...@@ -48,13 +48,13 @@ RSpec.describe 'Path Locks', :js do
end end
within '.file-actions' do within '.file-actions' do
click_link "Lock" accept_confirm(text: 'Are you sure you want to lock VERSION?') { click_link "Lock" }
expect(page).to have_link('Unlock') expect(page).to have_link('Unlock')
end end
within '.file-actions' do within '.file-actions' do
click_link "Unlock" accept_confirm(text: 'Are you sure you want to unlock VERSION?') { click_link "Unlock" }
expect(page).to have_link('Lock') expect(page).to have_link('Lock')
end end
...@@ -68,7 +68,7 @@ RSpec.describe 'Path Locks', :js do ...@@ -68,7 +68,7 @@ RSpec.describe 'Path Locks', :js do
within '.locks' do within '.locks' do
expect(page).to have_content('encoding') expect(page).to have_content('encoding')
accept_confirm { click_link "Unlock" } accept_confirm(text: 'Are you sure you want to unlock encoding?') { click_link "Unlock" }
expect(page).not_to have_content('encoding') expect(page).not_to have_content('encoding')
end end
......
...@@ -3987,6 +3987,12 @@ msgid_plural "Are you sure you want to import %d repositories?" ...@@ -3987,6 +3987,12 @@ msgid_plural "Are you sure you want to import %d repositories?"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "Are you sure you want to lock %{path}?"
msgstr ""
msgid "Are you sure you want to lock this directory?"
msgstr ""
msgid "Are you sure you want to lose unsaved changes?" msgid "Are you sure you want to lose unsaved changes?"
msgstr "" msgstr ""
...@@ -4047,6 +4053,12 @@ msgstr "" ...@@ -4047,6 +4053,12 @@ msgstr ""
msgid "Are you sure you want to unlock %{path_lock_path}?" msgid "Are you sure you want to unlock %{path_lock_path}?"
msgstr "" msgstr ""
msgid "Are you sure you want to unlock %{path}?"
msgstr ""
msgid "Are you sure you want to unlock this directory?"
msgstr ""
msgid "Are you sure you want to unsubscribe from the %{type}: %{link_to_noteable_text}?" msgid "Are you sure you want to unsubscribe from the %{type}: %{link_to_noteable_text}?"
msgstr "" msgstr ""
......
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