FIX: Make recent search items populate input with value (#25704)

- Make clicking a recent search item populate the search input with said value
- Don't add empty search strings to recent search history.
This commit is contained in:
Isaac Janzen 2024-02-15 12:18:35 -07:00 committed by GitHub
parent 974b3a2a6f
commit 45a130e696
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 13 deletions

View File

@ -95,7 +95,10 @@ export default class AssistantItem extends Component {
@debounce(100)
itemSelected() {
let updatedTerm = "";
if (this.args.slug && this.args.suggestionKeyword) {
if (
this.args.slug &&
(this.args.suggestionKeyword || this.args.concatSlug)
) {
updatedTerm = this.prefix.concat(this.args.slug);
} else {
updatedTerm = this.prefix.trim();

View File

@ -18,6 +18,7 @@
@closeSearchMenu={{@closeSearchMenu}}
@searchTermChanged={{@searchTermChanged}}
@usage="recent-search"
@concatSlug={{true}}
/>
{{/each}}
</div>

View File

@ -20,12 +20,11 @@ export default class RecentSearches extends Component {
}
@action
clearRecent() {
return User.resetRecentSearches().then((result) => {
if (result.success) {
this.currentUser.recent_searches.clear();
}
});
async clearRecent() {
const result = await User.resetRecentSearches();
if (result.success) {
this.currentUser.recent_searches.clear();
}
}
@action
@ -39,11 +38,10 @@ export default class RecentSearches extends Component {
this.search.handleArrowUpOrDown(e);
}
loadRecentSearches() {
User.loadRecentSearches().then((result) => {
if (result.success && result.recent_searches?.length) {
this.currentUser.set("recent_searches", result.recent_searches);
}
});
async loadRecentSearches() {
const result = await User.loadRecentSearches();
if (result.success && result.recent_searches?.length) {
this.currentUser.set("recent_searches", result.recent_searches);
}
}
}

View File

@ -237,6 +237,10 @@ export function applySearchAutocomplete($input, siteSettings) {
}
export function updateRecentSearches(currentUser, term) {
if (!term) {
return;
}
let recentSearches = Object.assign(currentUser.recent_searches || []);
if (recentSearches.includes(term)) {

View File

@ -716,6 +716,12 @@ acceptance("Search - Authenticated", function (needs) {
"blue",
"shows second recent search"
);
await click(
".search-menu .search-menu-recent li:nth-of-type(1) .search-link"
);
assert.dom("input#search-term").hasValue("yellow");
});
test("initial options - overriding behavior with addSearchMenuAssistantSelectCallback", async function (assert) {