summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-09-14 16:51:25 +0100
committerAndré Luís <aluis@gitlab.com>2018-09-21 11:59:41 +0100
commit2497c29ef0d1e178c8b3aa96e8304ee6765bae4e (patch)
treeaf895b8945ee8f7ae88c18826385538f10cb171e /app/assets/javascripts/notes
parent2036458e150db2840dbb1219f1cb5e079b648deb (diff)
downloadgitlab-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/notes')
-rw-r--r--app/assets/javascripts/notes/stores/actions.js22
-rw-r--r--app/assets/javascripts/notes/stores/mutations.js3
2 files changed, 7 insertions, 18 deletions
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js
index 68df63b8539..62b36f300ff 100644
--- a/app/assets/javascripts/notes/stores/actions.js
+++ b/app/assets/javascripts/notes/stores/actions.js
@@ -44,23 +44,11 @@ export const fetchDiscussions = ({ commit }, path) =>
commit(types.SET_INITIAL_DISCUSSIONS, discussions);
});
-export const refetchDiscussionById = ({ commit, state }, { path, discussionId }) =>
- new Promise(resolve => {
- service
- .fetchDiscussions(path)
- .then(res => res.json())
- .then(discussions => {
- const selectedDiscussion = discussions.find(discussion => discussion.id === discussionId);
- if (selectedDiscussion) {
- commit(types.UPDATE_DISCUSSION, selectedDiscussion);
- // We need to refetch as it is now the transformed one in state
- const discussion = utils.findNoteObjectById(state.discussions, discussionId);
-
- resolve(discussion);
- }
- })
- .catch(() => {});
- });
+export const updateDiscussion = ({ commit }, discussion) => {
+ commit(types.UPDATE_DISCUSSION, discussion);
+
+ return discussion;
+};
export const deleteNote = ({ commit, dispatch }, note) =>
service.deleteNote(note.path).then(() => {
diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js
index f1242a0d8be..73e55705f39 100644
--- a/app/assets/javascripts/notes/stores/mutations.js
+++ b/app/assets/javascripts/notes/stores/mutations.js
@@ -4,7 +4,8 @@ import * as constants from '../constants';
import { isInMRPage } from '../../lib/utils/common_utils';
export default {
- [types.ADD_NEW_NOTE](state, note) {
+ [types.ADD_NEW_NOTE](state, data) {
+ const note = data.discussion ? data.discussion.notes[0] : data;
const { discussion_id, type } = note;
const [exists] = state.discussions.filter(n => n.id === note.discussion_id);
const isDiscussion = type === constants.DISCUSSION_NOTE || type === constants.DIFF_NOTE;