summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorTim Zallmann <tzallmann@gitlab.com>2018-09-07 17:13:11 +0200
committerTim Zallmann <tzallmann@gitlab.com>2018-09-07 17:13:11 +0200
commitd2cbe07398c3f824ffecbd78ff5749daca678d3e (patch)
tree80db47a1f53e1333b6252d14e314bb6a758f158e /app/assets/javascripts
parentd4d5ed59f98eb3218418c385327224d2512e518e (diff)
downloadgitlab-ce-d2cbe07398c3f824ffecbd78ff5749daca678d3e.tar.gz
Adapted so utils + actions don't include any mutations and mutations are always against state
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/diffs/store/actions.js58
-rw-r--r--app/assets/javascripts/diffs/store/mutation_types.js4
-rw-r--r--app/assets/javascripts/diffs/store/mutations.js72
-rw-r--r--app/assets/javascripts/notes/stores/mutations.js7
-rw-r--r--app/assets/javascripts/notes/stores/utils.js4
5 files changed, 78 insertions, 67 deletions
diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js
index 44ae0f2f17b..184a90c6033 100644
--- a/app/assets/javascripts/diffs/store/actions.js
+++ b/app/assets/javascripts/diffs/store/actions.js
@@ -31,66 +31,18 @@ export const fetchDiffFiles = ({ state, commit }) => {
// This is adding line discussions to the actual lines in the diff tree
// once for parallel and once for inline mode
-export const assignDiscussionsToDiff = ({ state, commit }, allLineDiscussions) => {
+export const assignDiscussionsToDiff = ({ commit }, allLineDiscussions) => {
Object.values(allLineDiscussions).forEach(discussions => {
if (discussions.length > 0) {
const { fileHash } = discussions[0];
- const selectedFile = state.diffFiles.find(file => file.fileHash === fileHash);
- if (selectedFile) {
- const targetLine = selectedFile.parallelDiffLines.find(
- line =>
- (line.left && line.left.lineCode === discussions[0].line_code) ||
- (line.right && line.right.lineCode === discussions[0].line_code),
- );
- if (targetLine) {
- if (targetLine.left && targetLine.left.lineCode === discussions[0].line_code) {
- commit(types.SET_LINE_DISCUSSIONS, { line: targetLine.left, discussions });
- } else {
- commit(types.SET_LINE_DISCUSSIONS, { line: targetLine.right, discussions });
- }
- }
-
- if (selectedFile.highlightedDiffLines) {
- const targetInlineLine = selectedFile.highlightedDiffLines.find(
- line => line.lineCode === discussions[0].line_code,
- );
-
- if (targetInlineLine) {
- commit(types.SET_LINE_DISCUSSIONS, { line: targetInlineLine, discussions });
- }
- }
- }
+ commit(types.SET_LINE_DISCUSSIONS_FOR_FILE, { fileHash, discussions });
}
});
};
-export const removeDiscussionsFromDiff = ({ state, commit }, removeDiscussion) => {
- const { fileHash } = removeDiscussion;
- const selectedFile = state.diffFiles.find(file => file.fileHash === fileHash);
-
- if (selectedFile) {
- const targetLine = selectedFile.parallelDiffLines.find(
- line =>
- (line.left && line.left.lineCode === removeDiscussion.line_code) ||
- (line.right && line.right.lineCode === removeDiscussion.line_code),
- );
-
- if (targetLine) {
- if (targetLine.left && targetLine.left.lineCode === removeDiscussion.line_code) {
- commit(types.REMOVE_LINE_DISCUSSIONS, targetLine.left);
- } else {
- commit(types.REMOVE_LINE_DISCUSSIONS, targetLine.right);
- }
- }
-
- const targetInlineLine = selectedFile.highlightedDiffLines.find(
- line => line.lineCode === removeDiscussion.line_code,
- );
-
- if (targetInlineLine) {
- commit(types.REMOVE_LINE_DISCUSSIONS, targetInlineLine);
- }
- }
+export const removeDiscussionsFromDiff = ({ commit }, removeDiscussion) => {
+ const { fileHash, line_code } = removeDiscussion;
+ commit(types.REMOVE_LINE_DISCUSSIONS_FOR_FILE, { fileHash, lineCode: line_code });
};
export const startRenderDiffsQueue = ({ state, commit }) => {
diff --git a/app/assets/javascripts/diffs/store/mutation_types.js b/app/assets/javascripts/diffs/store/mutation_types.js
index 80f2807682a..f61efbe6e1e 100644
--- a/app/assets/javascripts/diffs/store/mutation_types.js
+++ b/app/assets/javascripts/diffs/store/mutation_types.js
@@ -9,5 +9,5 @@ export const ADD_CONTEXT_LINES = 'ADD_CONTEXT_LINES';
export const ADD_COLLAPSED_DIFFS = 'ADD_COLLAPSED_DIFFS';
export const EXPAND_ALL_FILES = 'EXPAND_ALL_FILES';
export const RENDER_FILE = 'RENDER_FILE';
-export const SET_LINE_DISCUSSIONS = 'SET_LINE_DISCUSSIONS';
-export const REMOVE_LINE_DISCUSSIONS = 'REMOVE_LINE_DISCUSSIONS';
+export const SET_LINE_DISCUSSIONS_FOR_FILE = 'SET_LINE_DISCUSSIONS_FOR_FILE';
+export const REMOVE_LINE_DISCUSSIONS_FOR_FILE = 'REMOVE_LINE_DISCUSSIONS_FOR_FILE';
diff --git a/app/assets/javascripts/diffs/store/mutations.js b/app/assets/javascripts/diffs/store/mutations.js
index 1dd43f7857a..6fce8ed5df3 100644
--- a/app/assets/javascripts/diffs/store/mutations.js
+++ b/app/assets/javascripts/diffs/store/mutations.js
@@ -84,15 +84,71 @@ export default {
}));
},
- [types.SET_LINE_DISCUSSIONS](state, { line, discussions }) {
- Object.assign(line, {
- discussions,
- });
+ [types.SET_LINE_DISCUSSIONS_FOR_FILE](state, { fileHash, discussions }) {
+ const selectedFile = state.diffFiles.find(f => f.fileHash === fileHash);
+ if (selectedFile) {
+ const targetLine = selectedFile.parallelDiffLines.find(
+ line =>
+ (line.left && line.left.lineCode === discussions[0].line_code) ||
+ (line.right && line.right.lineCode === discussions[0].line_code),
+ );
+ if (targetLine) {
+ if (targetLine.left && targetLine.left.lineCode === discussions[0].line_code) {
+ Object.assign(targetLine.left, {
+ discussions,
+ });
+ } else {
+ Object.assign(targetLine.right, {
+ discussions,
+ });
+ }
+ }
+
+ if (selectedFile.highlightedDiffLines) {
+ const targetInlineLine = selectedFile.highlightedDiffLines.find(
+ line => line.lineCode === discussions[0].line_code,
+ );
+
+ if (targetInlineLine) {
+ Object.assign(targetInlineLine, {
+ discussions,
+ });
+ }
+ }
+ }
},
- [types.REMOVE_LINE_DISCUSSIONS](state, line) {
- Object.assign(line, {
- discussions: [],
- });
+ [types.REMOVE_LINE_DISCUSSIONS_FOR_FILE](state, { fileHash, lineCode }) {
+ const selectedFile = state.diffFiles.find(f => f.fileHash === fileHash);
+ if (selectedFile) {
+ const targetLine = selectedFile.parallelDiffLines.find(
+ line =>
+ (line.left && line.left.lineCode === lineCode) ||
+ (line.right && line.right.lineCode === lineCode),
+ );
+ if (targetLine) {
+ if (targetLine.left && targetLine.left.lineCode === lineCode) {
+ Object.assign(targetLine.left, {
+ discussions: [],
+ });
+ } else {
+ Object.assign(targetLine.right, {
+ discussions: [],
+ });
+ }
+ }
+
+ if (selectedFile.highlightedDiffLines) {
+ const targetInlineLine = selectedFile.highlightedDiffLines.find(
+ line => line.lineCode === lineCode,
+ );
+
+ if (targetInlineLine) {
+ Object.assign(targetInlineLine, {
+ discussions: [],
+ });
+ }
+ }
+ }
},
};
diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js
index 8e1da818e3b..2c04bfea122 100644
--- a/app/assets/javascripts/notes/stores/mutations.js
+++ b/app/assets/javascripts/notes/stores/mutations.js
@@ -99,6 +99,10 @@ export default {
const discussions = [];
discussionsData.forEach(discussion => {
+ if (discussion.diff_file) {
+ Object.assign(discussion, { fileHash: discussion.diff_file.file_hash });
+ }
+
// To support legacy notes, should be very rare case.
if (discussion.individual_note && discussion.notes.length > 1) {
discussion.notes.forEach(n => {
@@ -186,6 +190,9 @@ export default {
const note = noteData;
const selectedDiscussion = state.discussions.find(disc => disc.id === note.id);
note.expanded = true; // override expand flag to prevent collapse
+ if (note.diff_file) {
+ Object.assign(note, { fileHash: note.diff_file.file_hash });
+ }
Object.assign(selectedDiscussion, { ...note });
},
diff --git a/app/assets/javascripts/notes/stores/utils.js b/app/assets/javascripts/notes/stores/utils.js
index 7608790d042..8ccbdb4c130 100644
--- a/app/assets/javascripts/notes/stores/utils.js
+++ b/app/assets/javascripts/notes/stores/utils.js
@@ -30,10 +30,6 @@ export const reduceDiscussionsToLineCodes = selectedDiscussions =>
if (note.diff_discussion && note.line_code && note.resolvable) {
// For context about line notes: there might be multiple notes with the same line code
const items = acc[note.line_code] || [];
- if (note.diff_file) {
- // Object.assign(note, { fileHash: note.diff_file.file_hash });
- }
-
items.push(note);
Object.assign(acc, { [note.line_code]: items });