Commit d5cf738c authored by Phil Hughes's avatar Phil Hughes

Merge branch '45120-fix-ide-editor-to-update-size-on-show-change' into 'master'

Fix IDE editor to update dimensions on show change

Closes #45120

See merge request gitlab-org/gitlab-ce!30135
parents 2f4fbca2 9e185534
...@@ -40,27 +40,36 @@ export default { ...@@ -40,27 +40,36 @@ export default {
}, },
showContentViewer() { showContentViewer() {
return ( return (
(this.shouldHideEditor || this.file.viewMode === 'preview') && (this.shouldHideEditor || this.isPreviewViewMode) &&
(this.viewer !== viewerTypes.mr || !this.file.mrChange) (this.viewer !== viewerTypes.mr || !this.file.mrChange)
); );
}, },
showDiffViewer() { showDiffViewer() {
return this.shouldHideEditor && this.file.mrChange && this.viewer === viewerTypes.mr; return this.shouldHideEditor && this.file.mrChange && this.viewer === viewerTypes.mr;
}, },
isEditorViewMode() {
return this.file.viewMode === 'editor';
},
isPreviewViewMode() {
return this.file.viewMode === 'preview';
},
editTabCSS() { editTabCSS() {
return { return {
active: this.file.viewMode === 'editor', active: this.isEditorViewMode,
}; };
}, },
previewTabCSS() { previewTabCSS() {
return { return {
active: this.file.viewMode === 'preview', active: this.isPreviewViewMode,
}; };
}, },
fileType() { fileType() {
const info = viewerInformationForPath(this.file.path); const info = viewerInformationForPath(this.file.path);
return (info && info.id) || ''; return (info && info.id) || '';
}, },
showEditor() {
return !this.shouldHideEditor && this.isEditorViewMode;
},
}, },
watch: { watch: {
file(newVal, oldVal) { file(newVal, oldVal) {
...@@ -89,7 +98,7 @@ export default { ...@@ -89,7 +98,7 @@ export default {
} }
}, },
rightPanelCollapsed() { rightPanelCollapsed() {
this.editor.updateDimensions(); this.refreshEditorDimensions();
}, },
viewer() { viewer() {
if (!this.file.pending) { if (!this.file.pending) {
...@@ -98,11 +107,17 @@ export default { ...@@ -98,11 +107,17 @@ export default {
}, },
panelResizing() { panelResizing() {
if (!this.panelResizing) { if (!this.panelResizing) {
this.editor.updateDimensions(); this.refreshEditorDimensions();
} }
}, },
rightPaneIsOpen() { rightPaneIsOpen() {
this.editor.updateDimensions(); this.refreshEditorDimensions();
},
showEditor(val) {
if (val) {
// We need to wait for the editor to actually be rendered.
this.$nextTick(() => this.refreshEditorDimensions());
}
}, },
}, },
beforeDestroy() { beforeDestroy() {
...@@ -212,6 +227,11 @@ export default { ...@@ -212,6 +227,11 @@ export default {
eol: this.model.eol, eol: this.model.eol,
}); });
}, },
refreshEditorDimensions() {
if (this.showEditor) {
this.editor.updateDimensions();
}
},
}, },
viewerTypes, viewerTypes,
}; };
...@@ -249,7 +269,7 @@ export default { ...@@ -249,7 +269,7 @@ export default {
</div> </div>
<file-templates-bar v-if="showFileTemplatesBar(file.name)" /> <file-templates-bar v-if="showFileTemplatesBar(file.name)" />
<div <div
v-show="!shouldHideEditor && file.viewMode === 'editor'" v-show="showEditor"
ref="editor" ref="editor"
:class="{ :class="{
'is-readonly': isCommitModeActive, 'is-readonly': isCommitModeActive,
......
---
title: Fix IDE editor not showing when switching back from preview
merge_request: 30135
author:
type: fixed
...@@ -14,7 +14,10 @@ describe('RepoEditor', () => { ...@@ -14,7 +14,10 @@ describe('RepoEditor', () => {
let vm; let vm;
beforeEach(done => { beforeEach(done => {
const f = file(); const f = {
...file(),
viewMode: 'editor',
};
const RepoEditor = Vue.extend(repoEditor); const RepoEditor = Vue.extend(repoEditor);
vm = createComponentWithStore(RepoEditor, store, { vm = createComponentWithStore(RepoEditor, store, {
...@@ -41,12 +44,17 @@ describe('RepoEditor', () => { ...@@ -41,12 +44,17 @@ describe('RepoEditor', () => {
Editor.editorInstance.dispose(); Editor.editorInstance.dispose();
}); });
it('renders an ide container', done => { const findEditor = () => vm.$el.querySelector('.multi-file-editor-holder');
Vue.nextTick(() => { const changeRightPanelCollapsed = () => {
expect(vm.shouldHideEditor).toBeFalsy(); const { state } = vm.$store;
done(); state.rightPanelCollapsed = !state.rightPanelCollapsed;
}); };
it('renders an ide container', () => {
expect(vm.shouldHideEditor).toBeFalsy();
expect(vm.showEditor).toBe(true);
expect(findEditor()).not.toHaveCss({ display: 'none' });
}); });
it('renders only an edit tab', done => { it('renders only an edit tab', done => {
...@@ -283,7 +291,7 @@ describe('RepoEditor', () => { ...@@ -283,7 +291,7 @@ describe('RepoEditor', () => {
}); });
it('calls updateDimensions when rightPanelCollapsed is changed', done => { it('calls updateDimensions when rightPanelCollapsed is changed', done => {
vm.$store.state.rightPanelCollapsed = true; changeRightPanelCollapsed();
vm.$nextTick(() => { vm.$nextTick(() => {
expect(vm.editor.updateDimensions).toHaveBeenCalled(); expect(vm.editor.updateDimensions).toHaveBeenCalled();
...@@ -358,6 +366,47 @@ describe('RepoEditor', () => { ...@@ -358,6 +366,47 @@ describe('RepoEditor', () => {
}); });
}); });
describe('when files view mode is preview', () => {
beforeEach(done => {
spyOn(vm.editor, 'updateDimensions');
vm.file.viewMode = 'preview';
vm.$nextTick(done);
});
it('should hide editor', () => {
expect(vm.showEditor).toBe(false);
expect(findEditor()).toHaveCss({ display: 'none' });
});
it('should not update dimensions', done => {
changeRightPanelCollapsed();
vm.$nextTick()
.then(() => {
expect(vm.editor.updateDimensions).not.toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
});
describe('when file view mode changes to editor', () => {
beforeEach(done => {
vm.file.viewMode = 'editor';
// one tick to trigger watch
vm.$nextTick()
// another tick needed until we can update dimensions
.then(() => vm.$nextTick())
.then(done)
.catch(done.fail);
});
it('should update dimensions', () => {
expect(vm.editor.updateDimensions).toHaveBeenCalled();
});
});
});
it('calls removePendingTab when old file is pending', done => { it('calls removePendingTab when old file is pending', done => {
spyOnProperty(vm, 'shouldHideEditor').and.returnValue(true); spyOnProperty(vm, 'shouldHideEditor').and.returnValue(true);
spyOn(vm, 'removePendingTab'); spyOn(vm, 'removePendingTab');
......
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