A platform for community discussion. Free, open, simple.
UI: Add the DE search table hiding mechanism back per before (#41278)
Natalie Tay26401d557a2b
diff --git a/plugins/discourse-data-explorer/admin/assets/javascripts/admin/templates/admin-plugins/show/explorer/edit.gjs b/plugins/discourse-data-explorer/admin/assets/javascripts/admin/templates/admin-plugins/show/explorer/edit.gjsindex 53535cfb75b..f5e4b575164 100644--- a/plugins/discourse-data-explorer/admin/assets/javascripts/admin/templates/admin-plugins/show/explorer/edit.gjs+++ b/plugins/discourse-data-explorer/admin/assets/javascripts/admin/templates/admin-plugins/show/explorer/edit.gjs@@ -114,7 +114,7 @@ export default class QueriesEdit extends Component {@disabled={{@controller.aiGenerating}}/>{{else}}- <div class="query-editor">+ <div class="query-editor {{if @controller.hideSchema 'no-schema'}}"><div class="query-editor__header"><h3 class="query-editor__label">{{i18n"explorer.sql_label"@@ -135,7 +135,11 @@ export default class QueriesEdit extends Component {</div><div class="right-panel">- <ExplorerSchema @schema={{@controller.schema}} />+ <ExplorerSchema+ @schema={{@controller.schema}}+ @hideSchema={{@controller.hideSchema}}+ @updateHideSchema={{@controller.updateHideSchema}}+ /></div></div>@@ -245,7 +249,7 @@ export default class QueriesEdit extends Component {<DConditionalLoadingSpinner @condition={{@controller.loading}} />{{#if (and (eq @controller.mode "ai") (eq @controller.view "sql"))}}- <div class="query-editor">+ <div class="query-editor {{if @controller.hideSchema 'no-schema'}}"><div class="query-editor__header"><h3 class="query-editor__label">{{i18n "explorer.sql_label"}}</h3></div>@@ -264,7 +268,11 @@ export default class QueriesEdit extends Component {</div><div class="right-panel">- <ExplorerSchema @schema={{@controller.schema}} />+ <ExplorerSchema+ @schema={{@controller.schema}}+ @hideSchema={{@controller.hideSchema}}+ @updateHideSchema={{@controller.updateHideSchema}}+ /></div></div>diff --git a/plugins/discourse-data-explorer/admin/assets/javascripts/admin/templates/admin-plugins/show/explorer/new.gjs b/plugins/discourse-data-explorer/admin/assets/javascripts/admin/templates/admin-plugins/show/explorer/new.gjsindex 95b6f650baf..af82fd86340 100644--- a/plugins/discourse-data-explorer/admin/assets/javascripts/admin/templates/admin-plugins/show/explorer/new.gjs+++ b/plugins/discourse-data-explorer/admin/assets/javascripts/admin/templates/admin-plugins/show/explorer/new.gjs@@ -196,7 +196,7 @@ export default <template><label class="query-new__sql-label">{{i18n "explorer.ai.sql_label"}}</label>- <div class="query-editor">+ <div class="query-editor {{if @controller.hideSchema 'no-schema'}}"><div class="panels-flex"><div class="editor-panel"><AceEditor@@ -206,7 +206,11 @@ export default <template>/></div><div class="right-panel">- <ExplorerSchema @schema={{@controller.schema}} />+ <ExplorerSchema+ @schema={{@controller.schema}}+ @hideSchema={{@controller.hideSchema}}+ @updateHideSchema={{@controller.updateHideSchema}}+ /></div></div><div class="clear"></div>diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/explorer-schema.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/explorer-schema.gjsindex 3cb43e3f1cd..fa8aaf8534a 100644--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/explorer-schema.gjs+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/explorer-schema.gjs@@ -5,6 +5,7 @@ import { action } from "@ember/object";import { isBlank, isEmpty } from "@ember/utils";import withEventValue from "discourse/helpers/with-event-value";import { debounce } from "discourse/lib/decorators";+import DButton from "discourse/ui-kit/d-button";import DConditionalLoadingSpinner from "discourse/ui-kit/d-conditional-loading-spinner";import dIcon from "discourse/ui-kit/helpers/d-icon";import { i18n } from "discourse-i18n";@@ -126,27 +127,52 @@ export default class ExplorerSchema extends Component {this.updateFilter(value);}+ @action+ collapseSchema() {+ this.args.updateHideSchema(true);+ }++ @action+ expandSchema() {+ this.args.updateHideSchema(false);+ }+<template>- <div class="schema">- <div class="schema-search">- {{dIcon "magnifying-glass" class="schema-search__icon"}}- <input- type="text"- class="schema-search__input"- placeholder={{i18n "explorer.schema.search_tables"}}- {{on "input" (withEventValue this.filterChanged)}}- />- </div>+ {{#if @hideSchema}}+ <DButton+ @action={{this.expandSchema}}+ @icon="chevron-left"+ @ariaLabel="explorer.schema.show"+ class="schema__toggle --expand no-text unhide"+ />+ {{else}}+ <div class="schema">+ <div class="schema-search">+ {{dIcon "magnifying-glass" class="schema-search__icon"}}+ <input+ type="text"+ class="schema-search__input"+ placeholder={{i18n "explorer.schema.search_tables"}}+ {{on "input" (withEventValue this.filterChanged)}}+ />+ <DButton+ @action={{this.collapseSchema}}+ @icon="chevron-right"+ @ariaLabel="explorer.schema.hide"+ class="schema__toggle --collapse no-text"+ />+ </div>- <div class="schema-container">- <DConditionalLoadingSpinner @condition={{this.loading}}>- <ul>- {{#each this.filteredTables as |table|}}- <OneTable @table={{table}} />- {{/each}}- </ul>- </DConditionalLoadingSpinner>+ <div class="schema-container">+ <DConditionalLoadingSpinner @condition={{this.loading}}>+ <ul>+ {{#each this.filteredTables as |table|}}+ <OneTable @table={{table}} />+ {{/each}}+ </ul>+ </DConditionalLoadingSpinner>+ </div></div>- </div>+ {{/if}}</template>}diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/edit.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/edit.jsindex 0ac15a0aa73..c0806abdaae 100644--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/edit.js+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/edit.js@@ -15,7 +15,8 @@ import { subscribeToAiGeneration } from "discourse/plugins/discourse-data-explorimport { defaultView } from "discourse/plugins/discourse-data-explorer/discourse/lib/chart-helpers";import Query from "discourse/plugins/discourse-data-explorer/discourse/models/query";-const viewStore = new KeyValueStore("discourse_data_explorer_");+const dataExplorerStore = new KeyValueStore("discourse_data_explorer_");+const HIDE_SCHEMA_KEY = "hide_schema";export default class PluginsExplorerController extends Controller {@service modal;@@ -31,6 +32,7 @@ export default class PluginsExplorerController extends Controller {@tracked results = this.model.results;@tracked dirty = false;@tracked isCachedResult = false;+ @tracked hideSchema = dataExplorerStore.get(HIDE_SCHEMA_KEY) === "true";@tracked view = "table";@tracked mode = "manual";@tracked aiPrompt = "";@@ -164,7 +166,7 @@ export default class PluginsExplorerController extends Controller {initView() {const queryId = this.model?.id;- const stored = queryId ? viewStore.get(`view_${queryId}`) : null;+ const stored = queryId ? dataExplorerStore.get(`view_${queryId}`) : null;const validViews =this.mode === "ai" ? ["chart", "table", "sql"] : ["chart", "table"];if (validViews.includes(stored)) {@@ -181,10 +183,16 @@ export default class PluginsExplorerController extends Controller {this.view = value;const queryId = this.model?.id;if (queryId) {- viewStore.set({ key: `view_${queryId}`, value });+ dataExplorerStore.set({ key: `view_${queryId}`, value });}}+ @action+ updateHideSchema(value) {+ this.hideSchema = value;+ dataExplorerStore.set({ key: HIDE_SCHEMA_KEY, value: value.toString() });+ }+@actionsetMode(value) {this.mode = value;diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/new.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/new.jsindex ad79b7c6284..84b7bc1b3bc 100644--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/new.js+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/new.js@@ -4,10 +4,14 @@ import { action } from "@ember/object";import { service } from "@ember/service";import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";+import KeyValueStore from "discourse/lib/key-value-store";import I18n, { i18n } from "discourse-i18n";import { subscribeToAiGeneration } from "discourse/plugins/discourse-data-explorer/discourse/lib/ai-generation";import { defaultView } from "discourse/plugins/discourse-data-explorer/discourse/lib/chart-helpers";+const dataExplorerStore = new KeyValueStore("discourse_data_explorer_");+const HIDE_SCHEMA_KEY = "hide_schema";+export default class AdminPluginsExplorerNew extends Controller {@service store;@service router;@@ -24,6 +28,7 @@ export default class AdminPluginsExplorerNew extends Controller {@tracked generatedDescription = "";@tracked mode = "ai";@tracked schema = null;+ @tracked hideSchema = dataExplorerStore.get(HIDE_SCHEMA_KEY) === "true";@tracked manualSql = "SELECT 1";@tracked previewLoading = false;@tracked previewResults = null;@@ -98,6 +103,12 @@ export default class AdminPluginsExplorerNew extends Controller {this.manualSql = value;}+ @action+ updateHideSchema(value) {+ this.hideSchema = value;+ dataExplorerStore.set({ key: HIDE_SCHEMA_KEY, value: value.toString() });+ }+@actionasync create({ name, description }) {try {@@ -280,6 +291,7 @@ export default class AdminPluginsExplorerNew extends Controller {this.generatedDescription = "";this.mode = "ai";this.schema = null;+ this.hideSchema = dataExplorerStore.get(HIDE_SCHEMA_KEY) === "true";this.manualSql = "SELECT 1";this.loading = false;this.manualFormData = { name: "", description: "" };diff --git a/plugins/discourse-data-explorer/assets/stylesheets/explorer.scss b/plugins/discourse-data-explorer/assets/stylesheets/explorer.scssindex 8a969026aa5..61a7a956b18 100644--- a/plugins/discourse-data-explorer/assets/stylesheets/explorer.scss+++ b/plugins/discourse-data-explorer/assets/stylesheets/explorer.scss@@ -145,6 +145,7 @@ table.group-reports {--width: 345px;flex-shrink: 0;flex-grow: 0;+ position: relative;width: var(--width);@include viewport.until(sm) {@@ -203,6 +204,10 @@ table.group-reports {}}+ .schema__toggle {+ flex: 0 0 auto;+ }+.schema-table-name {font-weight: bold;border-bottom: 1px solid var(--primary-low);@@ -292,6 +297,23 @@ table.group-reports {}}+ &.no-schema {+ .editor-panel {+ flex-basis: 100%;+ }++ .right-panel {+ width: 0;+ }++ .schema__toggle.--expand {+ position: absolute;+ inset-block-start: var(--space-2);+ inset-inline-start: -2.75em;+ z-index: 1;+ }+ }+.grippie {cursor: nwse-resize;padding-bottom: var(--space-2);diff --git a/plugins/discourse-data-explorer/config/locales/client.en.yml b/plugins/discourse-data-explorer/config/locales/client.en.ymlindex 88555911833..60b07b2b165 100644--- a/plugins/discourse-data-explorer/config/locales/client.en.yml+++ b/plugins/discourse-data-explorer/config/locales/client.en.yml@@ -90,6 +90,8 @@ en:title: "Database Schema"filter: "Search..."search_tables: "Search tables"+ hide: "Hide schema"+ show: "Show schema"sensitive: "The contents of this column may contain particularly sensitive or private information. Please exercise caution when using the contents of this column."types:bool:diff --git a/plugins/discourse-data-explorer/test/javascripts/acceptance/new-query-test.js b/plugins/discourse-data-explorer/test/javascripts/acceptance/new-query-test.jsindex 19206971c63..3a420ef7d26 100644--- a/plugins/discourse-data-explorer/test/javascripts/acceptance/new-query-test.js+++ b/plugins/discourse-data-explorer/test/javascripts/acceptance/new-query-test.js@@ -1,5 +1,6 @@import { click, currentURL, fillIn, settled, visit } from "@ember/test-helpers";import { test } from "qunit";+import KeyValueStore from "discourse/lib/key-value-store";import {acceptance,publishToMessageBus,@@ -9,6 +10,12 @@ acceptance("New Query", function (needs) {needs.user();needs.settings({ data_explorer_enabled: true });+ const dataExplorerStore = new KeyValueStore("discourse_data_explorer_");++ needs.hooks.afterEach(() => {+ dataExplorerStore.remove("hide_schema");+ });+needs.pretender((server, helper) => {server.get("/admin/plugins/discourse-data-explorer.json", () => {return helper.response({@@ -101,6 +108,12 @@ acceptance("New Query", function (needs) {.dom(".query-new__manual-form .editor-panel .ace-wrapper").exists("SQL editor renders alongside the schema sidebar");+ await click(".query-new__manual-form .schema__toggle.--collapse");++ assert+ .dom(".query-new__manual-form .schema-search__input")+ .doesNotExist("schema sidebar can be hidden");+await fillIn(".query-new__manual-form [data-name='name'] input", "foo");await fillIn(".query-new__manual-form [data-name='description'] textarea",@@ -112,6 +125,26 @@ acceptance("New Query", function (needs) {currentURL(),"/admin/plugins/discourse-data-explorer/queries/-15");++ assert+ .dom(".query-editor.no-schema .schema__toggle.--expand")+ .exists("schema hidden state persists across Data Explorer pages");+ });++ test("starts with the schema hidden when the preference is stored", async function (assert) {+ dataExplorerStore.set({ key: "hide_schema", value: "true" });++ await visit("/admin/plugins/discourse-data-explorer/queries/new");++ assert+ .dom(".query-new__manual-form .query-editor.no-schema")+ .exists("stored hidden state is applied");+ assert+ .dom(".query-new__manual-form .schema-search__input")+ .doesNotExist("schema search is hidden");+ assert+ .dom(".query-new__manual-form .schema__toggle.--expand")+ .exists("schema can still be shown again");});});diff --git a/plugins/discourse-data-explorer/test/javascripts/components/explorer-schema-test.gjs b/plugins/discourse-data-explorer/test/javascripts/components/explorer-schema-test.gjsindex 196c0e6b178..549da1bac71 100644--- a/plugins/discourse-data-explorer/test/javascripts/components/explorer-schema-test.gjs+++ b/plugins/discourse-data-explorer/test/javascripts/components/explorer-schema-test.gjs@@ -1,4 +1,4 @@-import { fillIn, render } from "@ember/test-helpers";+import { click, fillIn, render } from "@ember/test-helpers";import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import ExplorerSchema from "discourse/plugins/discourse-data-explorer/discourse/components/explorer-schema";@@ -54,4 +54,40 @@ module("Component | ExplorerSchema", function (hooks) {assert.dom(".schema-table").doesNotExist();});++ test("can be hidden and shown again", async function (assert) {+ this.setProperties({+ schema,+ hideSchema: false,+ updateHideSchema: (value) => this.set("hideSchema", value),+ });++ await render(+ <template>+ <ExplorerSchema+ @schema={{this.schema}}+ @hideSchema={{this.hideSchema}}+ @updateHideSchema={{this.updateHideSchema}}+ />+ </template>+ );++ assert.dom(".schema-search__input").exists("search input is visible");+ assert+ .dom(".schema__toggle.--collapse")+ .hasAttribute("aria-label", "Hide schema");++ await click(".schema__toggle.--collapse");++ assert.dom(".schema-search__input").doesNotExist("search input is hidden");+ assert.dom(".schema-table").doesNotExist("schema tables are hidden");+ assert+ .dom(".schema__toggle.--expand")+ .hasAttribute("aria-label", "Show schema");++ await click(".schema__toggle.--expand");++ assert.dom(".schema-search__input").exists("search input is visible again");+ assert.dom(".schema-table").exists("schema tables are visible again");+ });});