Commit 2d02e88b authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'tor/defect/file-viewed-reviews/convert-to-vuex' into 'master'

Resolve "Mark as viewed stays checked in Single File Mode"

See merge request gitlab-org/gitlab!55922
parents 3e2b3e16 3f329d56
...@@ -125,7 +125,7 @@ export default { ...@@ -125,7 +125,7 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
mrReviews: { rehydratedMrReviews: {
type: Object, type: Object,
required: false, required: false,
default: () => ({}), default: () => ({}),
...@@ -164,6 +164,7 @@ export default { ...@@ -164,6 +164,7 @@ export default {
'canMerge', 'canMerge',
'hasConflicts', 'hasConflicts',
'viewDiffsFileByFile', 'viewDiffsFileByFile',
'mrReviews',
]), ]),
...mapGetters('diffs', ['whichCollapsedTypes', 'isParallelView', 'currentDiffIndex']), ...mapGetters('diffs', ['whichCollapsedTypes', 'isParallelView', 'currentDiffIndex']),
...mapGetters(['isNotesFetched', 'getNoteableData']), ...mapGetters(['isNotesFetched', 'getNoteableData']),
...@@ -268,7 +269,7 @@ export default { ...@@ -268,7 +269,7 @@ export default {
showSuggestPopover: this.showSuggestPopover, showSuggestPopover: this.showSuggestPopover,
viewDiffsFileByFile: fileByFile(this.fileByFileUserPreference), viewDiffsFileByFile: fileByFile(this.fileByFileUserPreference),
defaultSuggestionCommitMessage: this.defaultSuggestionCommitMessage, defaultSuggestionCommitMessage: this.defaultSuggestionCommitMessage,
mrReviews: this.mrReviews || {}, mrReviews: this.rehydratedMrReviews,
}); });
if (this.shouldShow) { if (this.shouldShow) {
...@@ -513,7 +514,7 @@ export default { ...@@ -513,7 +514,7 @@ export default {
v-for="(file, index) in diffs" v-for="(file, index) in diffs"
:key="file.newPath" :key="file.newPath"
:file="file" :file="file"
:reviewed="fileReviews[index]" :reviewed="fileReviews[file.id]"
:is-first-file="index === 0" :is-first-file="index === 0"
:is-last-file="index === diffFilesLength - 1" :is-last-file="index === diffFilesLength - 1"
:help-page-path="helpPagePath" :help-page-path="helpPagePath"
......
...@@ -150,6 +150,11 @@ export default { ...@@ -150,6 +150,11 @@ export default {
}, },
}, },
watch: { watch: {
'file.id': {
handler: function fileIdHandler() {
this.manageViewedEffects();
},
},
'file.file_hash': { 'file.file_hash': {
handler: function hashChangeWatch(newHash, oldHash) { handler: function hashChangeWatch(newHash, oldHash) {
this.isCollapsed = isCollapsed(this.file); this.isCollapsed = isCollapsed(this.file);
...@@ -186,9 +191,7 @@ export default { ...@@ -186,9 +191,7 @@ export default {
this.postRender(); this.postRender();
} }
if (this.reviewed && !this.isCollapsed && this.showLocalFileReviews) { this.manageViewedEffects();
this.handleToggle();
}
}, },
beforeDestroy() { beforeDestroy() {
eventHub.$off(EVT_EXPAND_ALL_FILES, this.expandAllListener); eventHub.$off(EVT_EXPAND_ALL_FILES, this.expandAllListener);
...@@ -200,6 +203,11 @@ export default { ...@@ -200,6 +203,11 @@ export default {
'setRenderIt', 'setRenderIt',
'setFileCollapsedByUser', 'setFileCollapsedByUser',
]), ]),
manageViewedEffects() {
if (this.reviewed && !this.isCollapsed && this.showLocalFileReviews) {
this.handleToggle();
}
},
expandAllListener() { expandAllListener() {
if (this.isCollapsed) { if (this.isCollapsed) {
this.handleToggle(); this.handleToggle();
......
...@@ -124,7 +124,7 @@ export default function initDiffsApp(store) { ...@@ -124,7 +124,7 @@ export default function initDiffsApp(store) {
showSuggestPopover: this.showSuggestPopover, showSuggestPopover: this.showSuggestPopover,
fileByFileUserPreference: this.viewDiffsFileByFile, fileByFileUserPreference: this.viewDiffsFileByFile,
defaultSuggestionCommitMessage: this.defaultSuggestionCommitMessage, defaultSuggestionCommitMessage: this.defaultSuggestionCommitMessage,
mrReviews: getReviewsForMergeRequest(mrPath), rehydratedMrReviews: getReviewsForMergeRequest(mrPath),
}, },
}); });
}, },
......
...@@ -9,7 +9,12 @@ export function isFileReviewed(reviews, file) { ...@@ -9,7 +9,12 @@ export function isFileReviewed(reviews, file) {
} }
export function reviewStatuses(files, reviews) { export function reviewStatuses(files, reviews) {
return files.map((file) => isFileReviewed(reviews, file)); return files.reduce((flat, file) => {
return {
...flat,
[file.id]: isFileReviewed(reviews, file),
};
}, {});
} }
export function getReviewsForMergeRequest(mrPath) { export function getReviewsForMergeRequest(mrPath) {
......
---
title: Fix 'viewed' checkbox in single-file view mode
merge_request: 55922
author:
type: fixed
...@@ -49,11 +49,11 @@ describe('File Review(s) utilities', () => { ...@@ -49,11 +49,11 @@ describe('File Review(s) utilities', () => {
it.each` it.each`
mrReviews | files | fileReviews mrReviews | files | fileReviews
${{}} | ${[file1, file2]} | ${[false, false]} ${{}} | ${[file1, file2]} | ${{ 123: false, '098': false }}
${{ abc: ['123'] }} | ${[file1, file2]} | ${[true, false]} ${{ abc: ['123'] }} | ${[file1, file2]} | ${{ 123: true, '098': false }}
${{ abc: ['098'] }} | ${[file1, file2]} | ${[false, true]} ${{ abc: ['098'] }} | ${[file1, file2]} | ${{ 123: false, '098': true }}
${{ def: ['123'] }} | ${[file1, file2]} | ${[false, false]} ${{ def: ['123'] }} | ${[file1, file2]} | ${{ 123: false, '098': false }}
${{ abc: ['123'], def: ['098'] }} | ${[]} | ${[]} ${{ abc: ['123'], def: ['098'] }} | ${[]} | ${{}}
`( `(
'returns $fileReviews based on the diff files in state and the existing reviews $reviews', 'returns $fileReviews based on the diff files in state and the existing reviews $reviews',
({ mrReviews, files, fileReviews }) => { ({ mrReviews, files, fileReviews }) => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment