Skip to content

Commit

Permalink
#2371 move search function to store and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
athu-tran committed Mar 14, 2024
1 parent c1952b5 commit bf6e2d4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
17 changes: 1 addition & 16 deletions src/components/cveRecordLookupModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,7 @@ export default {
}
}
this.search();
},
search() {
// * Check if keyword is CVE ID
if (useCveListSearchStore().isCveIdPattern()) {
useCveListSearchStore().totalExecutingRequests = 2;
// 1st, lookup ID to get Record data, and continue to get CVE Records that mention that ID
useCveListSearchStore().cveId = useCveListSearchStore().query.toUpperCase();
useCveListSearchStore().getRecordData();
} else {
useCveListSearchStore().totalExecutingRequests = 1;
}
// * 2nd, query search service
useCveListSearchStore().getSearchResults();
useCveListSearchStore().search();
},
removeHelpText() {
if (this.query.length === 0) {
Expand Down
19 changes: 17 additions & 2 deletions src/stores/cveListSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
this[field] -= 1;
},
isCveIdPattern() {
return new RegExp(/^CVE-\d{4}-\d{4,7}$/, 'i').test(useCveListSearchStore().query);
return new RegExp(/^CVE-\d{4}-\d{4,7}$/, 'i').test(this.query);
},
search() {
// * Check if keyword is CVE ID
if (this.isCveIdPattern()) {
this.totalExecutingRequests = 2;

// 1st, lookup ID to get Record data, and continue to get CVE Records that mention that ID
this.cveId = this.query.toUpperCase();
this.getRecordData();
} else {
this.totalExecutingRequests = 1;
}

// * 2nd, query search service
this.getSearchResults();
},
async getRecordData() {
this.cveRecordIsLoading = true;
Expand All @@ -41,7 +56,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
try {
axios.defaults.baseURL = `https://${import.meta.env.VITE_CVE_SERVICES_BASE_URL}`;
const response = await axios.get(getRecordUrl);
const cveRecordData = response?.data || {};
const cveRecordData = response?.data || {};
console.log('cveRecordData', response?.data || {})
console.log('Got record data');
console.log(response)
Expand Down
12 changes: 7 additions & 5 deletions src/views/CVERecord/SearchResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<p>
<span>Showing </span>
<span class="has-text-weight-bold">
{{ (pagination.currentPage * numberPerPage) + 1 }} - {{ (pagination.currentPage * numberPerPage) + numberPerPage }}
{{ ((pagination.currentPage * numberPerPage) - numberPerPage) + 1 }} - {{ ((pagination.currentPage * numberPerPage) - numberPerPage) + numberPerPage }}
</span>
<span> of </span>
<span class="has-text-weight-bold">
Expand Down Expand Up @@ -127,8 +127,8 @@
</thead>
<tbody>
<tr class="cve-search-result" v-if="Object.keys(useCveListSearchStore.recordData).length > 0">
<td data-label="CVE ID" class="is-hidden-touch">{{ useCveListSearchStore.recordData.cveId }}</td>
<td data-label="CNA" class="is-hidden-touch">{{ useCveListSearchStore.recordData.cna }}</td>
<td data-label="CVE ID" style="width: 20%">{{ useCveListSearchStore.recordData.cveId }}</td>
<td data-label="CNA" style="width: 20%">{{ useCveListSearchStore.recordData.cna }}</td>
<td data-label="Description">
<p v-for="description in useCveListSearchStore.recordData.descriptions" :key="description.key">{{ description }}</p>
</td>
Expand Down Expand Up @@ -163,7 +163,6 @@
name: 'SearchResults',
data() {
return {
isMessageExpanded: false,
useCveListSearchStore: useCveListSearchStore(),
numberPerPage: 25,
sortBy: {
Expand All @@ -182,7 +181,6 @@
},
beforeMount(){
this.setupPagination();
console.log(this.pagination.totalPages)
},
watch: {
numberPerPage() {
Expand All @@ -203,6 +201,8 @@
if (this.pagination?.startWindow && this.pagination?.endWindow) {
this.pagination.currentPageWindow = this.calcRange(this.pagination.startWindow, this.pagination.endWindow, 1);
}
console.log('pagination ', this.pagination)
},
setupResultsPage() {
// search service count starts at 0
Expand All @@ -225,6 +225,7 @@
this.pagination.currentPageWindow = this.calcRange(this.pagination.startWindow, this.pagination.endWindow, 1);
}
console.log(this.pagination.currentPage, this.pagination.startWindow, this.pagination.endWindow, )
console.log('pagination ', this.pagination)
this.paginate();
},
getPreviousPage() {
Expand All @@ -241,6 +242,7 @@
this.pagination.currentPageWindow = this.calcRange(this.pagination.startWindow, this.pagination.endWindow, 1);
}
console.log('pagination ', this.pagination)
this.paginate();
},
paginate() {
Expand Down
Empty file added vue.config.js
Empty file.

0 comments on commit bf6e2d4

Please sign in to comment.