Browse Source

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

* Introduce fuzzy search for quick links of assistant

* Update changelog
pull/5018/merge
Kenrick Tandrian 3 days ago
committed by GitHub
parent
commit
e28ab59673
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 15
      libs/ui/src/lib/assistant/assistant.component.ts
  3. 10
      package-lock.json
  4. 1
      package.json

1
CHANGELOG.md

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Introduced fuzzy search for the quick links of the assistant
- Improved the search results of the assistant to only display categories with content - Improved the search results of the assistant to only display categories with content
- Renamed `Account` to `account` in the `Order` database schema - Renamed `Account` to `account` in the `Order` database schema
- Improved the language localization for German (`de`) - Improved the language localization for German (`de`)

15
libs/ui/src/lib/assistant/assistant.component.ts

@ -41,6 +41,7 @@ import { MatSelectModule } from '@angular/material/select';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { Account, AssetClass, DataSource } from '@prisma/client'; import { Account, AssetClass, DataSource } from '@prisma/client';
import { differenceInYears } from 'date-fns'; import { differenceInYears } from 'date-fns';
import Fuse from 'fuse.js';
import { isFunction } from 'lodash'; import { isFunction } from 'lodash';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { EMPTY, Observable, Subject, merge, of } from 'rxjs'; import { EMPTY, Observable, Subject, merge, of } from 'rxjs';
@ -642,19 +643,17 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
return acc; return acc;
}, [] as IRoute[]); }, [] as IRoute[]);
return allRoutes const fuse = new Fuse(allRoutes, {
.filter(({ title }) => { keys: ['title'],
return title.toLowerCase().includes(searchTerm); threshold: 0.3
}) });
.map(({ routerLink, title }) => {
return fuse.search(searchTerm).map(({ item: { routerLink, title } }) => {
return { return {
routerLink, routerLink,
mode: SearchMode.QUICK_LINK as const, mode: SearchMode.QUICK_LINK as const,
name: title name: title
}; };
})
.sort((a, b) => {
return a.name.localeCompare(b.name);
}); });
} }

10
package-lock.json

@ -66,6 +66,7 @@
"countup.js": "2.8.2", "countup.js": "2.8.2",
"date-fns": "4.1.0", "date-fns": "4.1.0",
"envalid": "8.0.0", "envalid": "8.0.0",
"fuse.js": "7.1.0",
"google-spreadsheet": "3.2.0", "google-spreadsheet": "3.2.0",
"helmet": "7.0.0", "helmet": "7.0.0",
"http-status-codes": "2.3.0", "http-status-codes": "2.3.0",
@ -20615,6 +20616,15 @@
"url": "https://github.com/sponsors/ljharb" "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": { "node_modules/gaxios": {
"version": "4.3.3", "version": "4.3.3",
"resolved": "https://registry.npmjs.org/gaxios/-/gaxios-4.3.3.tgz", "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-4.3.3.tgz",

1
package.json

@ -112,6 +112,7 @@
"countup.js": "2.8.2", "countup.js": "2.8.2",
"date-fns": "4.1.0", "date-fns": "4.1.0",
"envalid": "8.0.0", "envalid": "8.0.0",
"fuse.js": "7.1.0",
"google-spreadsheet": "3.2.0", "google-spreadsheet": "3.2.0",
"helmet": "7.0.0", "helmet": "7.0.0",
"http-status-codes": "2.3.0", "http-status-codes": "2.3.0",

Loading…
Cancel
Save