Skip to content

Commit bf6e2d4

Browse files
committed
#2371 move search function to store and fix errors
1 parent c1952b5 commit bf6e2d4

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

src/components/cveRecordLookupModule.vue

+1-16
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,7 @@ export default {
104104
}
105105
}
106106
107-
this.search();
108-
},
109-
search() {
110-
// * Check if keyword is CVE ID
111-
if (useCveListSearchStore().isCveIdPattern()) {
112-
useCveListSearchStore().totalExecutingRequests = 2;
113-
114-
// 1st, lookup ID to get Record data, and continue to get CVE Records that mention that ID
115-
useCveListSearchStore().cveId = useCveListSearchStore().query.toUpperCase();
116-
useCveListSearchStore().getRecordData();
117-
} else {
118-
useCveListSearchStore().totalExecutingRequests = 1;
119-
}
120-
121-
// * 2nd, query search service
122-
useCveListSearchStore().getSearchResults();
107+
useCveListSearchStore().search();
123108
},
124109
removeHelpText() {
125110
if (this.query.length === 0) {

src/stores/cveListSearch.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,22 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
3131
this[field] -= 1;
3232
},
3333
isCveIdPattern() {
34-
return new RegExp(/^CVE-\d{4}-\d{4,7}$/, 'i').test(useCveListSearchStore().query);
34+
return new RegExp(/^CVE-\d{4}-\d{4,7}$/, 'i').test(this.query);
35+
},
36+
search() {
37+
// * Check if keyword is CVE ID
38+
if (this.isCveIdPattern()) {
39+
this.totalExecutingRequests = 2;
40+
41+
// 1st, lookup ID to get Record data, and continue to get CVE Records that mention that ID
42+
this.cveId = this.query.toUpperCase();
43+
this.getRecordData();
44+
} else {
45+
this.totalExecutingRequests = 1;
46+
}
47+
48+
// * 2nd, query search service
49+
this.getSearchResults();
3550
},
3651
async getRecordData() {
3752
this.cveRecordIsLoading = true;
@@ -41,7 +56,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
4156
try {
4257
axios.defaults.baseURL = `https://${import.meta.env.VITE_CVE_SERVICES_BASE_URL}`;
4358
const response = await axios.get(getRecordUrl);
44-
const cveRecordData = response?.data || {};
59+
const cveRecordData = response?.data || {};
4560
console.log('cveRecordData', response?.data || {})
4661
console.log('Got record data');
4762
console.log(response)

src/views/CVERecord/SearchResults.vue

+7-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<p>
5151
<span>Showing </span>
5252
<span class="has-text-weight-bold">
53-
{{ (pagination.currentPage * numberPerPage) + 1 }} - {{ (pagination.currentPage * numberPerPage) + numberPerPage }}
53+
{{ ((pagination.currentPage * numberPerPage) - numberPerPage) + 1 }} - {{ ((pagination.currentPage * numberPerPage) - numberPerPage) + numberPerPage }}
5454
</span>
5555
<span> of </span>
5656
<span class="has-text-weight-bold">
@@ -127,8 +127,8 @@
127127
</thead>
128128
<tbody>
129129
<tr class="cve-search-result" v-if="Object.keys(useCveListSearchStore.recordData).length > 0">
130-
<td data-label="CVE ID" class="is-hidden-touch">{{ useCveListSearchStore.recordData.cveId }}</td>
131-
<td data-label="CNA" class="is-hidden-touch">{{ useCveListSearchStore.recordData.cna }}</td>
130+
<td data-label="CVE ID" style="width: 20%">{{ useCveListSearchStore.recordData.cveId }}</td>
131+
<td data-label="CNA" style="width: 20%">{{ useCveListSearchStore.recordData.cna }}</td>
132132
<td data-label="Description">
133133
<p v-for="description in useCveListSearchStore.recordData.descriptions" :key="description.key">{{ description }}</p>
134134
</td>
@@ -163,7 +163,6 @@
163163
name: 'SearchResults',
164164
data() {
165165
return {
166-
isMessageExpanded: false,
167166
useCveListSearchStore: useCveListSearchStore(),
168167
numberPerPage: 25,
169168
sortBy: {
@@ -182,7 +181,6 @@
182181
},
183182
beforeMount(){
184183
this.setupPagination();
185-
console.log(this.pagination.totalPages)
186184
},
187185
watch: {
188186
numberPerPage() {
@@ -203,6 +201,8 @@
203201
if (this.pagination?.startWindow && this.pagination?.endWindow) {
204202
this.pagination.currentPageWindow = this.calcRange(this.pagination.startWindow, this.pagination.endWindow, 1);
205203
}
204+
205+
console.log('pagination ', this.pagination)
206206
},
207207
setupResultsPage() {
208208
// search service count starts at 0
@@ -225,6 +225,7 @@
225225
this.pagination.currentPageWindow = this.calcRange(this.pagination.startWindow, this.pagination.endWindow, 1);
226226
}
227227
console.log(this.pagination.currentPage, this.pagination.startWindow, this.pagination.endWindow, )
228+
console.log('pagination ', this.pagination)
228229
this.paginate();
229230
},
230231
getPreviousPage() {
@@ -241,6 +242,7 @@
241242
242243
this.pagination.currentPageWindow = this.calcRange(this.pagination.startWindow, this.pagination.endWindow, 1);
243244
}
245+
console.log('pagination ', this.pagination)
244246
this.paginate();
245247
},
246248
paginate() {

vue.config.js

Whitespace-only changes.

0 commit comments

Comments
 (0)