From c12cdddeb56b65b6cc2ffbdb01b62a30845fda37 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Mon, 25 Mar 2024 15:37:32 +0200 Subject: [PATCH] RED-8711 - Filter out entity log entries that have no positions and show a toast message in dev mode --- .../services/files/redaction-log.service.ts | 18 +++++++++++++++--- libs/common-ui | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/red-ui/src/app/services/files/redaction-log.service.ts b/apps/red-ui/src/app/services/files/redaction-log.service.ts index 4256806ee..e965c2e1b 100644 --- a/apps/red-ui/src/app/services/files/redaction-log.service.ts +++ b/apps/red-ui/src/app/services/files/redaction-log.service.ts @@ -1,6 +1,6 @@ -import { Injectable } from '@angular/core'; -import { GenericService, QueryParam, RequiredParam, Validate } from '@iqser/common-ui'; -import { IRedactionLog, ISectionGrid } from '@red/domain'; +import { inject, Injectable } from '@angular/core'; +import { GenericService, QueryParam, RequiredParam, Toaster, Validate } from '@iqser/common-ui'; +import { IRedactionLog, IRedactionLogEntry, ISectionGrid } from '@red/domain'; import { catchError, tap } from 'rxjs/operators'; import { of } from 'rxjs'; @@ -9,6 +9,7 @@ import { of } from 'rxjs'; }) export class RedactionLogService extends GenericService { protected readonly _defaultModelPath = ''; + readonly #toaster = inject(Toaster); @Validate() getRedactionLog(@RequiredParam() dossierId: string, @RequiredParam() fileId: string, withManualRedactions?: boolean) { @@ -19,6 +20,7 @@ export class RedactionLogService extends GenericService { const redactionLog$ = this._getOne([dossierId, fileId], 'redactionLog', queryParams); return redactionLog$.pipe( + tap(redactionLog => (redactionLog.redactionLogEntry = this.#filterInvalidEntries(redactionLog.redactionLogEntry))), tap(redactionLog => redactionLog.redactionLogEntry.sort((a, b) => a.positions[0].page - b.positions[0].page)), catchError(() => of({} as IRedactionLog)), ); @@ -28,4 +30,14 @@ export class RedactionLogService extends GenericService { getSectionGrid(@RequiredParam() dossierId: string, @RequiredParam() fileId: string) { return this._getOne([dossierId, fileId], 'sectionGrid'); } + + #filterInvalidEntries(redactionLogEntry: IRedactionLogEntry[]) { + return redactionLogEntry.filter(entry => { + const hasPositions = !!entry.positions?.length; + if (!hasPositions) { + this.#toaster.devInfo(`Entry ${entry.id} was skipped because it has no position`); + } + return hasPositions; + }); + } } diff --git a/libs/common-ui b/libs/common-ui index d6f712232..8b304a727 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit d6f712232942f41a47d652cfb6dabc9d6b1694c7 +Subproject commit 8b304a7279bf5f15b86a0b8e6c5041406cbfbf1b