Browse Source

Refactoring

pull/5656/head
Thomas Kaul 4 weeks ago
parent
commit
d236476dc9
  1. 40
      libs/ui/src/lib/assistant/assistant.component.ts

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

@ -172,8 +172,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
private readonly PRESELECTION_DELAY = 100;
private keyManager: FocusKeyManager<GfAssistantListItemComponent>;
private preselectionTimeout: ReturnType<typeof setTimeout>;
private unsubscribeSubject = new Subject<void>();
private filterTypes: Filter['type'][] = [
'ACCOUNT',
@ -183,6 +181,9 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
'TAG'
];
private preselectionTimeout: ReturnType<typeof setTimeout>;
private unsubscribeSubject = new Subject<void>();
public constructor(
private adminService: AdminService,
private changeDetectorRef: ChangeDetectorRef,
@ -348,6 +349,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
.subscribe({
next: (searchResults) => {
this.searchResults = searchResults;
this.preselectFirstItem();
this.changeDetectorRef.markForCheck();
@ -374,14 +376,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
});
}
public ngOnDestroy() {
if (this.preselectionTimeout) {
clearTimeout(this.preselectionTimeout);
}
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
public ngOnChanges() {
this.accounts = this.user?.accounts ?? [];
@ -598,27 +592,34 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
this.isOpen = aIsOpen;
}
public ngOnDestroy() {
if (this.preselectionTimeout) {
clearTimeout(this.preselectionTimeout);
}
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
private getCurrentAssistantListItem() {
return this.assistantListItems.find(({ getHasFocus }) => {
return getHasFocus;
});
}
/**
* Gets the first search result item based on priority order:
* Quick Links Accounts Holdings Asset Profiles
*/
private getFirstSearchResultItem() {
// Priority order: Quick Links → Accounts → Holdings → Asset Profiles
if (this.searchResults.quickLinks?.length > 0) {
return this.searchResults.quickLinks[0];
}
if (this.searchResults.accounts?.length > 0) {
return this.searchResults.accounts[0];
}
if (this.searchResults.holdings?.length > 0) {
return this.searchResults.holdings[0];
}
if (this.searchResults.assetProfiles?.length > 0) {
return this.searchResults.assetProfiles[0];
}
@ -626,18 +627,12 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
return null;
}
/**
* Preselects the first search result item with debouncing
*/
private preselectFirstItem() {
// Clear any existing timeout
if (this.preselectionTimeout) {
clearTimeout(this.preselectionTimeout);
}
// Debounce preselection to handle rapid search changes
this.preselectionTimeout = setTimeout(() => {
// Check if we have search results and the assistant is open
if (!this.isOpen || !this.searchFormControl.value) {
return;
}
@ -648,15 +643,12 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
return;
}
// Clear any existing focus
for (const item of this.assistantListItems) {
item.removeFocus();
}
// Set the first item as active in the key manager
this.keyManager.setFirstItemActive();
// Get the currently focused item and apply focus styling
const currentFocusedItem = this.getCurrentAssistantListItem();
if (currentFocusedItem) {

Loading…
Cancel
Save