DEV: Conditionally show AI results toggle based on sort order (#652)

This commit is contained in:
Keegan George 2024-05-29 18:18:22 -07:00 committed by GitHub
parent 834fea672f
commit 02a50a29f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 19 deletions

View File

@ -24,11 +24,14 @@ export default class SemanticSearch extends Component {
@tracked searching = false; @tracked searching = false;
@tracked AIResults = []; @tracked AIResults = [];
@tracked showingAIResults = false; @tracked showingAIResults = false;
@tracked preventAISearch = false;
initialSearchTerm = this.args.outletArgs.search; initialSearchTerm = this.args.outletArgs.search;
get disableToggleSwitch() { 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; 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: // Search loading:
if (this.searching) { if (this.searching) {
return I18n.t("discourse_ai.embeddings.semantic_search_loading"); return I18n.t("discourse_ai.embeddings.semantic_search_loading");
@ -88,7 +86,8 @@ export default class SemanticSearch extends Component {
get searchEnabled() { get searchEnabled() {
return ( return (
this.args.outletArgs.type === SEARCH_TYPE_DEFAULT && 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) { if (!this.searchEnabled) {
return; return;
} }
if (
this.searchPreferencesManager?.sortOrder !== undefined &&
this.searchPreferencesManager?.sortOrder !== 0
) {
this.preventAISearch = true;
return;
} else {
this.preventAISearch = false;
}
if (this.initialSearchTerm && !this.searching) { if (this.initialSearchTerm && !this.searching) {
return this.performHyDESearch(); return this.performHyDESearch();

View File

@ -295,7 +295,6 @@ en:
embeddings: embeddings:
semantic_search: "Topics (Semantic)" semantic_search: "Topics (Semantic)"
semantic_search_loading: "Searching for more results using AI" 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: semantic_search_results:
toggle: "Showing %{count} results found using AI" toggle: "Showing %{count} results found using AI"
toggle_hidden: "Hiding %{count} results found using AI" toggle_hidden: "Hiding %{count} results found using AI"