Upgrade `explorer-schema` to Octane (#202)
* Upgrade `explorer-schema` to Octane
This commit is contained in:
parent
8028b9f16a
commit
7d1a9d487d
|
@ -0,0 +1,34 @@
|
||||||
|
{{#if this.hideSchema}}
|
||||||
|
<DButton
|
||||||
|
@action={{this.expandSchema}}
|
||||||
|
@icon="chevron-left"
|
||||||
|
@class="no-text unhide"
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<div class="schema">
|
||||||
|
<div class={{if this.hideSchema "hidden"}}>
|
||||||
|
<div class="schema-search inline-form full-width">
|
||||||
|
<TextField
|
||||||
|
@value={{this.filter}}
|
||||||
|
@onChange={{this.filterChanged}}
|
||||||
|
@placeholderKey="explorer.schema.filter"
|
||||||
|
/>
|
||||||
|
<DButton
|
||||||
|
@action={{this.collapseSchema}}
|
||||||
|
@icon="chevron-right"
|
||||||
|
@class="no-text"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ConditionalLoadingSpinner @condition={{this.loading}}>
|
||||||
|
<div class="schema-container">
|
||||||
|
<ul>
|
||||||
|
{{#each this.filteredTables as |table|}}
|
||||||
|
{{explorer-schema-onetable table=table}}
|
||||||
|
{{/each}}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</ConditionalLoadingSpinner>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -1,18 +1,17 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@glimmer/component";
|
||||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
import { debounce } from "discourse-common/utils/decorators";
|
||||||
import discourseDebounce from "discourse-common/lib/debounce";
|
|
||||||
import { isBlank, isEmpty } from "@ember/utils";
|
import { isBlank, isEmpty } from "@ember/utils";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
import { tracked } from "@glimmer/tracking";
|
||||||
|
|
||||||
export default Component.extend({
|
export default class ExplorerSchema extends Component {
|
||||||
actions: {
|
@tracked filter;
|
||||||
collapseSchema() {
|
@tracked loading;
|
||||||
this.set("hideSchema", true);
|
@tracked hideSchema = this.args.hideSchema;
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
@discourseComputed("schema")
|
get transformedSchema() {
|
||||||
transformedSchema(schema) {
|
const schema = this.args.schema;
|
||||||
for (let key in schema) {
|
for (const key in schema) {
|
||||||
if (!schema.hasOwnProperty(key)) {
|
if (!schema.hasOwnProperty(key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -48,28 +47,30 @@ export default Component.extend({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return schema;
|
return schema;
|
||||||
},
|
|
||||||
|
|
||||||
@discourseComputed("filter")
|
|
||||||
rfilter(filter) {
|
|
||||||
if (!isBlank(filter)) {
|
|
||||||
return new RegExp(filter);
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
filterTables(schema) {
|
get filteredTables() {
|
||||||
let tables = [];
|
let tables = [];
|
||||||
const filter = this.rfilter,
|
let filter = this.filter;
|
||||||
haveFilter = !!filter;
|
|
||||||
|
|
||||||
for (let key in schema) {
|
try {
|
||||||
if (!schema.hasOwnProperty(key)) {
|
if (!isBlank(this.filter)) {
|
||||||
|
filter = new RegExp(this.filter);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
filter = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const haveFilter = !!filter;
|
||||||
|
|
||||||
|
for (const key in this.transformedSchema) {
|
||||||
|
if (!this.transformedSchema.hasOwnProperty(key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!haveFilter) {
|
if (!haveFilter) {
|
||||||
tables.push({
|
tables.push({
|
||||||
name: key,
|
name: key,
|
||||||
columns: schema[key],
|
columns: this.transformedSchema[key],
|
||||||
open: false,
|
open: false,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
|
@ -79,20 +80,20 @@ export default Component.extend({
|
||||||
if (filter.source === key || filter.source + "s" === key) {
|
if (filter.source === key || filter.source + "s" === key) {
|
||||||
tables.unshift({
|
tables.unshift({
|
||||||
name: key,
|
name: key,
|
||||||
columns: schema[key],
|
columns: this.transformedSchema[key],
|
||||||
open: haveFilter,
|
open: haveFilter,
|
||||||
});
|
});
|
||||||
} else if (filter.test(key)) {
|
} else if (filter.test(key)) {
|
||||||
// whole table matches
|
// whole table matches
|
||||||
tables.push({
|
tables.push({
|
||||||
name: key,
|
name: key,
|
||||||
columns: schema[key],
|
columns: this.transformedSchema[key],
|
||||||
open: haveFilter,
|
open: haveFilter,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// filter the columns
|
// filter the columns
|
||||||
let filterCols = [];
|
let filterCols = [];
|
||||||
schema[key].forEach((col) => {
|
this.transformedSchema[key].forEach((col) => {
|
||||||
if (filter.source === col.column_name) {
|
if (filter.source === col.column_name) {
|
||||||
filterCols.unshift(col);
|
filterCols.unshift(col);
|
||||||
} else if (filter.test(col.column_name)) {
|
} else if (filter.test(col.column_name)) {
|
||||||
|
@ -109,29 +110,29 @@ export default Component.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tables;
|
return tables;
|
||||||
},
|
}
|
||||||
|
|
||||||
@observes("filter")
|
@debounce(500)
|
||||||
triggerFilter() {
|
updateFilter(value) {
|
||||||
discourseDebounce(
|
this.filter = value;
|
||||||
this,
|
this.loading = false;
|
||||||
function () {
|
}
|
||||||
this.set("filteredTables", this.filterTables(this.transformedSchema));
|
|
||||||
this.set("loading", false);
|
|
||||||
},
|
|
||||||
500
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
@observes("filter")
|
@action
|
||||||
setLoading() {
|
filterChanged(value) {
|
||||||
this.set("loading", true);
|
this.loading = true;
|
||||||
},
|
this.updateFilter(value);
|
||||||
|
}
|
||||||
|
|
||||||
init() {
|
@action
|
||||||
this._super(...arguments);
|
collapseSchema() {
|
||||||
|
this.hideSchema = true;
|
||||||
|
this.args.updateHideSchema(true);
|
||||||
|
}
|
||||||
|
|
||||||
this.set("loading", true);
|
@action
|
||||||
this.triggerFilter();
|
expandSchema() {
|
||||||
},
|
this.hideSchema = false;
|
||||||
});
|
this.args.updateHideSchema(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -175,10 +175,8 @@ export default Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
dummy() {},
|
updateHideSchema(value) {
|
||||||
|
this.set("hideSchema", value);
|
||||||
expandSchema() {
|
|
||||||
this.set("hideSchema", false);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
import(files) {
|
import(files) {
|
||||||
|
|
|
@ -119,17 +119,11 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="right-panel">
|
<div class="right-panel">
|
||||||
{{#if hideSchema}}
|
<ExplorerSchema
|
||||||
{{d-button
|
@schema={{schema}}
|
||||||
action=(action "expandSchema")
|
@hideSchema={{hideSchema}}
|
||||||
icon="chevron-left"
|
@updateHideSchema={{action "updateHideSchema"}}
|
||||||
class="no-text unhide"
|
/>
|
||||||
}}
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<div class="schema">
|
|
||||||
{{explorer-schema schema=schema hideSchema=hideSchema}}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
<div class={{if hideSchema "hidden"}}>
|
|
||||||
<div class="schema-search inline-form full-width">
|
|
||||||
{{text-field value=filter placeholderKey="explorer.schema.filter"}}
|
|
||||||
{{d-button
|
|
||||||
action=(action "collapseSchema")
|
|
||||||
icon="chevron-right"
|
|
||||||
class="no-text"
|
|
||||||
}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{conditional-loading-spinner condition=loading}}
|
|
||||||
|
|
||||||
<div class="schema-container">
|
|
||||||
<ul>
|
|
||||||
{{#each filteredTables as |table|}}
|
|
||||||
{{explorer-schema-onetable table=table}}
|
|
||||||
{{/each}}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
Loading…
Reference in New Issue