Fixes help center public article search so query responses stay compact and locale-scoped. Whitespace-only queries are now treated as empty in both the portal UI and the server-side search path, and search suggestions stay aligned with the trimmed query. Fixes: https://github.com/chatwoot/chatwoot/issues/10402 Closes: https://github.com/chatwoot/chatwoot/issues/10402 ## Why The public help center search endpoint reused the full article serializer for query responses, which returned much more data than the search suggestions UI needed. That made responses heavier than necessary and also surfaced nested portal and category data that made the results look cross-locale. Whitespace-only searches could also still reach the backend search path, and in Enterprise that meant embedding search could be invoked for a blank query. ## What changed - return a compact search-specific payload for article query responses - keep the existing full article serializer for normal article listing responses - preserve current-locale search behavior for the portal search flow - trim whitespace-only search terms on the client so they do not open suggestions or trigger a request - reuse the normalized query on the backend so whitespace-only requests are treated as empty searches in both OSS and Enterprise paths - pass the trimmed search term into suggestions so highlighting matches the actual query being sent - add request and frontend regression coverage for compact payloads, locale scoping, and whitespace-only search behavior ## Validation 1. Open `/hc/:portal/:locale` in the public help center. 2. Enter only spaces in the search box and confirm suggestions do not open. 3. Search for a real term and confirm suggestions appear. 4. Verify the results are limited to the active locale. 5. Click a suggestion and confirm it opens the correct article page. 6. Inspect the query response and confirm it returns the compact search payload instead of the full article serializer. --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
136 lines
3.1 KiB
Vue
136 lines
3.1 KiB
Vue
<script>
|
|
import SearchSuggestions from './SearchSuggestions.vue';
|
|
import PublicSearchInput from './PublicSearchInput.vue';
|
|
|
|
import ArticlesAPI from '../api/article';
|
|
|
|
export default {
|
|
components: {
|
|
PublicSearchInput,
|
|
SearchSuggestions,
|
|
},
|
|
emits: ['input', 'blur'],
|
|
data() {
|
|
return {
|
|
searchTerm: '',
|
|
isLoading: false,
|
|
showSearchBox: false,
|
|
searchResults: [],
|
|
};
|
|
},
|
|
|
|
computed: {
|
|
portalSlug() {
|
|
return window.portalConfig.portalSlug;
|
|
},
|
|
localeCode() {
|
|
return window.portalConfig.localeCode;
|
|
},
|
|
normalizedSearchTerm() {
|
|
return this.searchTerm.trim();
|
|
},
|
|
shouldShowSearchBox() {
|
|
return this.normalizedSearchTerm !== '' && this.showSearchBox;
|
|
},
|
|
searchTranslations() {
|
|
const { searchTranslations = {} } = window.portalConfig;
|
|
return searchTranslations;
|
|
},
|
|
},
|
|
|
|
watch: {
|
|
currentPage() {
|
|
this.clearSearchTerm();
|
|
},
|
|
},
|
|
|
|
unmounted() {
|
|
clearTimeout(this.typingTimer);
|
|
},
|
|
|
|
methods: {
|
|
onUpdateSearchTerm(value) {
|
|
this.searchTerm = value;
|
|
if (this.typingTimer) {
|
|
clearTimeout(this.typingTimer);
|
|
}
|
|
|
|
if (this.normalizedSearchTerm === '') {
|
|
this.searchResults = [];
|
|
this.isLoading = false;
|
|
this.closeSearch();
|
|
return;
|
|
}
|
|
|
|
this.openSearch();
|
|
this.isLoading = true;
|
|
this.typingTimer = setTimeout(() => {
|
|
this.fetchArticlesByQuery();
|
|
}, 1000);
|
|
},
|
|
onChange(e) {
|
|
this.$emit('input', e.target.value);
|
|
},
|
|
onBlur(e) {
|
|
this.$emit('blur', e.target.value);
|
|
},
|
|
openSearch() {
|
|
this.showSearchBox = true;
|
|
},
|
|
closeSearch() {
|
|
this.showSearchBox = false;
|
|
},
|
|
clearSearchTerm() {
|
|
this.searchTerm = '';
|
|
},
|
|
async fetchArticlesByQuery() {
|
|
const query = this.normalizedSearchTerm;
|
|
if (!query) {
|
|
this.isLoading = false;
|
|
return;
|
|
}
|
|
|
|
try {
|
|
this.isLoading = true;
|
|
this.searchResults = [];
|
|
const { data } = await ArticlesAPI.searchArticles(
|
|
this.portalSlug,
|
|
this.localeCode,
|
|
query
|
|
);
|
|
this.searchResults = data.payload;
|
|
} catch (error) {
|
|
// Show something wrong message
|
|
} finally {
|
|
this.isLoading = false;
|
|
}
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div v-on-clickaway="closeSearch" class="relative w-full max-w-5xl my-4">
|
|
<PublicSearchInput
|
|
:search-term="searchTerm"
|
|
:search-placeholder="searchTranslations.searchPlaceholder"
|
|
@update:search-term="onUpdateSearchTerm"
|
|
@focus="openSearch"
|
|
/>
|
|
<div
|
|
v-if="shouldShowSearchBox"
|
|
class="absolute w-full top-14"
|
|
@mouseover="openSearch"
|
|
>
|
|
<SearchSuggestions
|
|
:items="searchResults"
|
|
:is-loading="isLoading"
|
|
:search-term="normalizedSearchTerm"
|
|
:empty-placeholder="searchTranslations.emptyPlaceholder"
|
|
:results-title="searchTranslations.resultsTitle"
|
|
:loading-placeholder="searchTranslations.loadingPlaceholder"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|