From 34595d5ca4d27b96a40952f321d7539ffa26a7db Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 3 Jan 2023 20:52:54 +0200 Subject: [PATCH] RED-5845 - Suggestion still available in cache after re-upload file with keepManualChanges=false --- .../services/file-data.service.ts | 92 ++++++++++--------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts index ef04cce80..975f77543 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts @@ -179,17 +179,19 @@ export class FileDataService extends EntitiesService { - const redactionLogCopy = JSON.parse(JSON.stringify(redactionLog)); - redactionLogCopy.redactionLogEntry = redactionLogCopy.redactionLogEntry.reduce((filtered, entry) => { - const lastChange = entry.manualChanges.at(-1); - const isRemoveChange = this.#isRemoveChange(lastChange?.manualRedactionType); - if (isRemoveChange) { - entry.manualChanges.pop(); - filtered.push(entry); - } - return filtered; - }, []); - this._suggestionsService.removedRedactions = await this.#buildAnnotations(redactionLogCopy, file); + if (redactionLog.redactionLogEntry) { + const redactionLogCopy = JSON.parse(JSON.stringify(redactionLog)); + redactionLogCopy.redactionLogEntry = redactionLogCopy.redactionLogEntry?.reduce((filtered, entry) => { + const lastChange = entry.manualChanges.at(-1); + const isRemoveChange = this.#isRemoveChange(lastChange?.manualRedactionType); + if (isRemoveChange) { + entry.manualChanges.pop(); + filtered.push(entry); + } + return filtered; + }, []); + this._suggestionsService.removedRedactions = await this.#buildAnnotations(redactionLogCopy, file); + } } #isRemoveChange(type: ManualRedactionType) { @@ -201,41 +203,43 @@ export class FileDataService extends EntitiesService dict.type === redactionLogEntry.type); - if (!dictionary && checkDictionary) { - const dictionaryRequest = this._dictionaryService.loadDictionaryDataForDossierTemplate(this._state.dossierTemplateId); - await firstValueFrom(dictionaryRequest); - checkDictionary = false; - dictionary = this._state.dictionaries.find(dict => dict.type === redactionLogEntry.type); - } - - if (!dictionary) { - this.missingTypes.add(redactionLogEntry.type); - continue; - } - - const redactionLogEntryWrapper: RedactionLogEntry = new RedactionLogEntry( - redactionLogEntry, - changeLogValues.changeLogType, - changeLogValues.isChangeLogEntry, - redactionLog.legalBasis, - !!dictionary?.hint, - ); - - if (redactionLogEntry.sourceId) { - if (!sourceIdAnnotationIds[redactionLogEntry.sourceId]) { - sourceIdAnnotationIds[redactionLogEntry.sourceId] = []; + if (redactionLog.redactionLogEntry) { + for (const redactionLogEntry of redactionLog.redactionLogEntry) { + const changeLogValues = this.#getChangeLogValues(redactionLogEntry, file); + if (changeLogValues.hidden) { + continue; } - sourceIdAnnotationIds[redactionLogEntry.sourceId].push(redactionLogEntryWrapper); - } - result.push(redactionLogEntryWrapper); + let dictionary = this._state.dictionaries.find(dict => dict.type === redactionLogEntry.type); + if (!dictionary && checkDictionary) { + const dictionaryRequest = this._dictionaryService.loadDictionaryDataForDossierTemplate(this._state.dossierTemplateId); + await firstValueFrom(dictionaryRequest); + checkDictionary = false; + dictionary = this._state.dictionaries.find(dict => dict.type === redactionLogEntry.type); + } + + if (!dictionary) { + this.missingTypes.add(redactionLogEntry.type); + continue; + } + + const redactionLogEntryWrapper: RedactionLogEntry = new RedactionLogEntry( + redactionLogEntry, + changeLogValues.changeLogType, + changeLogValues.isChangeLogEntry, + redactionLog.legalBasis, + !!dictionary?.hint, + ); + + if (redactionLogEntry.sourceId) { + if (!sourceIdAnnotationIds[redactionLogEntry.sourceId]) { + sourceIdAnnotationIds[redactionLogEntry.sourceId] = []; + } + sourceIdAnnotationIds[redactionLogEntry.sourceId].push(redactionLogEntryWrapper); + } + + result.push(redactionLogEntryWrapper); + } } const sourceKeys = Object.keys(sourceIdAnnotationIds);