mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Enhance return search store with new methods and hooks for entity management.
- ✨ **Feature**: Added method to remove entities by process ID - ✨ **Feature**: Implemented onInit hook to clear entities based on process IDs - 🛠️ **Refactor**: Updated imports for clarity and organization - 🛠️ **Refactor**: Improved entity management logic in return search store
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
import { patchState, signalStore, type, withMethods } from '@ngrx/signals';
|
||||
import { patchState, signalStore, type, withHooks, withMethods } from '@ngrx/signals';
|
||||
import { rxMethod } from '@ngrx/signals/rxjs-interop';
|
||||
import { addEntity, entityConfig, updateEntity, withEntities } from '@ngrx/signals/entities';
|
||||
import {
|
||||
addEntity,
|
||||
entityConfig,
|
||||
setAllEntities,
|
||||
updateEntity,
|
||||
withEntities,
|
||||
} from '@ngrx/signals/entities';
|
||||
import { pipe, switchMap, tap } from 'rxjs';
|
||||
import { ReturnSearchService } from './return-search.service';
|
||||
import { tapResponse } from '@ngrx/operators';
|
||||
import { inject } from '@angular/core';
|
||||
import { effect, inject } from '@angular/core';
|
||||
import { QueryTokenSchema } from './schemas';
|
||||
import { Callback, ListResponseArgs } from '@isa/common/result';
|
||||
import { ReceiptListItem } from './models';
|
||||
import { Query } from '@isa/shared/filter';
|
||||
import { SessionStorageProvider, withStorage } from '@isa/core/storage';
|
||||
import { ProcessService } from '@isa/core/process';
|
||||
|
||||
/**
|
||||
* Enum representing the status of a return search process.
|
||||
@@ -54,6 +61,10 @@ export const ReturnSearchStore = signalStore(
|
||||
getEntity(processId: number): ReturnSearchEntity | undefined {
|
||||
return store.entities().find((e) => e.processId === processId);
|
||||
},
|
||||
removeAllEntitiesByProcessId(processId: number) {
|
||||
const entities = store.entities().filter((entity) => entity.processId !== processId);
|
||||
patchState(store, setAllEntities(entities, config));
|
||||
},
|
||||
})),
|
||||
withMethods((store) => ({
|
||||
/**
|
||||
@@ -197,4 +208,15 @@ export const ReturnSearchStore = signalStore(
|
||||
),
|
||||
),
|
||||
})),
|
||||
withHooks((store, processService = inject(ProcessService)) => ({
|
||||
onInit() {
|
||||
effect(() => {
|
||||
const processIds = processService.ids();
|
||||
const entities = store.entities().find((entity) => !processIds.includes(entity.processId));
|
||||
if (entities) {
|
||||
store.removeAllEntitiesByProcessId(entities.processId);
|
||||
}
|
||||
});
|
||||
},
|
||||
})),
|
||||
);
|
||||
|
||||
@@ -68,7 +68,7 @@ export function injectRestoreScrollPosition(): () => Promise<void> {
|
||||
if (position) {
|
||||
// wait for the next tick to ensure the DOM is ready
|
||||
await new Promise((r) => setTimeout(r, delay));
|
||||
|
||||
sessionStorage.clear(url);
|
||||
viewportScroller.scrollToPosition(position as [number, number]);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user