Update the state, not a param
Also fixed a bug where discussions wouldn't be assigned to a line when switching from discussion tab to changes tab
This commit is contained in:
parent
80a689fab8
commit
0fba7cca36
|
@ -63,7 +63,7 @@ export default {
|
|||
plainDiffPath: state => state.diffs.plainDiffPath,
|
||||
emailPatchPath: state => state.diffs.emailPatchPath,
|
||||
}),
|
||||
...mapState('diffs', ['showTreeList']),
|
||||
...mapState('diffs', ['showTreeList', 'isLoading']),
|
||||
...mapGetters('diffs', ['isParallelView']),
|
||||
...mapGetters(['isNotesFetched', 'getNoteableData']),
|
||||
targetBranch() {
|
||||
|
@ -152,7 +152,7 @@ export default {
|
|||
}
|
||||
},
|
||||
setDiscussions() {
|
||||
if (this.isNotesFetched && !this.assignedDiscussions) {
|
||||
if (this.isNotesFetched && !this.assignedDiscussions && !this.isLoading) {
|
||||
requestIdleCallback(
|
||||
() =>
|
||||
this.assignDiscussionsToDiff().then(() => {
|
||||
|
|
|
@ -37,29 +37,13 @@ export const fetchDiffFiles = ({ state, commit }) => {
|
|||
// once for parallel and once for inline mode
|
||||
export const assignDiscussionsToDiff = (
|
||||
{ commit, state, rootState },
|
||||
discussionsToAssign = rootState.notes.discussions,
|
||||
discussions = rootState.notes.discussions,
|
||||
) => {
|
||||
const diffPositionByLineCode = getDiffPositionByLineCode(state.diffFiles);
|
||||
const discussionsByDiffFile = discussionsToAssign
|
||||
.filter(discussion => discussion.diff_discussion)
|
||||
.reduce((acc, discussion) => {
|
||||
const discussions = (
|
||||
acc[discussion.diff_file.file_hash] || { discussions: [] }
|
||||
).discussions.concat(discussion);
|
||||
|
||||
return {
|
||||
...acc,
|
||||
[discussion.diff_file.file_hash]: {
|
||||
diffFile: state.diffFiles.find(file => file.fileHash === discussion.diff_file.file_hash),
|
||||
discussions,
|
||||
},
|
||||
};
|
||||
}, {});
|
||||
|
||||
Object.values(discussionsByDiffFile).forEach(({ discussions, diffFile }) => {
|
||||
discussions.filter(discussion => discussion.diff_discussion).forEach(discussion => {
|
||||
commit(types.SET_LINE_DISCUSSIONS_FOR_FILE, {
|
||||
diffFile,
|
||||
discussions,
|
||||
discussion,
|
||||
diffPositionByLineCode,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -90,11 +90,11 @@ export default {
|
|||
}));
|
||||
},
|
||||
|
||||
[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, { diffFile, discussions, diffPositionByLineCode }) {
|
||||
[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, { discussion, diffPositionByLineCode }) {
|
||||
const { latestDiff } = state;
|
||||
|
||||
discussions.forEach(discussion => {
|
||||
const discussionLineCode = discussion.line_code;
|
||||
const fileHash = discussion.diff_file.file_hash;
|
||||
const lineCheck = ({ lineCode }) =>
|
||||
lineCode === discussionLineCode &&
|
||||
isDiscussionApplicableToLine({
|
||||
|
@ -103,36 +103,53 @@ export default {
|
|||
latestDiff,
|
||||
});
|
||||
|
||||
if (diffFile.highlightedDiffLines) {
|
||||
const line = diffFile.highlightedDiffLines.find(lineCheck);
|
||||
state.diffFiles = state.diffFiles.map(diffFile => {
|
||||
if (diffFile.fileHash === fileHash) {
|
||||
const file = { ...diffFile };
|
||||
|
||||
if (line) {
|
||||
Object.assign(line, {
|
||||
if (file.highlightedDiffLines) {
|
||||
file.highlightedDiffLines = file.highlightedDiffLines.map(line => {
|
||||
if (lineCheck(line)) {
|
||||
return {
|
||||
...line,
|
||||
discussions: line.discussions.concat(discussion),
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (diffFile.parallelDiffLines) {
|
||||
const { left, right } = diffFile.parallelDiffLines.find(
|
||||
parallelLine =>
|
||||
(parallelLine.left && lineCheck(parallelLine.left)) ||
|
||||
(parallelLine.right && lineCheck(parallelLine.right)),
|
||||
);
|
||||
const line = left && left.lineCode === discussionLineCode ? left : right;
|
||||
|
||||
if (line) {
|
||||
Object.assign(line, {
|
||||
discussions: line.discussions.concat(discussion),
|
||||
return line;
|
||||
});
|
||||
}
|
||||
|
||||
if (file.parallelDiffLines) {
|
||||
file.parallelDiffLines = file.parallelDiffLines.map(line => {
|
||||
const left = line.left && lineCheck(line.left);
|
||||
const right = line.right && lineCheck(line.right);
|
||||
|
||||
if (left || right) {
|
||||
return {
|
||||
left: {
|
||||
...line.left,
|
||||
discussions: left ? line.left.discussions.concat(discussion) : [],
|
||||
},
|
||||
right: {
|
||||
...line.right,
|
||||
discussions: right ? line.right.discussions.concat(discussion) : [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (!diffFile.parallelDiffLines || !diffFile.highlightedDiffLines) {
|
||||
Object.assign(diffFile, {
|
||||
discussions: diffFile.discussions.concat(discussion),
|
||||
return line;
|
||||
});
|
||||
}
|
||||
|
||||
if (!file.parallelDiffLines || !file.highlightedDiffLines) {
|
||||
file.discussions = file.discussions.concat(discussion);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
return diffFile;
|
||||
});
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue