Merged PR 2061: feature(crm-data-access): Added check in customer resource if customerId has...

feature(crm-data-access): Added check in customer resource if customerId has changed to prevent flickering in the view after Filter changes etc.

Ref: #5478
This commit is contained in:
Nino Righi
2025-11-28 12:40:04 +00:00
committed by Lorenz Hilpert
parent c0cc0e1bbc
commit 3228abef44

View File

@@ -1,4 +1,11 @@
import { effect, inject, Injectable, resource, signal } from '@angular/core';
import {
effect,
inject,
Injectable,
resource,
signal,
untracked,
} from '@angular/core';
import { CrmSearchService, CrmTabMetadataService } from '../services';
import { TabService } from '@isa/core/tabs';
import { Customer } from '../schemas';
@@ -7,17 +14,20 @@ import { Customer } from '../schemas';
export class CustomerResource {
#customerService = inject(CrmSearchService);
#params = signal<{ customerId: number | undefined; eagerLoading: number }>({
protected _params = signal<{
customerId: number | undefined;
eagerLoading: number;
}>({
customerId: undefined,
eagerLoading: 3,
});
params(params: { customerId?: number; eagerLoading?: number }) {
this.#params.update((p) => ({ ...p, ...params }));
this._params.update((p) => ({ ...p, ...params }));
}
readonly resource = resource({
params: () => this.#params(),
params: () => this._params(),
loader: async ({ params, abortSignal }): Promise<Customer | undefined> => {
if (!params.customerId) {
return undefined;
@@ -45,12 +55,17 @@ export class SelectedCustomerResource extends CustomerResource {
super();
effect(() => {
const tabId = this.#tabId();
let customerId = undefined;
const customerId = tabId
? this.#customerMetadata.selectedCustomerId(tabId)
: undefined;
if (tabId) {
customerId = this.#customerMetadata.selectedCustomerId(tabId);
}
this.params({ customerId });
untracked(() => {
if (this._params().customerId !== customerId) {
this.params({ customerId });
}
});
});
}