diff options
author | Phil Hughes <me@iamphill.com> | 2018-09-14 16:51:25 +0100 |
---|---|---|
committer | André Luís <aluis@gitlab.com> | 2018-09-21 11:59:41 +0100 |
commit | 2497c29ef0d1e178c8b3aa96e8304ee6765bae4e (patch) | |
tree | af895b8945ee8f7ae88c18826385538f10cb171e /app/assets/javascripts/diffs/store/actions.js | |
parent | 2036458e150db2840dbb1219f1cb5e079b648deb (diff) | |
download | gitlab-ce-2497c29ef0d1e178c8b3aa96e8304ee6765bae4e.tar.gz |
Use returned discussion from API
We now use the returned discussion instead of re-fetching
all of the discussions and filtering out the ones we don't need.
This speeds up the process of creating a diff discussions
by saving us another API request before we can render the discussion
Diffstat (limited to 'app/assets/javascripts/diffs/store/actions.js')
-rw-r--r-- | app/assets/javascripts/diffs/store/actions.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js index e60bb9dd7e3..98d8d5943f9 100644 --- a/app/assets/javascripts/diffs/store/actions.js +++ b/app/assets/javascripts/diffs/store/actions.js @@ -1,9 +1,12 @@ import Vue from 'vue'; import axios from '~/lib/utils/axios_utils'; import Cookies from 'js-cookie'; +import createFlash from '~/flash'; +import { s__ } from '~/locale'; import { handleLocationHash, historyPushState } from '~/lib/utils/common_utils'; import { mergeUrlParams, getLocationHash } from '~/lib/utils/url_utility'; -import { getDiffPositionByLineCode } from './utils'; +import { reduceDiscussionsToLineCodes } from '../../notes/stores/utils'; +import { getDiffPositionByLineCode, getNoteFormData } from './utils'; import * as types from './mutation_types'; import { PARALLEL_DIFF_VIEW_TYPE, @@ -178,5 +181,19 @@ export const toggleFileDiscussions = ({ getters, dispatch }, diff) => { }); }; +export const saveDiffDiscussion = ({ dispatch }, { note, formData }) => { + const postData = getNoteFormData({ + note, + ...formData, + }); + + return dispatch('saveNote', postData, { root: true }) + .then(result => dispatch('updateDiscussion', result.discussion, { root: true })) + .then(discussion => + dispatch('assignDiscussionsToDiff', reduceDiscussionsToLineCodes([discussion])), + ) + .catch(() => createFlash(s__('MergeRequests|Saving the comment failed'))); +}; + // prevent babel-plugin-rewire from generating an invalid default during karma tests export default () => {}; |