Merged PR 2065: ♻️ refactor(core-navigation): remove library and use TabService directly

♻️ refactor(core-navigation): remove library and use TabService directly

Remove @isa/core/navigation library entirely as it was just a thin
wrapper around TabService.patchTabMetadata(). Consumers now use
TabService directly for scoped metadata operations.

Changes:
- Delete libs/core/navigation/ (~12 files, ~2900 LOC removed)
- Update 6 consumer components to use TabService directly
- Remove @isa/core/navigation path alias from tsconfig.base.json
- All operations now synchronous (removed async/await)

Migration pattern:
- preserveContext() → patchTabMetadata(tabId, { [scope]: data })
- restoreContext() → activatedTab()?.metadata?.[scope]
- restoreAndClearContext() → get + patchTabMetadata(tabId, { [scope]: null })

Refs #5502
This commit is contained in:
Lorenz Hilpert
2025-12-02 15:41:18 +00:00
committed by Nino Righi
parent a3c865e39c
commit fdfb54a3a0
23 changed files with 82 additions and 2937 deletions

View File

@@ -9,8 +9,7 @@ import { DecimalPipe } from '@angular/common';
import { Component, Input, OnInit, inject } from '@angular/core';
import { IconComponent } from '@shared/components/icon';
import { BonusCardInfoDTO } from '@generated/swagger/crm-api';
import { injectTabId } from '@isa/core/tabs';
import { NavigationStateService } from '@isa/core/navigation';
import { injectTabId, TabService } from '@isa/core/tabs';
import { Router } from '@angular/router';
import { CustomerSearchNavigation } from '@shared/services/navigation';
@@ -47,7 +46,7 @@ import { CustomerSearchNavigation } from '@shared/services/navigation';
export class KundenkarteComponent implements OnInit {
#tabId = injectTabId();
#router = inject(Router);
#navigationState = inject(NavigationStateService);
#tabService = inject(TabService);
#customerNavigationService = inject(CustomerSearchNavigation);
@Input() cardDetails: BonusCardInfoDTO;
@@ -69,13 +68,12 @@ export class KundenkarteComponent implements OnInit {
return;
}
this.#navigationState.preserveContext(
{
this.#tabService.patchTabMetadata(tabId, {
'select-customer': {
returnUrl: `/${tabId}/reward`,
autoTriggerContinueFn: true,
},
'select-customer',
);
});
await this.#router.navigate(
this.#customerNavigationService.detailsRoute({

View File

@@ -49,9 +49,14 @@ import {
NavigateAfterRewardSelection,
RewardSelectionPopUpService,
} from '@isa/checkout/shared/reward-selection-dialog';
import { NavigationStateService } from '@isa/core/navigation';
import { TabService } from '@isa/core/tabs';
import { ShippingAddressDTO as CrmShippingAddressDTO } from '@generated/swagger/crm-api';
interface SelectCustomerContext {
returnUrl?: string;
autoTriggerContinueFn?: boolean;
}
export interface CustomerDetailsViewMainState {
isBusy: boolean;
shoppingCart: ShoppingCartDTO;
@@ -80,7 +85,7 @@ export class CustomerDetailsViewMainComponent
private _router = inject(Router);
private _activatedRoute = inject(ActivatedRoute);
private _genderSettings = inject(GenderSettingsService);
private _navigationState = inject(NavigationStateService);
private _tabService = inject(TabService);
private _onDestroy$ = new Subject<void>();
customerService = inject(CrmCustomerService);
@@ -97,18 +102,19 @@ export class CustomerDetailsViewMainComponent
map(([fetchingCustomer, fetchingList]) => fetchingCustomer || fetchingList),
);
async getReturnUrlFromContext(): Promise<string | null> {
// Get from preserved context (survives intermediate navigations, auto-scoped to tab)
const context = await this._navigationState.restoreContext<{
returnUrl?: string;
}>('select-customer');
getReturnUrlFromContext(): string | null {
// Get from preserved context (survives intermediate navigations, scoped to tab)
const context = this._tabService.activatedTab()?.metadata?.[
'select-customer'
] as SelectCustomerContext | undefined;
return context?.returnUrl ?? null;
}
async checkHasReturnUrl(): Promise<void> {
const hasContext =
await this._navigationState.hasPreservedContext('select-customer');
checkHasReturnUrl(): void {
const hasContext = !!this._tabService.activatedTab()?.metadata?.[
'select-customer'
];
this.hasReturnUrl.set(hasContext);
}
@@ -321,24 +327,23 @@ export class CustomerDetailsViewMainComponent
ngOnInit() {
// Check if we have a return URL context
this.checkHasReturnUrl().then(async () => {
// Check if we should auto-trigger continue() (only from Kundenkarte)
const context = await this._navigationState.restoreContext<{
returnUrl?: string;
autoTriggerContinueFn?: boolean;
}>('select-customer');
this.checkHasReturnUrl();
if (context?.autoTriggerContinueFn) {
// Clear the autoTriggerContinueFn flag immediately (preserves returnUrl automatically)
await this._navigationState.patchContext(
{ autoTriggerContinueFn: undefined },
'select-customer',
);
// Check if we should auto-trigger continue() (only from Kundenkarte)
const tab = this._tabService.activatedTab();
const context = tab?.metadata?.['select-customer'] as
| SelectCustomerContext
| undefined;
// Auto-trigger continue() ONLY when coming from Kundenkarte
this.continue();
}
});
if (context?.autoTriggerContinueFn && tab) {
// Clear the autoTriggerContinueFn flag immediately (preserves returnUrl)
this._tabService.patchTabMetadata(tab.id, {
'select-customer': { ...context, autoTriggerContinueFn: undefined },
});
// Auto-trigger continue() ONLY when coming from Kundenkarte
this.continue();
}
this.processId$
.pipe(
@@ -436,10 +441,18 @@ export class CustomerDetailsViewMainComponent
// #5262 Check for reward selection flow before navigation
if (this.hasReturnUrl()) {
// Restore from preserved context (auto-scoped to current tab) and clean up
const context = await this._navigationState.restoreAndClearContext<{
returnUrl?: string;
}>('select-customer');
// Restore from preserved context (scoped to current tab) and clean up
const tab = this._tabService.activatedTab();
const context = tab?.metadata?.['select-customer'] as
| SelectCustomerContext
| undefined;
// Clear the context
if (tab) {
this._tabService.patchTabMetadata(tab.id, {
'select-customer': null,
});
}
if (context?.returnUrl) {
await this._router.navigateByUrl(context.returnUrl);

View File

@@ -10,7 +10,7 @@ import {
import { CustomerSearchStore } from '../store';
import { ActivatedRoute, Router } from '@angular/router';
import { map } from 'rxjs/operators';
import { NavigationStateService } from '@isa/core/navigation';
import { TabService } from '@isa/core/tabs';
import { CustomerSearchNavigation } from '@shared/services/navigation';
import { AsyncPipe } from '@angular/common';
import { CustomerMenuComponent } from '../../components/customer-menu';
@@ -51,7 +51,7 @@ export class KundenkarteMainViewComponent implements OnDestroy {
#cardTransactionsResource = inject(CustomerCardTransactionsResource);
elementRef = inject(ElementRef);
#router = inject(Router);
#navigationState = inject(NavigationStateService);
#tabService = inject(TabService);
#customerNavigationService = inject(CustomerSearchNavigation);
/**
@@ -120,13 +120,12 @@ export class KundenkarteMainViewComponent implements OnDestroy {
}
// Preserve context for auto-triggering continue() in details view
this.#navigationState.preserveContext(
{
this.#tabService.patchTabMetadata(tabId, {
'select-customer': {
returnUrl: `/${tabId}/reward`,
autoTriggerContinueFn: true,
},
'select-customer',
);
});
// Navigate to customer details - will auto-trigger continue()
await this.#router.navigate(