Browse Source

feat(lib): resolve comments

pull/4870/head
KenTandrian 4 weeks ago
parent
commit
52ba57b408
  1. 9
      libs/ui/src/lib/assistant/assistant-list-item/assistant-list-item.component.ts
  2. 2
      libs/ui/src/lib/assistant/assistant-list-item/assistant-list-item.html
  3. 40
      libs/ui/src/lib/assistant/assistant.component.ts
  4. 35
      libs/ui/src/lib/assistant/assistant.html
  5. 10
      libs/ui/src/lib/assistant/interfaces/interfaces.ts

9
libs/ui/src/lib/assistant/assistant-list-item/assistant-list-item.component.ts

@ -74,11 +74,12 @@ export class GfAssistantListItemComponent
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
} }
public isAssetProfileOrHoldingItem( public isAsset(item: ISearchResultItem): item is IAssetSearchResultItem {
item: ISearchResultItem
): item is IAssetSearchResultItem {
return ( return (
item.mode === SearchMode.ASSET_PROFILE || item.mode === SearchMode.HOLDING (item.mode === SearchMode.ASSET_PROFILE ||
item.mode === SearchMode.HOLDING) &&
!!item.dataSource &&
!!item.symbol
); );
} }

2
libs/ui/src/lib/assistant/assistant-list-item/assistant-list-item.html

@ -7,7 +7,7 @@
><span ><span
><b>{{ item?.name }}</b></span ><b>{{ item?.name }}</b></span
> >
@if (item && isAssetProfileOrHoldingItem(item)) { @if (item && isAsset(item)) {
<br /> <br />
<small class="text-muted" <small class="text-muted"
>{{ item?.symbol | gfSymbol }} · {{ item?.currency }} >{{ item?.symbol | gfSymbol }} · {{ item?.currency }}

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

@ -210,6 +210,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
holdings: [], holdings: [],
quickLinks: [] quickLinks: []
} as ISearchResults; } as ISearchResults;
if (!searchTerm) { if (!searchTerm) {
return of(results).pipe( return of(results).pipe(
tap(() => { tap(() => {
@ -222,17 +223,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
); );
} }
// QuickLinks
const quickLinksData = this.searchQuickLinks(searchTerm);
const quickLinks$: Observable<Partial<ISearchResults>> = of({
quickLinks: quickLinksData
}).pipe(
tap(() => {
this.isLoading.quickLinks = false;
this.changeDetectorRef.markForCheck();
})
);
// Asset Profiles // Asset Profiles
const assetProfiles$: Observable<Partial<ISearchResults>> = this const assetProfiles$: Observable<Partial<ISearchResults>> = this
.hasPermissionToAccessAdminControl .hasPermissionToAccessAdminControl
@ -280,6 +270,18 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}) })
); );
// QuickLinks
const quickLinksData = this.searchQuickLinks(searchTerm);
const quickLinks$: Observable<Partial<ISearchResults>> = of({
quickLinks: quickLinksData
}).pipe(
tap(() => {
this.isLoading.quickLinks = false;
this.changeDetectorRef.markForCheck();
})
);
// Merge all results // Merge all results
return merge(quickLinks$, assetProfiles$, holdings$).pipe( return merge(quickLinks$, assetProfiles$, holdings$).pipe(
scan( scan(
@ -599,11 +601,11 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
} }
private searchQuickLinks(aSearchTerm: string): ISearchResultItem[] { private searchQuickLinks(aSearchTerm: string): ISearchResultItem[] {
const term = aSearchTerm.toLowerCase(); const searchTerm = aSearchTerm.toLowerCase();
const allRoutes = Object.values(internalRoutes) const allRoutes = Object.values(internalRoutes)
.filter((route) => { .filter(({ excludeFromAssistant }) => {
return !route.excludeFromAssistant; return !excludeFromAssistant;
}) })
.reduce((acc, route) => { .reduce((acc, route) => {
acc.push(route); acc.push(route);
@ -614,14 +616,14 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
}, [] as IRoute[]); }, [] as IRoute[]);
return allRoutes return allRoutes
.filter((route) => { .filter(({ title }) => {
return route.title.toLowerCase().includes(term); return title.toLowerCase().includes(searchTerm);
}) })
.map((route) => { .map(({ routerLink, title }) => {
return { return {
routerLink,
mode: SearchMode.QUICK_LINK as const, mode: SearchMode.QUICK_LINK as const,
name: route.title, name: title
routerLink: route.routerLink
}; };
}) })
.sort((a, b) => { .sort((a, b) => {

35
libs/ui/src/lib/assistant/assistant.html

@ -40,15 +40,18 @@
*ngIf="searchFormControl.value" *ngIf="searchFormControl.value"
class="overflow-auto py-3 result-container" class="overflow-auto py-3 result-container"
> >
<div> <div
<div class="h6 mb-1 px-2" i18n>Holdings</div> *ngIf="searchResults?.quickLinks?.length !== 0 || isLoading.quickLinks"
class="mb-3"
>
<div class="h6 mb-1 px-2" i18n>Quick Links</div>
<gf-assistant-list-item <gf-assistant-list-item
*ngFor="let searchResultItem of searchResults?.holdings" *ngFor="let searchResultItem of searchResults?.quickLinks"
[item]="searchResultItem" [item]="searchResultItem"
(clicked)="onCloseAssistant()" (clicked)="onCloseAssistant()"
/> />
<ng-container *ngIf="searchResults?.holdings?.length === 0"> <ng-container>
@if (isLoading.holdings) { @if (isLoading.quickLinks) {
<ngx-skeleton-loader <ngx-skeleton-loader
animation="pulse" animation="pulse"
class="mx-2" class="mx-2"
@ -57,20 +60,18 @@
width: '100%' width: '100%'
}" }"
/> />
} @else {
<div class="px-2 py-1" i18n>No entries...</div>
} }
</ng-container> </ng-container>
</div> </div>
<div *ngIf="hasPermissionToAccessAdminControl" class="mt-3"> <div>
<div class="h6 mb-1 px-2" i18n>Asset Profiles</div> <div class="h6 mb-1 px-2" i18n>Holdings</div>
<gf-assistant-list-item <gf-assistant-list-item
*ngFor="let searchResultItem of searchResults?.assetProfiles" *ngFor="let searchResultItem of searchResults?.holdings"
[item]="searchResultItem" [item]="searchResultItem"
(clicked)="onCloseAssistant()" (clicked)="onCloseAssistant()"
/> />
<ng-container *ngIf="searchResults?.assetProfiles?.length === 0"> <ng-container *ngIf="searchResults?.holdings?.length === 0">
@if (isLoading.assetProfiles) { @if (isLoading.holdings) {
<ngx-skeleton-loader <ngx-skeleton-loader
animation="pulse" animation="pulse"
class="mx-2" class="mx-2"
@ -84,15 +85,15 @@
} }
</ng-container> </ng-container>
</div> </div>
<div class="mt-3"> <div *ngIf="hasPermissionToAccessAdminControl" class="mt-3">
<div class="h6 mb-1 px-2" i18n>Quick Links</div> <div class="h6 mb-1 px-2" i18n>Asset Profiles</div>
<gf-assistant-list-item <gf-assistant-list-item
*ngFor="let searchResultItem of searchResults?.quickLinks" *ngFor="let searchResultItem of searchResults?.assetProfiles"
[item]="searchResultItem" [item]="searchResultItem"
(clicked)="onCloseAssistant()" (clicked)="onCloseAssistant()"
/> />
<ng-container *ngIf="searchResults?.quickLinks?.length === 0"> <ng-container *ngIf="searchResults?.assetProfiles?.length === 0">
@if (isLoading.quickLinks) { @if (isLoading.assetProfiles) {
<ngx-skeleton-loader <ngx-skeleton-loader
animation="pulse" animation="pulse"
class="mx-2" class="mx-2"

10
libs/ui/src/lib/assistant/interfaces/interfaces.ts

@ -3,11 +3,6 @@ import { DateRange } from '@ghostfolio/common/types';
import { SearchMode } from '../enums/search-mode'; import { SearchMode } from '../enums/search-mode';
export interface IDateRangeOption {
label: string;
value: DateRange;
}
export interface IAssetSearchResultItem extends AssetProfileIdentifier { export interface IAssetSearchResultItem extends AssetProfileIdentifier {
assetSubClassString: string; assetSubClassString: string;
currency: string; currency: string;
@ -15,6 +10,11 @@ export interface IAssetSearchResultItem extends AssetProfileIdentifier {
name: string; name: string;
} }
export interface IDateRangeOption {
label: string;
value: DateRange;
}
export interface IQuickLinkSearchResultItem { export interface IQuickLinkSearchResultItem {
mode: SearchMode.QUICK_LINK; mode: SearchMode.QUICK_LINK;
name: string; name: string;

Loading…
Cancel
Save