diff options
author | Fatih Acet <acetfatih@gmail.com> | 2019-05-08 07:36:34 +0000 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2019-05-08 07:36:34 +0000 |
commit | 18dd29c0c3c3367b3188a8bac687dea609736e9a (patch) | |
tree | 468dd4c90c1640d1b7c7e16feba1c2b31e61279f /app | |
parent | 4f447e0f4b87d77f1de408cd69a66323465437f8 (diff) | |
parent | 4f1d2bf5a29f28a9f961379d4a3f426454b868b0 (diff) | |
download | gitlab-ce-18dd29c0c3c3367b3188a8bac687dea609736e9a.tar.gz |
Merge branch 'winh-notes-error-handling' into 'master'
Handle errors in successful notes reply
Closes #61377
See merge request gitlab-org/gitlab-ce!28082
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/notes/stores/actions.js | 17 | ||||
-rw-r--r-- | app/assets/javascripts/notes/stores/utils.js | 7 |
2 files changed, 17 insertions, 7 deletions
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js index bac124be34c..63658d49a05 100644 --- a/app/assets/javascripts/notes/stores/actions.js +++ b/app/assets/javascripts/notes/stores/actions.js @@ -268,11 +268,20 @@ export const saveNote = ({ commit, dispatch }, noteData) => { const { errors } = res; const commandsChanges = res.commands_changes; - if (hasQuickActions && errors && Object.keys(errors).length) { - eTagPoll.makeRequest(); + if (errors && Object.keys(errors).length) { + /* + The following reply means that quick actions have been successfully applied: - $('.js-gfm-input').trigger('clear-commands-cache.atwho'); - Flash(__('Commands applied'), 'notice', noteData.flashContainer); + {"commands_changes":{},"valid":false,"errors":{"commands_only":["Commands applied"]}} + */ + if (hasQuickActions) { + eTagPoll.makeRequest(); + + $('.js-gfm-input').trigger('clear-commands-cache.atwho'); + Flash(__('Commands applied'), 'notice', noteData.flashContainer); + } else { + throw new Error(__('Failed to save comment!')); + } } if (commandsChanges) { diff --git a/app/assets/javascripts/notes/stores/utils.js b/app/assets/javascripts/notes/stores/utils.js index 029fde348fb..ed4cef4a917 100644 --- a/app/assets/javascripts/notes/stores/utils.js +++ b/app/assets/javascripts/notes/stores/utils.js @@ -2,7 +2,8 @@ import AjaxCache from '~/lib/utils/ajax_cache'; import { trimFirstCharOfLineContent } from '~/diffs/store/utils'; import { sprintf, __ } from '~/locale'; -const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm; +// factory function because global flag makes RegExp stateful +const createQuickActionsRegex = () => /^\/\w+.*$/gm; export const findNoteObjectById = (notes, id) => notes.filter(n => n.id === id)[0]; @@ -27,9 +28,9 @@ export const getQuickActionText = note => { return text; }; -export const hasQuickActions = note => REGEX_QUICK_ACTIONS.test(note); +export const hasQuickActions = note => createQuickActionsRegex().test(note); -export const stripQuickActions = note => note.replace(REGEX_QUICK_ACTIONS, '').trim(); +export const stripQuickActions = note => note.replace(createQuickActionsRegex(), '').trim(); export const prepareDiffLines = diffLines => diffLines.map(line => ({ ...trimFirstCharOfLineContent(line) })); |