Merge pull request #1843 from Safelite/CSR-2072-fix-insurance-search-dropdown

CSR-2072 fix insurance search dropdown after API was updated and case…
This commit is contained in:
bmauger 2024-05-06 13:50:57 -04:00 committed by GitHub
commit 5ef80b4a83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -96,15 +96,29 @@ export default {
findMatches(request, response) {
const matches = [];
const term = request?.term?.toUpperCase();
const nonPriorityMatches = [];
this.searchableInsuranceCompanyList.forEach((company, index) => {
if (
company.accountName.indexOf(term) !== -1 ||
company.altTerms.indexOf(term) !== -1
company.accountName.toUpperCase().indexOf(term) !== -1 ||
company.altTerms.toUpperCase().indexOf(term) !== -1
) {
matches.push(company.accountName);
}
});
response(matches);
// Prioritize matched typed entries to top of list
const priorityMatches = matches.filter((companyName, index) => {
if (companyName.toUpperCase().indexOf(term) === 0) {
return companyName;
} else {
nonPriorityMatches.push(companyName);
}
});
const prioritizedMatches = [...priorityMatches, ...nonPriorityMatches];
response(prioritizedMatches);
},
selectInsuranceCompany(parentAccountName) {
// this runs upon user selection within jQueryUI Autocomplete