Commit 7f34b7cb authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'issue-edit-inline-project-move-warning' into 'issue-edit-inline'

Warn before moving issue in inline edit form

See merge request !11708
parents 0defc4f7 10dccdc4
...@@ -114,6 +114,7 @@ export default { ...@@ -114,6 +114,7 @@ export default {
description: this.state.descriptionText, description: this.state.descriptionText,
lockedWarningVisible: false, lockedWarningVisible: false,
move_to_project_id: 0, move_to_project_id: 0,
updateLoading: false,
}); });
} }
}, },
...@@ -121,6 +122,14 @@ export default { ...@@ -121,6 +122,14 @@ export default {
this.showForm = false; this.showForm = false;
}, },
updateIssuable() { updateIssuable() {
const canPostUpdate = this.store.formState.move_to_project_id !== 0 ?
confirm('Are you sure you want to move this issue to another project?') : true; // eslint-disable-line no-alert
if (!canPostUpdate) {
this.store.formState.updateLoading = false;
return;
}
this.service.updateIssuable(this.store.formState) this.service.updateIssuable(this.store.formState)
.then(res => res.json()) .then(res => res.json())
.then((data) => { .then((data) => {
...@@ -149,7 +158,7 @@ export default { ...@@ -149,7 +158,7 @@ export default {
// Stop the poll so we don't get 404's with the issue not existing // Stop the poll so we don't get 404's with the issue not existing
this.poll.stop(); this.poll.stop();
gl.utils.visitUrl(data.path); gl.utils.visitUrl(data.web_url);
}) })
.catch(() => { .catch(() => {
eventHub.$emit('close.form'); eventHub.$emit('close.form');
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
data() { data() {
return { return {
deleteLoading: false, deleteLoading: false,
updateLoading: false,
}; };
}, },
computed: { computed: {
...@@ -25,7 +24,7 @@ ...@@ -25,7 +24,7 @@
}, },
methods: { methods: {
updateIssuable() { updateIssuable() {
this.updateLoading = true; this.formState.updateLoading = true;
eventHub.$emit('update.issuable'); eventHub.$emit('update.issuable');
}, },
closeForm() { closeForm() {
...@@ -47,7 +46,7 @@ ...@@ -47,7 +46,7 @@
<div class="prepend-top-default append-bottom-default clearfix"> <div class="prepend-top-default append-bottom-default clearfix">
<button <button
class="btn btn-save pull-left" class="btn btn-save pull-left"
:class="{ disabled: updateLoading || !isSubmitEnabled }" :class="{ disabled: formState.updateLoading || !isSubmitEnabled }"
type="submit" type="submit"
:disabled="updateLoading || !isSubmitEnabled" :disabled="updateLoading || !isSubmitEnabled"
@click.prevent="updateIssuable"> @click.prevent="updateIssuable">
...@@ -55,7 +54,7 @@ ...@@ -55,7 +54,7 @@
<i <i
class="fa fa-spinner fa-spin" class="fa fa-spinner fa-spin"
aria-hidden="true" aria-hidden="true"
v-if="updateLoading"> v-if="formState.updateLoading">
</i> </i>
</button> </button>
<button <button
......
...@@ -19,6 +19,7 @@ export default class Store { ...@@ -19,6 +19,7 @@ export default class Store {
description: '', description: '',
lockedWarningVisible: false, lockedWarningVisible: false,
move_to_project_id: 0, move_to_project_id: 0,
updateLoading: false,
}; };
} }
......
...@@ -20,7 +20,7 @@ module IssuableActions ...@@ -20,7 +20,7 @@ module IssuableActions
format.html { redirect_to index_path } format.html { redirect_to index_path }
format.json do format.json do
render json: { render json: {
path: index_path web_url: index_path
} }
end end
end end
......
...@@ -32,13 +32,16 @@ describe('Issuable output', () => { ...@@ -32,13 +32,16 @@ describe('Issuable output', () => {
canMove: true, canMove: true,
endpoint: '/gitlab-org/gitlab-shell/issues/9/realtime_changes', endpoint: '/gitlab-org/gitlab-shell/issues/9/realtime_changes',
issuableRef: '#1', issuableRef: '#1',
initialTitle: '', initialTitleHtml: '',
initialTitleText: '',
initialDescriptionHtml: '', initialDescriptionHtml: '',
initialDescriptionText: '', initialDescriptionText: '',
markdownPreviewUrl: '/', markdownPreviewUrl: '/',
markdownDocs: '/', markdownDocs: '/',
projectsAutocompleteUrl: '/', projectsAutocompleteUrl: '/',
isConfidential: false, isConfidential: false,
projectNamespace: '/',
projectPath: '/',
}, },
}).$mount(); }).$mount();
}); });
...@@ -224,6 +227,23 @@ describe('Issuable output', () => { ...@@ -224,6 +227,23 @@ describe('Issuable output', () => {
}); });
}); });
it('does not update issuable if project move confirm is false', (done) => {
spyOn(window, 'confirm').and.returnValue(false);
spyOn(vm.service, 'updateIssuable');
vm.store.formState.move_to_project_id = 1;
vm.updateIssuable();
setTimeout(() => {
expect(
vm.service.updateIssuable,
).not.toHaveBeenCalled();
done();
});
});
it('closes form on error', (done) => { it('closes form on error', (done) => {
spyOn(window, 'Flash').and.callThrough(); spyOn(window, 'Flash').and.callThrough();
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve, reject) => { spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve, reject) => {
......
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