From 2abeebac579c910fa7b682777811b30f3da36b07 Mon Sep 17 00:00:00 2001 From: Lhc_fl Date: Mon, 2 Sep 2024 10:09:34 +0800 Subject: [PATCH 1/2] UX: Automatically convert to lowercase in explorer-schema In the past, ExplorerSchema searches were case-sensitive, so if the user's input method capitalized the first letter, it was likely that no results would be found. The new change allows you to enter uppercase letters, which will automatically be converted to lowercase when searching. meta topic: https://meta.discourse.org/t/can-the-data-explorer-search-input-be-converted-to-lower-case/323435 --- .../discourse/components/explorer-schema.js | 2 +- .../components/explorer-schema-test.js | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/javascripts/components/explorer-schema-test.js diff --git a/assets/javascripts/discourse/components/explorer-schema.js b/assets/javascripts/discourse/components/explorer-schema.js index bc6fccff..ee4b2d8e 100644 --- a/assets/javascripts/discourse/components/explorer-schema.js +++ b/assets/javascripts/discourse/components/explorer-schema.js @@ -114,7 +114,7 @@ export default class ExplorerSchema extends Component { @debounce(500) updateFilter(value) { - this.filter = value; + this.filter = value.toLowerCase(); this.loading = false; } diff --git a/test/javascripts/components/explorer-schema-test.js b/test/javascripts/components/explorer-schema-test.js new file mode 100644 index 00000000..4d1dafe8 --- /dev/null +++ b/test/javascripts/components/explorer-schema-test.js @@ -0,0 +1,60 @@ +import { fillIn, render } from "@ember/test-helpers"; +import hbs from "htmlbars-inline-precompile"; +import { module, test } from "qunit"; +import { setupRenderingTest } from "discourse/tests/helpers/component-test"; + +const schema = { + posts: [ + { + column_name: "id", + data_type: "serial", + primary: true, + notes: "primary key", + havetypeinfo: true, + }, + { + column_name: "raw", + data_type: "text", + column_desc: "The raw Markdown that the user entered into the composer.", + havepopup: true, + havetypeinfo: true, + }, + ], + categories: [ + { + column_name: "id", + data_type: "serial", + primary: true, + notes: "primary key", + havetypeinfo: true, + }, + { + column_name: "name", + data_type: "varchar(50)", + havetypeinfo: false, + }, + ], +}; + +module("Data Explorer Plugin | Component | explorer-schema", function (hooks) { + setupRenderingTest(hooks); + + test("will automatically convert to lowercase", async function (assert) { + this.setProperties({ + schema, + hideSchema: false, + updateHideSchema: () => {}, + }); + + await render(hbs` + `); + + await fillIn(`.schema-search input`, "Cat"); + + assert.dom(".schema-table").exists(); + }); +}); From 55b32c9a0d9a8bfe31ff07488160a2567972110d Mon Sep 17 00:00:00 2001 From: Lhc_fl Date: Mon, 2 Sep 2024 10:16:35 +0800 Subject: [PATCH 2/2] more test --- test/javascripts/components/explorer-schema-test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/javascripts/components/explorer-schema-test.js b/test/javascripts/components/explorer-schema-test.js index 4d1dafe8..f741b797 100644 --- a/test/javascripts/components/explorer-schema-test.js +++ b/test/javascripts/components/explorer-schema-test.js @@ -56,5 +56,9 @@ module("Data Explorer Plugin | Component | explorer-schema", function (hooks) { await fillIn(`.schema-search input`, "Cat"); assert.dom(".schema-table").exists(); + + await fillIn(`.schema-search input`, "NotExist"); + + assert.dom(".schema-table").doesNotExist(); }); });