From 344f6e357d6aae33426a1e1dded7faf9d380ab97 Mon Sep 17 00:00:00 2001 From: Rishabh <5862206+rishabhnambiar@users.noreply.github.com> Date: Fri, 2 Nov 2018 18:11:20 +0530 Subject: [PATCH] FEATURE: Replace combo-box with search filter (#28) * FEATURE: Replace combo-box with search filter * Delete unused listname property and css fixes * Use ES6 syntax and `@computed` decorator --- .../controllers/admin-plugins-explorer.js.es6 | 12 ++++++++++++ assets/javascripts/discourse/models/query.js.es6 | 11 ----------- .../discourse/templates/admin/plugins-explorer.hbs | 7 +++++-- assets/stylesheets/explorer.scss | 4 ++++ config/locales/client.en.yml | 3 ++- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 index c288ae0..a79e8e9 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 @@ -2,6 +2,7 @@ import showModal from "discourse/lib/show-modal"; import Query from "discourse/plugins/discourse-data-explorer/discourse/models/query"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { ajax } from "discourse/lib/ajax"; +import { default as computed } from "ember-addons/ember-computed-decorators"; const NoQuery = Query.create({ name: "No queries", fake: true }); @@ -26,6 +27,17 @@ export default Ember.Controller.extend({ sortBy: ["last_run_at:desc"], sortedQueries: Em.computed.sort("model", "sortBy"), + @computed("search") + filteredContent(search) { + const regexp = new RegExp(this.get("search")); + return this.get("sortedQueries").filter(function(result) { + return ( + regexp.test(result.get("name")) || + regexp.test(result.get("description")) + ); + }); + }, + createDisabled: function() { return (this.get("newQueryName") || "").trim().length === 0; }.property("newQueryName"), diff --git a/assets/javascripts/discourse/models/query.js.es6 b/assets/javascripts/discourse/models/query.js.es6 index 9aa9f13..15f1176 100644 --- a/assets/javascripts/discourse/models/query.js.es6 +++ b/assets/javascripts/discourse/models/query.js.es6 @@ -54,17 +54,6 @@ const Query = RestModel.extend({ ); }.property("id"), - listName: function() { - let name = this.get("name"); - if (this.get("dirty")) { - name += " (*)"; - } - if (this.get("destroyed")) { - name += " (deleted)"; - } - return name; - }.property("name", "dirty", "destroyed"), - createProperties() { if (this.get("sql")) { // Importing diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index f6fdcc9..d09000d 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -5,7 +5,7 @@ {{else}} {{#unless selectedQueryId}}
- {{combo-box valueAttribute="id" class="btn-left" value=selectedQueryId nameProperty="listName" none="explorer.menu_none" content=content castInteger="true" nameChanges="true"}} + {{text-field value=search placeholderKey="explorer.search_placeholder"}} {{d-button action="showCreate" icon="plus" class="no-text btn-right"}} {{d-button action="importQuery" label="explorer.import.label" icon="upload btn-right"}}
@@ -164,7 +164,7 @@ - {{#each sortedQueries as |query|}} + {{#each filteredContent as |query|}} @@ -191,6 +191,9 @@ {{/if}} + {{else}} +
+ {{i18n "explorer.no_search_results"}} {{/each}} diff --git a/assets/stylesheets/explorer.scss b/assets/stylesheets/explorer.scss index 0d2dc75..b3cd95b 100644 --- a/assets/stylesheets/explorer.scss +++ b/assets/stylesheets/explorer.scss @@ -236,6 +236,7 @@ .query-list { display: flex; + max-height: 30px; .btn-left { margin-right: 0.5em; } @@ -296,6 +297,9 @@ cursor: pointer; display: inline-block; } + .no-search-results { + color: $primary-medium; + } } .result-info { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index fb56b3f..8970f51 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -66,4 +66,5 @@ en: explain_label: "Include query plan?" save_params: "Set Defaults" reset_params: "Reset" - menu_none: "Select a query" + search_placeholder: "Search..." + no_search_results: "Sorry, we couldn't find any results matching your text."