From 8a982beae924ba0e94326aa94aa318baf1f4f88d Mon Sep 17 00:00:00 2001 From: Linca <41134017+Lhcfl@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:02:36 +0800 Subject: [PATCH] UX: Automatically convert to lowercase in explorer-schema (#325) * 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 | 64 +++++++++++++++++++ 2 files changed, 65 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 bc6fccf..ee4b2d8 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 0000000..f741b79 --- /dev/null +++ b/test/javascripts/components/explorer-schema-test.js @@ -0,0 +1,64 @@ +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(); + + await fillIn(`.schema-search input`, "NotExist"); + + assert.dom(".schema-table").doesNotExist(); + }); +});