Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/introduce fuzzy search for quick links of assistant (#5055)

Kenrick Tandriane28ab59673b2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9ccc0239b4..d6f10399f4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- Introduced fuzzy search for the quick links of the assistant
- Improved the search results of the assistant to only display categories with content
- Renamed `Account` to `account` in the `Order` database schema
- Improved the language localization for German (`de`)
diff --git a/libs/ui/src/lib/assistant/assistant.component.ts b/libs/ui/src/lib/assistant/assistant.component.ts
index 22c75b91c5..75e770ca7d 100644
--- a/libs/ui/src/lib/assistant/assistant.component.ts
+++ b/libs/ui/src/lib/assistant/assistant.component.ts
@@ -41,6 +41,7 @@ import { MatSelectModule } from '@angular/material/select';
import { RouterModule } from '@angular/router';
import { Account, AssetClass, DataSource } from '@prisma/client';
import { differenceInYears } from 'date-fns';
+import Fuse from 'fuse.js';
import { isFunction } from 'lodash';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { EMPTY, Observable, Subject, merge, of } from 'rxjs';
@@ -642,20 +643,18 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
return acc;
}, [] as IRoute[]);
- return allRoutes
- .filter(({ title }) => {
- return title.toLowerCase().includes(searchTerm);
- })
- .map(({ routerLink, title }) => {
- return {
- routerLink,
- mode: SearchMode.QUICK_LINK as const,
- name: title
- };
- })
- .sort((a, b) => {
- return a.name.localeCompare(b.name);
- });
+ const fuse = new Fuse(allRoutes, {
+ keys: ['title'],
+ threshold: 0.3
+ });
+
+ return fuse.search(searchTerm).map(({ item: { routerLink, title } }) => {
+ return {
+ routerLink,
+ mode: SearchMode.QUICK_LINK as const,
+ name: title
+ };
+ });
}
private setFilterFormValues() {
diff --git a/package-lock.json b/package-lock.json
index f5c8ed8af8..12ac3a8a79 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -66,6 +66,7 @@
"countup.js": "2.8.2",
"date-fns": "4.1.0",
"envalid": "8.0.0",
+ "fuse.js": "7.1.0",
"google-spreadsheet": "3.2.0",
"helmet": "7.0.0",
"http-status-codes": "2.3.0",
@@ -20615,6 +20616,15 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/fuse.js": {
+ "version": "7.1.0",
+ "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.1.0.tgz",
+ "integrity": "sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==",
+ "license": "Apache-2.0",
+ "engines": {
+ "node": ">=10"
+ }
+ },
"node_modules/gaxios": {
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/gaxios/-/gaxios-4.3.3.tgz",
diff --git a/package.json b/package.json
index f3155dba3e..0e72f16646 100644
--- a/package.json
+++ b/package.json
@@ -112,6 +112,7 @@
"countup.js": "2.8.2",
"date-fns": "4.1.0",
"envalid": "8.0.0",
+ "fuse.js": "7.1.0",
"google-spreadsheet": "3.2.0",
"helmet": "7.0.0",
"http-status-codes": "2.3.0",