Commit 8e265bc3 authored by Phil Hughes's avatar Phil Hughes

Fix collapsed files not fully fully expanding

This fixes files that are collapsed by default not expanding
when the expand all button is clicked.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/53866
parent 4bda46a1
......@@ -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