Upgrade explorer-schema onetable/enum to Octane (#203)

* Upgrade explorer-schema onetable/enum to Octane
This commit is contained in:
Isaac Janzen 2022-12-20 10:30:43 -06:00 committed by GitHub
parent 147bfec207
commit cf365f7df2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 97 deletions

View File

@ -1,18 +0,0 @@
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({
tagName: "ol",
@discourseComputed("col.enum")
enuminfo(hash) {
let result = [];
for (let key in hash) {
if (!hash.hasOwnProperty(key)) {
continue;
}
result.push({ value: key, name: hash[key] });
}
return result;
},
});

View File

@ -1,25 +0,0 @@
import Component from "@ember/component";
import { on } from "discourse-common/utils/decorators";
import { reads } from "@ember/object/computed";
export default Component.extend({
classNameBindings: [":schema-table", "open"],
tagName: "li",
open: reads("table.open"),
@on("didInsertElement")
_bindClicks() {
$(this.element)
.find(".schema-table-name")
.click((e) => {
this.set("table.open", !this.table.open);
e.preventDefault();
});
},
@on("willDestroyElement")
_cleanup() {
$(this.element).find(".schema-table-name").off("click");
},
});

View File

@ -25,7 +25,7 @@
<div class="schema-container">
<ul>
{{#each this.filteredTables as |table|}}
{{explorer-schema-onetable table=table}}
<ExplorerSchema::OneTable @table={{table}} />
{{/each}}
</ul>
</div>

View File

@ -0,0 +1,7 @@
<ol>
{{#each this.enuminfo as |enum|}}
<li value={{enum.value}}>
{{enum.name}}
</li>
{{/each}}
</ol>

View File

@ -0,0 +1,10 @@
import Component from "@glimmer/component";
export default class EnumInfo extends Component {
get enuminfo() {
return Object.entries(this.args.col.enum).map(([value, name]) => ({
value,
name,
}));
}
}

View File

@ -0,0 +1,50 @@
<li class="schema-table {{this.styles}}" {{on "click" this.toggleOpen}}>
<div class="schema-table-name">
{{#if this.open}}
{{d-icon "caret-down"}}
{{else}}
{{d-icon "caret-right"}}
{{/if}}
{{@table.name}}
</div>
<div class="schema-table-cols">
{{#if this.open}}
<dl>
{{#each @table.columns as |col|}}
<div>
<dt
class={{if col.sensitive "sensitive"}}
title={{if col.sensitive (i18n "explorer.schema.sensitive")}}
>
{{#if col.sensitive}}
{{d-icon "exclamation-triangle"}}
{{/if}}
{{col.column_name}}
</dt>
<dd>
{{col.data_type}}
{{#if col.havetypeinfo}}
<br />
{{#if col.havepopup}}
<div class="popup-info">
{{d-icon "info"}}
<div class="popup">
{{col.column_desc}}
{{#if col.enum}}
<ExplorerSchema::EnumInfo @col={{col}} />
{{/if}}
</div>
</div>
{{/if}}
<span class="schema-typenotes">
{{col.notes}}
</span>
{{/if}}
</dd>
</div>
{{/each}}
</dl>
{{/if}}
</div>
</li>

View File

@ -0,0 +1,16 @@
import Component from "@glimmer/component";
import { bind } from "discourse-common/utils/decorators";
import { tracked } from "@glimmer/tracking";
export default class OneTable extends Component {
@tracked open = this.args.table.open;
get styles() {
return this.open ? "open" : "";
}
@bind
toggleOpen() {
this.open = !this.open;
}
}

View File

@ -1,5 +0,0 @@
{{#each enuminfo as |enum|}}
<li value={{enum.value}}>
{{enum.name}}
</li>
{{/each}}

View File

@ -1,48 +0,0 @@
<div class="schema-table-name">
{{#if open}}
{{d-icon "caret-down"}}
{{else}}
{{d-icon "caret-right"}}
{{/if}}
{{table.name}}
</div>
<div class="schema-table-cols">
{{#if open}}
<dl>
{{#each table.columns as |col|}}
<div>
<dt
class={{if col.sensitive "sensitive"}}
title={{if col.sensitive (i18n "explorer.schema.sensitive")}}
>
{{#if col.sensitive}}
{{d-icon "exclamation-triangle"}}
{{/if}}
{{col.column_name}}
</dt>
<dd>
{{col.data_type}}
{{#if col.havetypeinfo}}
<br>
{{#if col.havepopup}}
<div class="popup-info">
{{d-icon "info"}}
<div class="popup">
{{col.column_desc}}
{{#if col.enum}}
{{explorer-schema-enuminfo col=col}}
{{/if}}
</div>
</div>
{{/if}}
<span class="schema-typenotes">
{{col.notes}}
</span>
{{/if}}
</dd>
</div>
{{/each}}
</dl>
{{/if}}
</div>