Commit 63b4b4b2 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'mr-expand-all-collapsed-files' into 'master'

Fix collapsed files not fully fully expanding

Closes #53866

See merge request gitlab-org/gitlab-ce!23019
parents 07fc2ded 8e265bc3
...@@ -32,6 +32,7 @@ export default { ...@@ -32,6 +32,7 @@ export default {
computed: { computed: {
...mapState('diffs', ['currentDiffFileId']), ...mapState('diffs', ['currentDiffFileId']),
...mapGetters(['isNotesFetched']), ...mapGetters(['isNotesFetched']),
...mapGetters('diffs', ['getDiffFileDiscussions']),
isCollapsed() { isCollapsed() {
return this.file.collapsed || false; return this.file.collapsed || false;
}, },
...@@ -57,12 +58,23 @@ export default { ...@@ -57,12 +58,23 @@ export default {
showLoadingIcon() { showLoadingIcon() {
return this.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed); return this.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed);
}, },
hasDiffLines() {
const { highlightedDiffLines, parallelDiffLines } = this.file;
return highlightedDiffLines && parallelDiffLines && parallelDiffLines.length > 0;
},
},
watch: {
'file.collapsed': function fileCollapsedWatch(newVal, oldVal) {
if (!newVal && oldVal && !this.hasDiffLines) {
this.handleLoadCollapsedDiff();
}
},
}, },
methods: { methods: {
...mapActions('diffs', ['loadCollapsedDiff', 'assignDiscussionsToDiff']), ...mapActions('diffs', ['loadCollapsedDiff', 'assignDiscussionsToDiff']),
handleToggle() { handleToggle() {
const { highlightedDiffLines, parallelDiffLines } = this.file; if (!this.hasDiffLines) {
if (!highlightedDiffLines && parallelDiffLines !== undefined && !parallelDiffLines.length) {
this.handleLoadCollapsedDiff(); this.handleLoadCollapsedDiff();
} else { } else {
this.file.collapsed = !this.file.collapsed; this.file.collapsed = !this.file.collapsed;
...@@ -81,7 +93,7 @@ export default { ...@@ -81,7 +93,7 @@ export default {
.then(() => { .then(() => {
requestIdleCallback( requestIdleCallback(
() => { () => {
this.assignDiscussionsToDiff(); this.assignDiscussionsToDiff(this.getDiffFileDiscussions(this.file));
}, },
{ timeout: 1000 }, { timeout: 1000 },
); );
......
...@@ -107,4 +107,26 @@ describe('DiffFile', () => { ...@@ -107,4 +107,26 @@ describe('DiffFile', () => {
}); });
}); });
}); });
describe('watch collapsed', () => {
it('calls handleLoadCollapsedDiff if collapsed changed & file has no lines', done => {
spyOn(vm, 'handleLoadCollapsedDiff');
vm.file.highlightedDiffLines = undefined;
vm.file.parallelDiffLines = [];
vm.file.collapsed = true;
vm.$nextTick()
.then(() => {
vm.file.collapsed = false;
return vm.$nextTick();
})
.then(() => {
expect(vm.handleLoadCollapsedDiff).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
});
});
}); });
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