UX: make SQL editor resizable (#33)

This commit is contained in:
Osama Sayegh 2019-04-07 09:05:43 +03:00 committed by GitHub
parent 83a2c96fe4
commit 859021bb3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 46 deletions

1
.gitignore vendored
View File

@ -5,5 +5,6 @@ auto_generated
Gemfile.lock Gemfile.lock
.DS_Store .DS_Store
*.swp *.swp
*.swo
.rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml .rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml

View File

@ -15,45 +15,64 @@ export default Ember.Component.extend({
if (this._state !== "inDOM") { if (this._state !== "inDOM") {
return; return;
} }
const $editPane = this.$().find(".query-editor"); const $editPane = this.$(".query-editor");
if (!$editPane.length) { if (!$editPane.length) {
return; return;
} }
const oldGrippie = this.get("grippie"); const oldGrippie = this.get("grippie");
if (oldGrippie) { if (oldGrippie) {
oldGrippie.off("mousedown mousemove mouseup"); oldGrippie.off("mousedown mousemove mouseup");
$editPane.off("mousemove mouseup");
} }
const $grippie = $editPane.find(".grippie"); const $grippie = $editPane.find(".grippie");
const $targets = $editPane.find(".ace-wrapper,.grippie-target"); const $target = $editPane.find(".panels-flex");
const $body = $("body"); const $document = Ember.$(document);
const self = this;
const minWidth = $target.width();
const minHeight = $target.height();
this.set("grippie", $grippie); this.set("grippie", $grippie);
const mousemove = function(e) { const mousemove = e => {
const diff = self.get("startY") - e.screenY; const diffY = this.get("startY") - e.screenY;
const newHeight = self.get("startSize") - diff; const diffX = this.get("startX") - e.screenX;
$targets.height(newHeight);
self.appEvents.trigger("ace:resize"); const newHeight = Math.max(minHeight, this.get("startHeight") - diffY);
const newWidth = Math.max(minWidth, this.get("startWidth") - diffX);
$target.height(newHeight);
$target.width(newWidth);
$grippie.width(newWidth);
this.appEvents.trigger("ace:resize");
}; };
let mouseup; const throttledMousemove = (event => {
mouseup = function(e) { event.preventDefault();
mousemove(e); Ember.run.throttle(this, mousemove, event, 20);
$body.off("mousemove", mousemove); }).bind(this);
$body.off("mouseup", mouseup);
self.set("startY", null);
self.set("startSize", null);
};
$grippie.on("mousedown", function(e) { const mouseup = (e => {
self.set("startY", e.screenY); $document.off("mousemove", throttledMousemove);
self.set("startSize", $targets.height()); $document.off("mouseup", mouseup);
this.setProperties({
startY: null,
startX: null,
startHeight: null,
startWidth: null
});
}).bind(this);
$body.on("mousemove", mousemove); $grippie.on("mousedown", e => {
$body.on("mouseup", mouseup); this.setProperties({
startY: e.screenY,
startX: e.screenX,
startHeight: $target.height(),
startWidth: $target.width()
});
$document.on("mousemove", throttledMousemove);
$document.on("mouseup", mouseup);
e.preventDefault(); e.preventDefault();
}); });
}, },

View File

@ -2,9 +2,6 @@ import debounce from "discourse/lib/debounce";
export default Ember.Component.extend({ export default Ember.Component.extend({
actions: { actions: {
expandSchema() {
this.set("hideSchema", false);
},
collapseSchema() { collapseSchema() {
this.set("hideSchema", true); this.set("hideSchema", true);
} }

View File

@ -96,6 +96,10 @@ export default Ember.Controller.extend({
actions: { actions: {
dummy() {}, dummy() {},
expandSchema() {
this.set("hideSchema", false);
},
importQuery() { importQuery() {
showModal("import-query"); showModal("import-query");
this.set("showCreate", false); this.set("showCreate", false);

View File

@ -55,15 +55,22 @@
{{! the SQL editor will show the first time you }} {{! the SQL editor will show the first time you }}
{{#if everEditing}} {{#if everEditing}}
<div class="query-editor {{if hideSchema "no-schema"}}"> <div class="query-editor {{if hideSchema "no-schema"}}">
<div class="right-panel"> <div class="panels-flex">
<div class="schema grippie-target">
{{explorer-schema schema=schema hideSchema=hideSchema}}
</div>
</div>
<div class="editor-panel"> <div class="editor-panel">
{{ace-editor content=selectedItem.sql mode="sql"}} {{ace-editor content=selectedItem.sql mode="sql"}}
</div> </div>
<div class="grippie"></div> <div class="right-panel">
{{#if hideSchema}}
{{d-button action=(action "expandSchema") icon="chevron-left" class="no-text unhide"}}
{{/if}}
<div class="schema">
{{explorer-schema schema=schema hideSchema=hideSchema}}
</div>
</div>
</div>
<div class="grippie">
{{d-icon "discourse-expand"}}
</div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
{{else}} {{else}}

View File

@ -1,6 +1,3 @@
{{#if hideSchema}}
{{d-button action=(action "expandSchema") icon="chevron-left" class="no-text unhide"}}
{{/if}}
<div class="{{if hideSchema "hidden"}}"> <div class="{{if hideSchema "hidden"}}">
{{text-field value=filter placeholderKey="explorer.schema.filter"}} {{text-field value=filter placeholderKey="explorer.schema.filter"}}
{{d-button action=(action "collapseSchema") icon="chevron-right" class="no-text"}} {{d-button action=(action "collapseSchema") icon="chevron-right" class="no-text"}}

View File

@ -3,13 +3,12 @@
} }
.query-editor { .query-editor {
border: 1px solid $primary-very-low;
margin-bottom: 15px; margin-bottom: 15px;
.editor-panel {
width: 65%; .panels-flex {
} display: flex;
.right-panel { height: 400px;
width: 35%; border: 1px solid $primary-very-low;
} }
&.no-schema { &.no-schema {
.editor-panel { .editor-panel {
@ -19,17 +18,20 @@
width: 0; width: 0;
button.unhide { button.unhide {
position: absolute; position: absolute;
margin-left: -31px; margin-left: -53px;
z-index: 1; z-index: 1;
} }
.schema {
display: none;
}
} }
} }
.editor-panel { .editor-panel {
float: left; flex-grow: 1;
.ace-wrapper { .ace-wrapper {
position: relative; position: relative;
height: 400px; height: 100%;
width: 100%; width: 100%;
} }
.ace_editor { .ace_editor {
@ -41,10 +43,12 @@
} }
} }
.right-panel { .right-panel {
float: right; flex-shrink: 0;
flex-grow: 0;
width: 300px;
.schema { .schema {
border-left: 1px solid $primary-low; border-left: 1px solid $primary-low;
height: 400px; height: 100%;
overflow-y: scroll; overflow-y: scroll;
overflow-x: hidden; overflow-x: hidden;
color: $primary-high; color: $primary-high;
@ -135,8 +139,17 @@
} }
} }
.grippie { .grippie {
cursor: nwse-resize;
clear: both; clear: both;
font-size: $font-down-2;
-webkit-user-select: none; -webkit-user-select: none;
color: $primary;
text-align: right;
background: $primary-very-low;
border: 1px solid $primary-very-low;
.d-icon {
transform: rotate(90deg);
}
} }
} }