UX: Full page search -- always show tooltip & add msg (#1051)

This commit is contained in:
Mark VanLandingham 2025-01-08 09:05:30 -06:00 committed by GitHub
parent 749af40fad
commit 327adbde29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 26 deletions

View File

@ -9,7 +9,7 @@ import { SEARCH_TYPE_DEFAULT } from "discourse/controllers/full-page-search";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { isValidSearchTerm, translateResults } from "discourse/lib/search"; import { isValidSearchTerm, translateResults } from "discourse/lib/search";
import icon from "discourse-common/helpers/d-icon"; import icon from "discourse-common/helpers/d-icon";
import I18n, { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
import DTooltip from "float-kit/components/d-tooltip"; import DTooltip from "float-kit/components/d-tooltip";
import AiIndicatorWave from "./ai-indicator-wave"; import AiIndicatorWave from "./ai-indicator-wave";
@ -64,26 +64,26 @@ export default class AiFullPageSearch extends Component {
get searchStateText() { get searchStateText() {
if (!this.validSearchOrder) { if (!this.validSearchOrder) {
return I18n.t( return i18n(
"discourse_ai.embeddings.semantic_search_results.unavailable" "discourse_ai.embeddings.semantic_search_results.unavailable"
); );
} }
// Search loading: // Search loading:
if (this.searching) { if (this.searching) {
return I18n.t("discourse_ai.embeddings.semantic_search_loading"); return i18n("discourse_ai.embeddings.semantic_search_loading");
} }
// We have results and we are showing them // We have results and we are showing them
if (this.AiResults.length && this.showingAiResults) { if (this.AiResults.length && this.showingAiResults) {
return I18n.t("discourse_ai.embeddings.semantic_search_results.toggle", { return i18n("discourse_ai.embeddings.semantic_search_results.toggle", {
count: this.AiResults.length, count: this.AiResults.length,
}); });
} }
// We have results but are hiding them // We have results but are hiding them
if (this.AiResults.length && !this.showingAiResults) { if (this.AiResults.length && !this.showingAiResults) {
return I18n.t( return i18n(
"discourse_ai.embeddings.semantic_search_results.toggle_hidden", "discourse_ai.embeddings.semantic_search_results.toggle_hidden",
{ {
count: this.AiResults.length, count: this.AiResults.length,
@ -96,12 +96,12 @@ export default class AiFullPageSearch extends Component {
this.AiResults.length === 0 && this.AiResults.length === 0 &&
this.searchTerm !== this.initialSearchTerm this.searchTerm !== this.initialSearchTerm
) { ) {
return I18n.t("discourse_ai.embeddings.semantic_search_results.new"); return i18n("discourse_ai.embeddings.semantic_search_results.new");
} }
// No results: // No results:
if (this.AiResults.length === 0) { if (this.AiResults.length === 0) {
return I18n.t("discourse_ai.embeddings.semantic_search_results.none"); return i18n("discourse_ai.embeddings.semantic_search_results.none");
} }
} }
@ -121,6 +121,14 @@ export default class AiFullPageSearch extends Component {
); );
} }
get tooltipText() {
return i18n(
`discourse_ai.embeddings.semantic_search_tooltips.${
this.validSearchOrder ? "results_explanation" : "invalid_sort"
}`
);
}
@action @action
toggleAiResults() { toggleAiResults() {
if (this.showingAiResults) { if (this.showingAiResults) {
@ -201,22 +209,17 @@ export default class AiFullPageSearch extends Component {
<AiIndicatorWave @loading={{this.searching}} /> <AiIndicatorWave @loading={{this.searching}} />
{{/if}} {{/if}}
{{#unless this.validSearchOrder}} <DTooltip
@identifier="semantic-search-tooltip"
<DTooltip class="semantic-search__tooltip"
@identifier="semantic-search-unavailable-tooltip" >
class="semantic-search__unavailable-tooltip" <:trigger>
> {{icon "far-circle-question"}}
<:trigger> </:trigger>
{{icon "far-circle-question"}} <:content>
</:trigger> {{this.tooltipText}}
<:content> </:content>
{{i18n </DTooltip>
"discourse_ai.embeddings.semantic_search_unavailable_tooltip"
}}
</:content>
</DTooltip>
{{/unless}}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
import Component from "@glimmer/component"; import Component from "@glimmer/component";
import AiSemanticSearch from "../../components/ai-full-page-search"; import AiFullPageSearch from "../../components/ai-full-page-search";
export default class AiFullPageSearchConnector extends Component { export default class AiFullPageSearchConnector extends Component {
static shouldRender(_args, { siteSettings }) { static shouldRender(_args, { siteSettings }) {
@ -7,7 +7,7 @@ export default class AiFullPageSearchConnector extends Component {
} }
<template> <template>
<AiSemanticSearch <AiFullPageSearch
@sortOrder={{@outletArgs.sortOrder}} @sortOrder={{@outletArgs.sortOrder}}
@searchTerm={{@outletArgs.search}} @searchTerm={{@outletArgs.search}}
@searchType={{@outletArgs.type}} @searchType={{@outletArgs.type}}

View File

@ -29,8 +29,9 @@
margin-left: 8px; margin-left: 8px;
} }
&__unavailable-tooltip { &__tooltip {
margin-left: 4px; margin-left: 4px;
font-size: var(--font-down-1);
} }
} }

View File

@ -486,6 +486,10 @@ en:
none: "Sorry, our AI search found no matching topics" none: "Sorry, our AI search found no matching topics"
new: "Press 'search' to begin looking for new results with AI" new: "Press 'search' to begin looking for new results with AI"
unavailable: "AI results unavailable" unavailable: "AI results unavailable"
semantic_search_tooltips:
results_explanation: "When enabled, additional AI search results will be added below."
invalid_sort: "Search results must be sorted by Relevance to display AI results"
semantic_search_unavailable_tooltip:
semantic_search_unavailable_tooltip: "Search results must be sorted by Relevance to display AI results" semantic_search_unavailable_tooltip: "Search results must be sorted by Relevance to display AI results"
ai_generated_result: "Search result found using AI" ai_generated_result: "Search result found using AI"
quick_search: quick_search: