RED-8711 - Filter out entity log entries that have no positions and show a toast message in dev mode

This commit is contained in:
Valentin Mihai 2024-03-25 12:08:26 +02:00
parent 25f4895017
commit 0aacc165bf
2 changed files with 17 additions and 7 deletions

View File

@ -190,10 +190,6 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
continue;
}
if (entry.state === EntryStates.REMOVED) {
continue;
}
const canBeMappedToASuperType = !!SuperTypeMapper[entry.entryType][entry.state](entry);
if (!canBeMappedToASuperType) {
if (this.#isIqserDevMode) {

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { GenericService } from '@iqser/common-ui';
import { IEntityLog, ISectionGrid } from '@red/domain';
import { inject, Injectable } from '@angular/core';
import { GenericService, isIqserDevMode, Toaster } from '@iqser/common-ui';
import { EntryStates, IEntityLog, IEntityLogEntry, ISectionGrid } from '@red/domain';
import { firstValueFrom, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
@ -9,11 +9,14 @@ import { catchError } from 'rxjs/operators';
})
export class EntityLogService extends GenericService<unknown> {
protected readonly _defaultModelPath = '';
readonly #isIqserDevMode = isIqserDevMode();
readonly #toaster = inject(Toaster);
async getEntityLog(dossierId: string, fileId: string) {
const queryParams = [{ key: 'includeUnprocessed', value: true }];
const entityLog$ = this._getOne<IEntityLog>([dossierId, fileId], 'entityLog', queryParams);
const entityLog = await firstValueFrom(entityLog$.pipe(catchError(() => of({} as IEntityLog))));
entityLog.entityLogEntry = this.#filterInvalidEntries(entityLog.entityLogEntry);
entityLog.entityLogEntry.sort((a, b) => a.positions[0].pageNumber - b.positions[0].pageNumber);
return entityLog;
}
@ -21,4 +24,15 @@ export class EntityLogService extends GenericService<unknown> {
getSectionGrid(dossierId: string, fileId: string) {
return this._getOne<ISectionGrid>([dossierId, fileId], 'sectionGrid');
}
#filterInvalidEntries(entityLogEntry: IEntityLogEntry[]) {
return entityLogEntry.filter(entry => {
const hasPositions = !!entry.positions?.length;
const isRemoved = entry.state === EntryStates.REMOVED;
if (!hasPositions) {
this.#toaster.devInfo(`Entry ${entry.id} was skipped because it has no position`);
}
return hasPositions && !isRemoved;
});
}
}