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 { deprecatedCreateFlash as flash } from '~/flash';
import axios from '~/lib/utils/axios_utils';
import { __ } from '~/locale';
import { sprintf, __ } from '~/locale';
export default function initPathLocks(url, path) {
$('a.path-lock').on('click', (e) => {
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
.post(url, {
path,
......
......@@ -7,13 +7,24 @@ export default () => {
const { router, data } = initTree();
if (data.pathLocksAvailable) {
const toggleBtn = document.querySelector('.js-path-lock');
const toggleBtn = document.querySelector('a.js-path-lock');
if (!toggleBtn) return;
toggleBtn.addEventListener('click', (e) => {
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');
axios
......
......@@ -23,7 +23,7 @@ RSpec.describe 'Path Locks', :js do
click_link "encoding"
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')
end
......@@ -36,7 +36,7 @@ RSpec.describe 'Path Locks', :js do
end
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')
end
......@@ -48,13 +48,13 @@ RSpec.describe 'Path Locks', :js do
end
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')
end
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')
end
......@@ -68,7 +68,7 @@ RSpec.describe 'Path Locks', :js do
within '.locks' do
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')
end
......
......@@ -3987,6 +3987,12 @@ msgid_plural "Are you sure you want to import %d repositories?"
msgstr[0] ""
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?"
msgstr ""
......@@ -4047,6 +4053,12 @@ msgstr ""
msgid "Are you sure you want to unlock %{path_lock_path}?"
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}?"
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