filter removed entries
This commit is contained in:
parent
74b4c1a11f
commit
5d7849be45
@ -93,10 +93,6 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
|
||||
});
|
||||
}
|
||||
|
||||
removeAnnotations(id: string[]) {
|
||||
this.#annotations.update(old => old.filter(annotation => !id.includes(annotation.id)));
|
||||
}
|
||||
|
||||
setEntities(entities: AnnotationWrapper[]): void {
|
||||
// this is a light version of setEntities to skip looping too much
|
||||
// used mostly for earmarks (which are usually a lot)
|
||||
@ -154,12 +150,7 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
|
||||
|
||||
this.#logger.info('[REDACTION_LOG] Redaction log loaded', redactionLog);
|
||||
const annotations = await this.processEntityLog(redactionLog);
|
||||
this.#annotations.update(old => {
|
||||
const notUpdated = old.filter(oldAnnotation => {
|
||||
return !annotations.some(newAnnotation => newAnnotation.id === oldAnnotation.id);
|
||||
});
|
||||
return [...notUpdated, ...annotations].sort((a, b) => a.positions[0].page - b.positions[0].page);
|
||||
});
|
||||
this.#annotations.set(annotations);
|
||||
}
|
||||
|
||||
async processEntityLog(entityLog: IEntityLog) {
|
||||
@ -175,11 +166,12 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
|
||||
log('[REDACTION_LOG] Delta loaded'),
|
||||
switchMap(delta => this.processEntityLog(delta)),
|
||||
tap(annotations => {
|
||||
const notDeleted = annotations.filter(annotation => !annotation.isRemoved);
|
||||
this.#annotations.update(old => {
|
||||
const notUpdated = old.filter(oldAnnotation => {
|
||||
return !oldAnnotation.pending && !annotations.some(newAnnotation => newAnnotation.id === oldAnnotation.id);
|
||||
});
|
||||
return [...notUpdated, ...annotations].sort((a, b) => a.positions[0].page - b.positions[0].page);
|
||||
return [...notUpdated, ...notDeleted].sort((a, b) => a.positions[0].page - b.positions[0].page);
|
||||
});
|
||||
}),
|
||||
tap(() => this.#logger.info('[REDACTION_LOG] Annotations updated', this.#annotations())),
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { GenericService, Toaster } from '@iqser/common-ui';
|
||||
import { EntryStates, IEntityLog, IEntityLogEntry, ISectionGrid } from '@red/domain';
|
||||
import { EntryState, EntryStates, IEntityLog, IEntityLogEntry, ISectionGrid } from '@red/domain';
|
||||
import { firstValueFrom, of } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
@ -15,7 +15,7 @@ export class EntityLogService extends GenericService<unknown> {
|
||||
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 = this.#filterInvalidEntries(entityLog.entityLogEntry, [EntryStates.REMOVED]);
|
||||
entityLog.entityLogEntry.sort((a, b) => a.positions[0].pageNumber - b.positions[0].pageNumber);
|
||||
return entityLog;
|
||||
}
|
||||
@ -35,15 +35,15 @@ export class EntityLogService extends GenericService<unknown> {
|
||||
return this._getOne<ISectionGrid>([dossierId, fileId], 'sectionGrid');
|
||||
}
|
||||
|
||||
#filterInvalidEntries(entityLogEntry: IEntityLogEntry[]) {
|
||||
#filterInvalidEntries(entityLogEntry: IEntityLogEntry[], invalidStates: EntryState[] = []) {
|
||||
return entityLogEntry.filter(entry => {
|
||||
entry.positions = entry.positions?.filter(p => !!p.rectangle?.length);
|
||||
const hasPositions = !!entry.positions?.length;
|
||||
const isRemoved = entry.state === EntryStates.REMOVED;
|
||||
const hasInvalidState = invalidStates.includes(entry.state);
|
||||
if (!hasPositions) {
|
||||
this.#toaster.devInfo(`Entry ${entry.id} was skipped because it has no position`);
|
||||
}
|
||||
return hasPositions && !isRemoved;
|
||||
return hasPositions && !hasInvalidState;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user