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 {
computed: {
...mapState('diffs', ['currentDiffFileId']),
...mapGetters(['isNotesFetched']),
...mapGetters('diffs', ['getDiffFileDiscussions']),
isCollapsed() {
return this.file.collapsed || false;
},
......@@ -57,12 +58,23 @@ export default {
showLoadingIcon() {
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: {
...mapActions('diffs', ['loadCollapsedDiff', 'assignDiscussionsToDiff']),
handleToggle() {
const { highlightedDiffLines, parallelDiffLines } = this.file;
if (!highlightedDiffLines && parallelDiffLines !== undefined && !parallelDiffLines.length) {
if (!this.hasDiffLines) {
this.handleLoadCollapsedDiff();
} else {
this.file.collapsed = !this.file.collapsed;
......@@ -81,7 +93,7 @@ export default {
.then(() => {
requestIdleCallback(
() => {
this.assignDiscussionsToDiff();
this.assignDiscussionsToDiff(this.getDiffFileDiscussions(this.file));
},
{ timeout: 1000 },
);
......
......@@ -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