Skip to content

Commit a33dfdd

Browse files
committed
use input events instead of watch for numberPerPage & sortBy; change response item from "search-metadata" to "searchMetadata"
1 parent 2f8bf61 commit a33dfdd

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/stores/cveListSearch.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
179179
let payLoad = this.createSearchPayload();
180180
const response = await axios.post(searchUrl, payLoad);
181181

182-
const searchMetaData = response.data['search-metadata'];
182+
const searchMetaData = response.data.searchMetadata;
183183

184184
if (searchMetaData.searchStatus === 'ok') {
185185
this.totalSearchResultCount = response.data.resultsTotal;
@@ -188,6 +188,11 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
188188
// There's likely something invalid in the search string.
189189
// Error message(s) and note(s) returned in the response will be
190190
// displayed to the user.
191+
//
192+
// We could reset the error message store here, because this is a
193+
// "new" search, but resetting may also mask an issue where the
194+
// search is inadvertently done multiple times (resulting in
195+
// duplicate error messages displayed).
191196

192197
const ems = useErrorMessageStore();
193198

src/views/CVERecord/SearchResults.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@
125125
<label class="label">Show:</label>
126126
<div class="control">
127127
<div class="select">
128-
<select v-model="cveListSearchStore.pagination.numberPerPage" aria-label="Select how many search results to show">
128+
<select v-model="cveListSearchStore.pagination.numberPerPage"
129+
aria-label="Select how many search results to show"
130+
@input="numberPerPageChange">
129131
<option v-for="num in cveListSearchStore.pagination.numberPerPageOptions" :key="`page-${num}`" :value="num">
130132
{{ num }}
131133
</option>
@@ -135,7 +137,9 @@
135137
<label for="sort" class="label">Sort by:</label>
136138
<div class="control">
137139
<div class="select">
138-
<select name="partner" v-model="cveListSearchStore.pagination.sortBy" aria-label="Select a sort option">
140+
<select name="partner" v-model="cveListSearchStore.pagination.sortBy"
141+
aria-label="Select a sort option"
142+
@input="sortByChange">
139143
<option v-for="sort in cveListSearchStore.pagination.sortByOptions" :key="sort.key"
140144
:value="sort"
141145
>
@@ -286,14 +290,6 @@ const app = createApp({});
286290
287291
app.component('ServiceUnavailable', ServiceUnavailable);
288292
289-
watch(()=>cveListSearchStore.pagination.numberPerPage, ()=>{
290-
if (!cveListSearchStore.isSearching) cveListSearchStore.handleNumberPerPageChange();
291-
}, { deep: true });
292-
293-
watch(()=>cveListSearchStore.pagination.sortBy, ()=>{
294-
if (!cveListSearchStore.isSearching) cveListSearchStore.sortResults();
295-
}, { deep: true });
296-
297293
function backToTop() {
298294
router.push({
299295
name: 'SearchResults',
@@ -311,6 +307,16 @@ function cveRecordRoute(cveId) {
311307
return recordRoute
312308
}
313309
310+
function numberPerPageChange() {
311+
if (!cveListSearchStore.isSearching)
312+
cveListSearchStore.handleNumberPerPageChange();
313+
}
314+
315+
function sortByChange() {
316+
if (!cveListSearchStore.isSearching)
317+
cveListSearchStore.sortResults();
318+
}
319+
314320
const websiteEnv = computed(() => {
315321
return import.meta.env.VITE_WEBSITE_ENVIRONMENT;
316322
});

0 commit comments

Comments
 (0)