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 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();

View File

@ -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"