Skip to content

Commit a994c84

Browse files
committed
search: display CVE record directly following search of CVE ID that returns only corresponding CVE record
1 parent 49ecea1 commit a994c84

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/stores/cveListSearch.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useGenericGlobalsStore } from './genericGlobals';
44
import axios from 'axios';
55

66
export const useCveListSearchStore = defineStore('cveListSearch ', {
7-
state: () => {
7+
state: () => {
88
return {
99
cveId: '',
1010
from: 0,
@@ -84,15 +84,36 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
8484
this.totalExecutingRequests = 1;
8585
await this.getSearchResults();
8686

87-
// * Check if keyword is CVE ID
8887
if (this.isCveIdPattern()) {
89-
this.totalExecutingRequests = 2;
90-
91-
// lookup ID to get Record data
88+
89+
// The user's query is one CVE ID.
90+
9291
this.cveId = this.query.toUpperCase();
93-
await this.getRecordData();
94-
}
9592

93+
if (this.searchResults.length === 1
94+
&& this.searchResults[0].cveId === this.cveId) {
95+
96+
// The search returned only ONE result and it's the CVE record
97+
// associated with the CVE ID given as the search string. Most
98+
// likely, the user just wants to see the CVE Record and not the
99+
// search results containing only the CVE link for the record
100+
// they're searching for (just to have to click on the CVE link to
101+
// get to the CVE Record). In this case, change the route to
102+
// go directly to the CVE Record display.
103+
104+
this.router.push({
105+
name: 'CVERecord',
106+
query: {id: this.cveId},
107+
replace: true
108+
});
109+
} else {
110+
111+
this.totalExecutingRequests = 2;
112+
113+
// lookup ID to get Record data
114+
await this.getRecordData();
115+
}
116+
}
96117
} catch (error) {
97118
// if record is not found, find potential reserved/rejected ID
98119
if (this.isCveIdPattern() && Object.keys(this.recordData).length === 0) {
@@ -306,7 +327,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
306327
async paginate() {
307328
try {
308329
this.calcToAndFromCounts();
309-
330+
310331
// search service starts at 0 while this app starts at 1
311332
this.from = (parseInt(this.pagination.currentPage) * parseInt(this.pagination.numberPerPage)) - parseInt(this.pagination.numberPerPage);
312333
if (parseInt(this.from) + parseInt(this.pagination.numberPerPage) > parseInt(this.totalSearchResultCount)) {
@@ -414,7 +435,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
414435

415436
this.pagination.currentPageWindow = this.calcRange(this.pagination.startWindow, this.pagination.endWindow);
416437
this.paginate();
417-
}
438+
}
418439
},
419440
handleNextPageChange() {
420441
this.pagination.currentPage = parseInt(this.pagination.currentPage) + 1;

src/views/CVERecord/SearchResults.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151
<div class="columns cve-columns">
5252
<div class="column cve-column">
5353
<router-link v-if="hasRecordData"
54-
:to="cveRecordRoute(cveListSearchStore.recordData.cveId)" target="_blank">
54+
:to="cveRecordRoute(cveListSearchStore.recordData.cveId)">
5555
{{ cveListSearchStore.recordData.cveId }}
5656
</router-link>
5757
<router-link v-if="hasIdData"
58-
:to="cveRecordRoute(cveListSearchStore.idData.cve_id)" target="_blank">
58+
:to="cveRecordRoute(cveListSearchStore.idData.cve_id)">
5959
{{ cveListSearchStore.idData.cve_id}}
6060
</router-link>
6161
</div>

0 commit comments

Comments
 (0)