Skip to content

Commit 947dd5b

Browse files
committed
fix Production/Test message for search
1 parent c80ce00 commit 947dd5b

File tree

4 files changed

+36
-50
lines changed

4 files changed

+36
-50
lines changed

src/components/cveRecordSearchModule.vue

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
import { useCveListSearchStore } from '@/stores/cveListSearch';
6161
import { computed, ref, watch } from 'vue';
6262
import { useRoute, useRouter } from 'vue-router';
63-
// Legacy Search Import
64-
import { usecveRecordStore, useErrorMessageStore } from '@/stores/cveRecord';
63+
import { useErrorMessageStore } from '@/stores/cveRecord';
6564
import { useGenericGlobalsStore } from '@/stores/genericGlobals';
6665
6766
const cveIdRegex = /^CVE\p{Pd}(?<year>\d{4})\p{Pd}(?<id>\d{4,})$/iu;
@@ -88,9 +87,8 @@ let queryString = ref('');
8887
let errorMessage = ref('');
8988
9089
let cveGenericGlobalsStore = useGenericGlobalsStore();
91-
let cveRecordStore = usecveRecordStore();
92-
let searchType = ref(searchOptionLabel);
93-
let cveId = cveRecordStore.cveId;
90+
let searchType = ref('');
91+
let cveId = '';
9492
9593
// this seems redundant, but it fixes an edge case. if a user searches for a
9694
// particular field, then on the results page flips the toggle, THEN refreshes
@@ -99,9 +97,12 @@ let searchTypeBoolean = computed(() => {
9997
return searchType.value === searchOptionLabel ? true : false;
10098
});
10199
102-
watch(searchType, () => {
103-
resetStates();
104-
});
100+
// The watch is set up first and then the initialization of the searchType
101+
// value so that the watch is triggered, which resets the state.
102+
103+
watch(searchType, () => {resetStates();});
104+
105+
searchType.value = searchOptionLabel;
105106
106107
watch(
107108
() => route.query,
@@ -115,8 +116,9 @@ watch(
115116
// find than the normal search (cveawg). In this case, we need to switch
116117
// the search type to "legacy". (issue #3426)
117118
118-
if (route?.name === cveRecordRouteName
119-
&& !cveGenericGlobalsStore.isProductionWebsite)
119+
if (route.name === cveRecordRouteName
120+
&& !cveGenericGlobalsStore.isProductionWebsite
121+
&& (route.query?.prod ?? 'false') !== 'true')
120122
searchType.value = legacyOptionLabel;
121123
else if (route.query?.query) {
122124
queryString.value = route.query.query.trim();
@@ -127,25 +129,20 @@ watch(
127129
)
128130
129131
function resetStates() {
130-
cveListSearchStore.searchType = cveGenericGlobalsStore.useSearch = searchTypeBoolean.value;
132+
const isSearch = searchTypeBoolean.value;
133+
const servicesUrl = isSearch ? cveGenericGlobalsStore.cveServicesBaseUrl
134+
: cveGenericGlobalsStore.cveServiceTestBaseUrl;
135+
cveGenericGlobalsStore.setUseSearch(isSearch);
136+
cveGenericGlobalsStore.setCurrentServicesUrl(servicesUrl);
137+
cveListSearchStore.searchType = isSearch;
131138
cveId = '';
132139
queryString.value = cveListSearchStore.query = '';
133140
errorMessageStore.$reset();
134141
cveListSearchStore.isSearchButtonDisabled = true;
135-
resetSearch();
136142
}
137143
138144
function startSearch() {
139-
// We only want to flip the search item _When we actually do a search_
140-
// otherwise we should default back to what we were on a page refresh
141-
if (searchTypeBoolean.value) {
142-
cveGenericGlobalsStore.setUseSearch(true);
143-
cveGenericGlobalsStore.setCurrentServicesUrl(cveGenericGlobalsStore.cveServicesBaseUrl);
144-
}
145-
else {
146-
cveGenericGlobalsStore.setUseSearch(false);
147-
cveGenericGlobalsStore.setCurrentServicesUrl(cveGenericGlobalsStore.cveServiceTestBaseUrl);
148-
}
145+
149146
if (cveGenericGlobalsStore.useSearch) {
150147
cveListSearchStore.$reset();
151148
cveListSearchStore.query = queryString.value;

src/stores/genericGlobals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ export const useGenericGlobalsStore = defineStore('genericGlobals', {
2525
sessionStorage.setItem('currentServicesUrl', JSON.stringify(value));
2626
}
2727
},
28-
});
28+
});

src/views/CVERecord/CVERecord.vue

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
<p id="alertIconCveRecordsRequestErrored" class="is-hidden">alert</p>
2727
<font-awesome-icon style="flex: 0 0 40px;" size="1x" icon="triangle-exclamation" role="img"
2828
aria-labelledby="alertIconCveRecordsRequestErrored" aria-hidden="false" />
29-
<p>You are accessing <span class="has-text-weight-bold">{{ usingProd }}</span> data from {{ resultUrl }}</p>
29+
<p>You are accessing data from
30+
{{ genericGlobalsStore.currentServicesUrl }}
31+
</p>
3032
</div>
3133
</div>
3234
<PublishedRecord v-if="usecveRecordStore.isPublished"/>
@@ -51,7 +53,9 @@
5153
<p id="alertIconCveRecordsRequestErrored" class="is-hidden">alert</p>
5254
<font-awesome-icon style="flex: 0 0 40px;" size="1x" icon="triangle-exclamation" role="img"
5355
aria-labelledby="alertIconCveRecordsRequestErrored" aria-hidden="false" />
54-
<p>You are accessing <span class="has-text-weight-bold">{{ usingProd }}</span> data from {{ resultUrl }}</p>
56+
<p>You are accessing data from
57+
{{ genericGlobalsStore.currentServicesUrl }}
58+
</p>
5559
</div>
5660
</div>
5761
<h1 class="title is-3 is-4 mb-2">{{usecveRecordStore.cveId}} not found.</h1>
@@ -94,13 +98,6 @@ export default {
9498
},
9599
data() {
96100
return {
97-
isResultFromProd: false,
98-
// There is a special case when the website deals with some cached data.
99-
// This ensures that the correct value is shown, even though it is not
100-
// pretty
101-
resultUrl: this.GenericGlobalsStore.useSearch
102-
? this.GenericGlobalsStore.cveServicesBaseUrl
103-
: this.GenericGlobalsStore.cveServiceTestBaseUrl,
104101
usecveRecordStore: usecveRecordStore(),
105102
cveId: usecveRecordStore().cveId,
106103
cveServicesUrl: undefined,
@@ -113,9 +110,6 @@ export default {
113110
};
114111
},
115112
computed: {
116-
usingProd() {
117-
return this.isResultFromProd ? 'Production' : 'Test'
118-
},
119113
isSearching() {
120114
return usecveRecordStore().isSearching;
121115
},
@@ -129,10 +123,6 @@ export default {
129123
this.cveId = this.cveIdToUpperCase(cveId);
130124
this.validateCveId();
131125
if (!this.disabled) {
132-
if (this.$route.query?.prod ?? 'false' === 'true')
133-
this.currentServicesUrl = this.genericGlobalsStore.cveServicesBaseUrl;
134-
else
135-
this.currentServicesUrl = this.genericGlobalsStore.currentServicesUrl;
136126
this.startLookup();
137127
} else {
138128
usecveRecordStore().showHelpText = true;
@@ -148,10 +138,6 @@ export default {
148138
this.cveId = this.cveIdToUpperCase(cveId);
149139
this.validateCveId();
150140
if (!this.disabled) {
151-
if (this.$route.query?.prod ?? 'false' === 'true')
152-
this.currentServicesUrl = this.genericGlobalsStore.cveServicesBaseUrl;
153-
else
154-
this.currentServicesUrl = this.genericGlobalsStore.currentServicesUrl;
155141
this.startLookup();
156142
} else {
157143
this.resetStates();
@@ -213,7 +199,7 @@ export default {
213199
214200
const getIdUrl = `/api/cve-id/${usecveRecordStore().cveId}`;
215201
try {
216-
axios.defaults.baseURL = this.currentServicesUrl;
202+
axios.defaults.baseURL = this.genericGlobalsStore.currentServicesUrl;
217203
const idData = await axios.get(getIdUrl);
218204
this.getIdStatusCode = 200;
219205
if (idData.status === 200 && idData?.data?.error === undefined) {
@@ -249,7 +235,8 @@ export default {
249235
}
250236
},
251237
async getRecordData() {
252-
const getRecordUrl = `${this.currentServicesUrl}/api/cve/${usecveRecordStore().cveId}`;
238+
const getRecordUrl = `${this.genericGlobalsStore.currentServicesUrl}`
239+
+ `/api/cve/${usecveRecordStore().cveId}`;
253240
if (this.GenericGlobalsStore.useSearch) {
254241
this.isResultFromProd = true;
255242
} else {

src/views/CVERecord/SearchResults.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626
<ServiceUnavailable></ServiceUnavailable>
2727
</div>
2828
<div v-else>
29-
<div v-if="websiteEnv !== 'prd'" class="notification is-warning is-light" role="alert">
29+
<div v-if="!genericGlobalsStore.isProductionWebsite"
30+
class="notification is-warning is-light" role="alert">
3031
<div class="is-flex is-justify-content-center">
3132
<p id="alertIconCveRecordsRequestErrored" class="is-hidden">alert</p>
3233
<font-awesome-icon style="flex: 0 0 40px;" size="1x" icon="triangle-exclamation" role="alert"
3334
aria-labelledby="alertIconCveRecordsRequestErrored" aria-hidden="false" />
34-
<p>You are accessing <span class="has-text-weight-bold">Production</span> data from {{ resultUrl }}</p>
35+
<p>You are accessing data from
36+
{{ generalGlobalsStore.currentServicesUrl }}
37+
</p>
3538
</div>
3639
</div>
3740
<h2 class="title">Search Results</h2>
@@ -282,7 +285,7 @@
282285
import { useCveListSearchStore } from '@/stores/cveListSearch';
283286
import { useGenericGlobalsStore } from '@/stores/genericGlobals';
284287
import { usePartnerStore } from '@/stores/partners';
285-
import { computed, createApp, ref, watch } from 'vue';
288+
import { computed, createApp, watch } from 'vue';
286289
import { useRouter } from 'vue-router';
287290
import ServiceUnavailable from '@/components/ServiceUnavailable.vue'
288291
@@ -291,7 +294,6 @@ const generalGlobalsStore = useGenericGlobalsStore();
291294
const partnerStore = usePartnerStore();
292295
const router = useRouter();
293296
const app = createApp({});
294-
const resultUrl = ref(generalGlobalsStore.cveServicesBaseUrl);
295297
296298
app.component('ServiceUnavailable', ServiceUnavailable);
297299
@@ -314,7 +316,7 @@ function backToTop() {
314316
function cveRecordRoute(cveId) {
315317
let recordRoute = `/CVERecord?id=${cveId}`;
316318
317-
if (!generalGlobalsStore.isProductionWebsite)
319+
if (!generalGlobalsStore.isProductionWebsite && generalGlobalsStore.useSearch)
318320
recordRoute += '&prod=true';
319321
320322
return recordRoute

0 commit comments

Comments
 (0)