mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
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:
committed by
Lorenz Hilpert
parent
c0cc0e1bbc
commit
3228abef44
@@ -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 { CrmSearchService, CrmTabMetadataService } from '../services';
|
||||||
import { TabService } from '@isa/core/tabs';
|
import { TabService } from '@isa/core/tabs';
|
||||||
import { Customer } from '../schemas';
|
import { Customer } from '../schemas';
|
||||||
@@ -7,17 +14,20 @@ import { Customer } from '../schemas';
|
|||||||
export class CustomerResource {
|
export class CustomerResource {
|
||||||
#customerService = inject(CrmSearchService);
|
#customerService = inject(CrmSearchService);
|
||||||
|
|
||||||
#params = signal<{ customerId: number | undefined; eagerLoading: number }>({
|
protected _params = signal<{
|
||||||
|
customerId: number | undefined;
|
||||||
|
eagerLoading: number;
|
||||||
|
}>({
|
||||||
customerId: undefined,
|
customerId: undefined,
|
||||||
eagerLoading: 3,
|
eagerLoading: 3,
|
||||||
});
|
});
|
||||||
|
|
||||||
params(params: { customerId?: number; eagerLoading?: number }) {
|
params(params: { customerId?: number; eagerLoading?: number }) {
|
||||||
this.#params.update((p) => ({ ...p, ...params }));
|
this._params.update((p) => ({ ...p, ...params }));
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly resource = resource({
|
readonly resource = resource({
|
||||||
params: () => this.#params(),
|
params: () => this._params(),
|
||||||
loader: async ({ params, abortSignal }): Promise<Customer | undefined> => {
|
loader: async ({ params, abortSignal }): Promise<Customer | undefined> => {
|
||||||
if (!params.customerId) {
|
if (!params.customerId) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -45,12 +55,17 @@ export class SelectedCustomerResource extends CustomerResource {
|
|||||||
super();
|
super();
|
||||||
effect(() => {
|
effect(() => {
|
||||||
const tabId = this.#tabId();
|
const tabId = this.#tabId();
|
||||||
|
let customerId = undefined;
|
||||||
|
|
||||||
const customerId = tabId
|
if (tabId) {
|
||||||
? this.#customerMetadata.selectedCustomerId(tabId)
|
customerId = this.#customerMetadata.selectedCustomerId(tabId);
|
||||||
: undefined;
|
}
|
||||||
|
|
||||||
this.params({ customerId });
|
untracked(() => {
|
||||||
|
if (this._params().customerId !== customerId) {
|
||||||
|
this.params({ customerId });
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user