feat(UI): resize query editor area

This commit is contained in:
Fabio Di Stasio 2021-01-31 13:03:25 +01:00
parent 5940b0b842
commit 88ab7c5a62
2 changed files with 43 additions and 2 deletions

View File

@ -212,7 +212,7 @@ export default {
mounted () { mounted () {
const resizer = this.$refs.resizer; const resizer = this.$refs.resizer;
resizer.addEventListener('mousedown', (e) => { resizer.addEventListener('mousedown', e => {
e.preventDefault(); e.preventDefault();
window.addEventListener('mousemove', this.resize); window.addEventListener('mousemove', this.resize);

View File

@ -3,11 +3,14 @@
<div class="workspace-query-runner column col-12"> <div class="workspace-query-runner column col-12">
<QueryEditor <QueryEditor
v-if="isSelected" v-if="isSelected"
ref="queryEditor"
:auto-focus="true" :auto-focus="true"
:value.sync="query" :value.sync="query"
:workspace="workspace" :workspace="workspace"
:schema="schema" :schema="schema"
:height="editorHeight"
/> />
<div ref="resizer" class="query-area-resizer" />
<div class="workspace-query-runner-footer"> <div class="workspace-query-runner-footer">
<div class="workspace-query-buttons"> <div class="workspace-query-buttons">
<button <button
@ -80,7 +83,8 @@ export default {
isQuering: false, isQuering: false,
results: [], results: [],
resultsCount: 0, resultsCount: 0,
affectedCount: 0 affectedCount: 0,
editorHeight: 200
}; };
}, },
computed: { computed: {
@ -94,6 +98,16 @@ export default {
created () { created () {
window.addEventListener('keydown', this.onKey); window.addEventListener('keydown', this.onKey);
}, },
mounted () {
const resizer = this.$refs.resizer;
resizer.addEventListener('mousedown', e => {
e.preventDefault();
window.addEventListener('mousemove', this.resize);
window.addEventListener('mouseup', this.stopResize);
});
},
beforeDestroy () { beforeDestroy () {
window.removeEventListener('keydown', this.onKey); window.removeEventListener('keydown', this.onKey);
}, },
@ -139,6 +153,21 @@ export default {
this.resultsCount = 0; this.resultsCount = 0;
this.affectedCount = 0; this.affectedCount = 0;
}, },
resize (e) {
const el = this.$refs.queryEditor.$el;
let editorHeight = e.pageY - el.getBoundingClientRect().top;
if (editorHeight > 400) editorHeight = 400;
if (editorHeight < 50) editorHeight = 50;
this.editorHeight = editorHeight;
},
stopResize () {
window.removeEventListener('mousemove', this.resize);
if (this.$refs.queryTable && this.results.length)
this.$refs.queryTable.resizeResults();
if (this.$refs.queryEditor)
this.$refs.queryEditor.editor.resize();
},
onKey (e) { onKey (e) {
if (this.isSelected) { if (this.isSelected) {
e.stopPropagation(); e.stopPropagation();
@ -155,11 +184,23 @@ export default {
align-content: baseline; align-content: baseline;
.workspace-query-runner { .workspace-query-runner {
position: relative;
.query-area-resizer {
position: absolute;
height: 5px;
bottom: 40px;
width: 100%;
cursor: ns-resize;
z-index: 99;
}
.workspace-query-runner-footer { .workspace-query-runner-footer {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding: 0.3rem 0.6rem 0.4rem; padding: 0.3rem 0.6rem 0.4rem;
align-items: center; align-items: center;
height: 42px;
.workspace-query-buttons { .workspace-query-buttons {
display: flex; display: flex;