From 02a50a29f8bc42caf70fd474a34166bf305e86db Mon Sep 17 00:00:00 2001 From: Keegan George Date: Wed, 29 May 2024 18:18:22 -0700 Subject: [PATCH] DEV: Conditionally show AI results toggle based on sort order (#652) --- .../semantic-search.gjs | 24 ++++++------------- config/locales/client.en.yml | 3 +-- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/assets/javascripts/discourse/connectors/full-page-search-below-search-header/semantic-search.gjs b/assets/javascripts/discourse/connectors/full-page-search-below-search-header/semantic-search.gjs index 8e6b91ed..c9eec103 100644 --- a/assets/javascripts/discourse/connectors/full-page-search-below-search-header/semantic-search.gjs +++ b/assets/javascripts/discourse/connectors/full-page-search-below-search-header/semantic-search.gjs @@ -24,11 +24,14 @@ export default class SemanticSearch extends Component { @tracked searching = false; @tracked AIResults = []; @tracked showingAIResults = false; - @tracked preventAISearch = false; initialSearchTerm = this.args.outletArgs.search; get disableToggleSwitch() { - if (this.searching || this.AIResults.length === 0 || this.preventAISearch) { + if ( + this.searching || + this.AIResults.length === 0 || + this.args.outletArgs.sortOrder !== 0 + ) { return true; } } @@ -53,11 +56,6 @@ export default class SemanticSearch extends Component { } } - // Search disabled for sort order: - if (this.preventAISearch) { - return I18n.t("discourse_ai.embeddings.semantic_search_disabled_sort"); - } - // Search loading: if (this.searching) { return I18n.t("discourse_ai.embeddings.semantic_search_loading"); @@ -88,7 +86,8 @@ export default class SemanticSearch extends Component { get searchEnabled() { return ( this.args.outletArgs.type === SEARCH_TYPE_DEFAULT && - isValidSearchTerm(this.searchTerm, this.siteSettings) + isValidSearchTerm(this.searchTerm, this.siteSettings) && + this.args.outletArgs.sortOrder === 0 ); } @@ -114,15 +113,6 @@ export default class SemanticSearch extends Component { if (!this.searchEnabled) { return; } - if ( - this.searchPreferencesManager?.sortOrder !== undefined && - this.searchPreferencesManager?.sortOrder !== 0 - ) { - this.preventAISearch = true; - return; - } else { - this.preventAISearch = false; - } if (this.initialSearchTerm && !this.searching) { return this.performHyDESearch(); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 4c1a57be..132fad8b 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -215,7 +215,7 @@ en: confirm_delete: Are you sure you want to delete this model? delete: Delete - tests: + tests: title: "Run Test" running: "Running test..." success: "Success!" @@ -295,7 +295,6 @@ en: embeddings: semantic_search: "Topics (Semantic)" semantic_search_loading: "Searching for more results using AI" - semantic_search_disabled_sort: "AI Search disabled for this sort order, sort by Relevance to enable." semantic_search_results: toggle: "Showing %{count} results found using AI" toggle_hidden: "Hiding %{count} results found using AI"