From e2b4f675615415c3cc23453f017c1259e65bba10 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 16 Jan 2024 16:22:52 +0200 Subject: [PATCH] RED-7903 - Show dummy redaction/hints while file is still processing --- libs/red-domain/src/lib/files/super-types.ts | 35 +++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/libs/red-domain/src/lib/files/super-types.ts b/libs/red-domain/src/lib/files/super-types.ts index 960258c34..27412a27e 100644 --- a/libs/red-domain/src/lib/files/super-types.ts +++ b/libs/red-domain/src/lib/files/super-types.ts @@ -18,33 +18,36 @@ function wrongSuperTypeHandler(): never | undefined { return undefined; } +function resolveRedactionType(entry: IEntityLogEntry, hint = false) { + const redaction = hint ? SuperTypes.Hint : SuperTypes.Redaction; + const manualRedaction = hint ? SuperTypes.ManualHint : SuperTypes.ManualRedaction; + + const manualChanges = entry.manualChanges; + const hasEngines = entry.engines.length; + const lastRelevantManualChange = manualChanges?.at(-1); + if (!!lastRelevantManualChange && !hasEngines) { + const pending = lastRelevantManualChange && !lastRelevantManualChange.processed; + if (pending && entry.dictionaryEntry) { + return redaction; + } + return manualRedaction; + } + return redaction; +} + /** * https://knecon.atlassian.net/wiki/spaces/RED/pages/102072322/EntityLog+-+Enum+combinations */ export const SuperTypeMapper: Record SuperType | undefined>> = { [EntityTypes.ENTITY]: { - [EntryStates.APPLIED]: entry => { - const hasManualChanges = entry.manualChanges.length; - const hasEngines = entry.engines.length; - if (hasManualChanges && !hasEngines) { - return SuperTypes.ManualRedaction; - } - return SuperTypes.Redaction; - }, + [EntryStates.APPLIED]: entry => resolveRedactionType(entry), [EntryStates.SKIPPED]: () => SuperTypes.Skipped, [EntryStates.IGNORED]: () => SuperTypes.Skipped, [EntryStates.REMOVED]: wrongSuperTypeHandler, }, [EntityTypes.HINT]: { [EntryStates.APPLIED]: wrongSuperTypeHandler, - [EntryStates.SKIPPED]: entry => { - const hasManualChanges = entry.manualChanges.length; - const hasEngines = entry.engines.length; - if (hasManualChanges && !hasEngines) { - return SuperTypes.ManualHint; - } - return SuperTypes.Hint; - }, + [EntryStates.SKIPPED]: entry => resolveRedactionType(entry, true), [EntryStates.IGNORED]: () => SuperTypes.IgnoredHint, [EntryStates.REMOVED]: wrongSuperTypeHandler, },