Skip to content

Commit 3326b37

Browse files
committed
cveRecordSearchModule: improve handling of empty search string
1 parent 841b45c commit 3326b37

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

src/components/cveRecordSearchModule.vue

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="field has-addons mt-1">
2020
<p class="control">
2121
<span v-if="websiteEnv !== 'prd'" class="select cve-search-selector">
22-
<select v-model="searchType" @input="searchTypeSwap">
22+
<select v-model="searchType">
2323
<option>Search CVE List</option>
2424
<option>Find a Test CVE Record/ID (Legacy)</option>
2525
</select>
@@ -111,6 +111,7 @@ function resetStates() {
111111
queryString.value = cveListSearchStore.query = '';
112112
showHelpMessage('');
113113
cveListSearchStore.isSearchButtonDisabled = true;
114+
resetSearch();
114115
}
115116
116117
function showHelpMessage(helpText) {
@@ -226,16 +227,19 @@ function onInputChange() {
226227
const isSearch = searchTypeBoolean.value;
227228
const searchValue = isSearch ? queryString.value : cveId;
228229
229-
if (cveListSearchStore.isSearchButtonDisabled) {
230-
if (prevSearchValue.value !== searchValue)
231-
cveListSearchStore.isSearchButtonDisabled = false;
232-
} else if (!searchValue.length) {
233-
// This handles the case when the user clears the input field following
234-
// a successful search, possibly by using the delete button or selecting
235-
// the input and cutting via the keyboard. It makes the state consistent
236-
// with when the page starts with nothing in the input field.
230+
if (!searchValue.length) {
231+
// This handles the case when the user clears the input field, by using the
232+
// delete button or selecting the input and cutting via the keyboard. It
233+
// makes the state consistent with when the page starts with nothing in the
234+
// input field.
237235
236+
resetSearch();
237+
showHelpMessage('');
238238
cveListSearchStore.isSearchButtonDisabled = true;
239+
240+
} else if (cveListSearchStore.isSearchButtonDisabled
241+
&& prevSearchValue.value !== searchValue) {
242+
cveListSearchStore.isSearchButtonDisabled = false;
239243
}
240244
}
241245
@@ -256,29 +260,28 @@ function validate() {
256260
} finally {
257261
cveListSearchStore.isSearchButtonDisabled = false;
258262
}
259-
} else if (route?.name != 'home' || route?.query) {
263+
} else {
260264
// The query string is not valid and the route indicates that the URL
261265
// is most likely associated with a previous valid search. The user
262266
// has initiated another search that is unrelated to the URL being
263267
// displayed (e.g., cve.org/CVERecord/SearchResults?query=CVE-2020-0001).
264268
// Rather than display a URL that is not associated with the
265269
// current search, reset it to the home route.
266270
267-
router.push({name: 'home', query: {}});
271+
resetSearch();
268272
}
269273
}
270274
271-
function searchTypeSwap() {
275+
function resetSearch() {
272276
273-
// This function is used only when there's an option menu present that
274-
// allows for using the "legacy" find, which does NOT apply to the
275-
// production website. When a switch is made in the type of search, this
276-
// function resets the previous search value and removes the URL that's
277-
// applicable to the other search type.
277+
// This function performs some reset tasks for the search that are
278+
// common. This includes clearing the previous search value and
279+
// making sure the URL is cleared of any search parameters.
278280
279281
prevSearchValue.value = '';
280282
281-
router.push({name: 'home', query: {}});
283+
if (route?.name != 'home' || route?.query)
284+
router.push({name: 'home', query: {}});
282285
}
283286
284287
const websiteEnv = computed(() => {

0 commit comments

Comments
 (0)