summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-13 00:08:05 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-13 00:08:05 +0000
commit47b8f79a0896f406008d5a7eda2781f8da301e91 (patch)
tree1f15328719ca1215a2bd0ec6650ece0ca59de3f4 /app/assets/javascripts
parent52fe64b740a4ddbd5b085386dfe40fea191174ea (diff)
downloadgitlab-ce-47b8f79a0896f406008d5a7eda2781f8da301e91.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/ide/stores/actions.js2
-rw-r--r--app/assets/javascripts/notes/components/comment_form.vue17
-rw-r--r--app/assets/javascripts/notes/components/noteable_discussion.vue23
-rw-r--r--app/assets/javascripts/notes/stores/actions.js43
4 files changed, 43 insertions, 42 deletions
diff --git a/app/assets/javascripts/ide/stores/actions.js b/app/assets/javascripts/ide/stores/actions.js
index e0fa5a5d9cd..2e7bf9a7d5a 100644
--- a/app/assets/javascripts/ide/stores/actions.js
+++ b/app/assets/javascripts/ide/stores/actions.js
@@ -20,7 +20,7 @@ export const discardAllChanges = ({ state, commit, dispatch }) => {
commit(types.DISCARD_FILE_CHANGES, file.path);
if (file.tempFile) {
- dispatch('closeFile', file.path);
+ dispatch('closeFile', file);
}
});
diff --git a/app/assets/javascripts/notes/components/comment_form.vue b/app/assets/javascripts/notes/components/comment_form.vue
index fda494fec07..492d8de3802 100644
--- a/app/assets/javascripts/notes/components/comment_form.vue
+++ b/app/assets/javascripts/notes/components/comment_form.vue
@@ -193,23 +193,10 @@ export default {
this.stopPolling();
this.saveNote(noteData)
- .then(res => {
+ .then(() => {
this.enableButton();
this.restartPolling();
-
- if (res.errors) {
- if (res.errors.commands_only) {
- this.discard();
- } else {
- Flash(
- __('Something went wrong while adding your comment. Please try again.'),
- 'alert',
- this.$refs.commentForm,
- );
- }
- } else {
- this.discard();
- }
+ this.discard();
if (withIssueAction) {
this.toggleIssueState();
diff --git a/app/assets/javascripts/notes/components/noteable_discussion.vue b/app/assets/javascripts/notes/components/noteable_discussion.vue
index 0151a3f10a5..1f31720ff40 100644
--- a/app/assets/javascripts/notes/components/noteable_discussion.vue
+++ b/app/assets/javascripts/notes/components/noteable_discussion.vue
@@ -198,23 +198,22 @@ export default {
data: postData,
};
- this.isReplying = false;
this.saveNote(replyData)
- .then(() => {
- clearDraft(this.autosaveKey);
+ .then(res => {
+ if (res.hasFlash !== true) {
+ this.isReplying = false;
+ clearDraft(this.autosaveKey);
+ }
callback();
})
.catch(err => {
this.removePlaceholderNotes();
- this.isReplying = true;
- this.$nextTick(() => {
- const msg = __(
- 'Your comment could not be submitted! Please check your network connection and try again.',
- );
- Flash(msg, 'alert', this.$el);
- this.$refs.noteForm.note = noteText;
- callback(err);
- });
+ const msg = __(
+ 'Your comment could not be submitted! Please check your network connection and try again.',
+ );
+ Flash(msg, 'alert', this.$el);
+ this.$refs.noteForm.note = noteText;
+ callback(err);
});
},
jumpToNextDiscussion() {
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js
index 97b0269509a..9bd245c094d 100644
--- a/app/assets/javascripts/notes/stores/actions.js
+++ b/app/assets/javascripts/notes/stores/actions.js
@@ -14,7 +14,7 @@ import sidebarTimeTrackingEventHub from '../../sidebar/event_hub';
import { isInViewport, scrollToElement, isInMRPage } from '../../lib/utils/common_utils';
import { mergeUrlParams } from '../../lib/utils/url_utility';
import mrWidgetEventHub from '../../vue_merge_request_widget/event_hub';
-import { __ } from '~/locale';
+import { __, sprintf } from '~/locale';
import Api from '~/api';
let eTagPoll;
@@ -252,29 +252,22 @@ export const saveNote = ({ commit, dispatch }, noteData) => {
}
}
- const processErrors = res => {
- const { errors } = res;
- if (!errors || !Object.keys(errors).length) {
- return res;
- }
-
+ const processQuickActions = res => {
+ const { errors: { commands_only: message } = { commands_only: null } } = res;
/*
The following reply means that quick actions have been successfully applied:
{"commands_changes":{},"valid":false,"errors":{"commands_only":["Commands applied"]}}
*/
- if (hasQuickActions) {
+ if (hasQuickActions && message) {
eTagPoll.makeRequest();
$('.js-gfm-input').trigger('clear-commands-cache.atwho');
- const { commands_only: message } = errors;
Flash(message || __('Commands applied'), 'notice', noteData.flashContainer);
-
- return res;
}
- throw new Error(__('Failed to save comment!'));
+ return res;
};
const processEmojiAward = res => {
@@ -321,11 +314,33 @@ export const saveNote = ({ commit, dispatch }, noteData) => {
return res;
};
+ const processErrors = error => {
+ if (error.response) {
+ const {
+ response: { data = {} },
+ } = error;
+ const { errors = {} } = data;
+ const { base = [] } = errors;
+
+ // we handle only errors.base for now
+ if (base.length > 0) {
+ const errorMsg = sprintf(__('Your comment could not be submitted because %{error}'), {
+ error: base[0].toLowerCase(),
+ });
+ Flash(errorMsg, 'alert', noteData.flashContainer);
+ return { ...data, hasFlash: true };
+ }
+ }
+
+ throw error;
+ };
+
return dispatch(methodToDispatch, postData, { root: true })
- .then(processErrors)
+ .then(processQuickActions)
.then(processEmojiAward)
.then(processTimeTracking)
- .then(removePlaceholder);
+ .then(removePlaceholder)
+ .catch(processErrors);
};
const pollSuccessCallBack = (resp, commit, state, getters, dispatch) => {