From bf41ec9bf9a02bd8544613b8b28a492b7d919d7f Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Wed, 24 May 2023 01:34:59 +0300 Subject: [PATCH] RED-6813: check for undefined --- .../src/app/models/file/annotation.wrapper.ts | 38 +++++----- .../app/models/file/redaction-log.entry.ts | 72 +++++++++---------- .../combo-series-vertical.component.ts | 5 +- .../license/combo-chart/y-axis.component.ts | 4 +- .../services/file-data.service.ts | 20 +++--- .../src/lib/redaction-log/change.ts | 6 +- .../lib/redaction-log/redaction-log-entry.ts | 2 +- 7 files changed, 72 insertions(+), 75 deletions(-) diff --git a/apps/red-ui/src/app/models/file/annotation.wrapper.ts b/apps/red-ui/src/app/models/file/annotation.wrapper.ts index 2af491b38..6c19db2d8 100644 --- a/apps/red-ui/src/app/models/file/annotation.wrapper.ts +++ b/apps/red-ui/src/app/models/file/annotation.wrapper.ts @@ -57,10 +57,10 @@ export class AnnotationWrapper implements IListable, Record { image?: boolean; manual?: boolean; pending = false; - hintDictionary?: boolean; + hintDictionary = false; textAfter?: string; textBefore?: string; - isChangeLogEntry?: boolean; + isChangeLogEntry = false; changeLogType?: 'ADDED' | 'REMOVED' | 'CHANGED'; engines?: string[]; hasBeenResized: boolean; @@ -326,13 +326,13 @@ export class AnnotationWrapper implements IListable, Record { c => c.manualRedactionType === ManualRedactionTypes.LEGAL_BASIS_CHANGE && c.annotationStatus === LogEntryStatuses.REQUESTED, )?.propertyChanges.legalBasis; - this._createContent(annotationWrapper, redactionLogEntry); - this._setSuperType(annotationWrapper, redactionLogEntry); - this._handleRecommendations(annotationWrapper, redactionLogEntry); + this.#createContent(annotationWrapper, redactionLogEntry); + this.#setSuperType(annotationWrapper, redactionLogEntry); + this.#handleRecommendations(annotationWrapper, redactionLogEntry); annotationWrapper.typeLabel = this.#getTypeLabel(redactionLogEntry, annotationWrapper); const entity = dictionaries.find(d => d.type === annotationWrapper.typeValue); - annotationWrapper.entity = entity.virtual ? null : entity; + annotationWrapper.entity = entity?.virtual ? null : entity; const colorKey = annotationWrapper.isSuperTypeBasedColor ? annotationDefaultColorConfig[annotationWrapper.superType] @@ -349,23 +349,23 @@ export class AnnotationWrapper implements IListable, Record { return annotationTypesTranslations[annotation.superType]; } - private static _handleRecommendations(annotationWrapper: AnnotationWrapper, redactionLogEntry: RedactionLogEntry) { + static #handleRecommendations(annotationWrapper: AnnotationWrapper, redactionLogEntry: RedactionLogEntry) { if (annotationWrapper.superType === SuperTypes.Recommendation) { annotationWrapper.recommendationType = redactionLogEntry.type; } } - private static _getLastRelevantManualChange(manualChanges: IManualChange[]) { + static #getLastRelevantManualChange(manualChanges: IManualChange[]) { return manualChanges[manualChanges.length - 1]; } - private static _setSuperType(annotationWrapper: AnnotationWrapper, redactionLogEntryWrapper: RedactionLogEntry) { + static #setSuperType(annotationWrapper: AnnotationWrapper, redactionLogEntryWrapper: RedactionLogEntry) { if (redactionLogEntryWrapper.manualChanges?.length) { - const lastRelevantManualChange = this._getLastRelevantManualChange(redactionLogEntryWrapper.manualChanges); + const lastRelevantManualChange = this.#getLastRelevantManualChange(redactionLogEntryWrapper.manualChanges); const viableChanges = redactionLogEntryWrapper.changes.filter(c => c.analysisNumber > 1); const lastChange = viableChanges.sort(chronologicallyBy(x => x.dateTime)).at(-1); const lastChangeOccurredAfterLastManualChange = - timestampOf(lastChange.dateTime) > timestampOf(lastRelevantManualChange.processedDate); + lastChange && timestampOf(lastChange.dateTime) > timestampOf(lastRelevantManualChange.processedDate); if (lastChangeOccurredAfterLastManualChange && lastChange.type === ChangeTypes.ADDED && redactionLogEntryWrapper.redacted) { annotationWrapper.superType = SuperTypes.Redaction; @@ -374,7 +374,7 @@ export class AnnotationWrapper implements IListable, Record { annotationWrapper.pending = !lastRelevantManualChange.processed; - annotationWrapper.superType = AnnotationWrapper._selectSuperType( + annotationWrapper.superType = AnnotationWrapper.#selectSuperType( redactionLogEntryWrapper, lastRelevantManualChange, annotationWrapper.hintDictionary, @@ -396,7 +396,7 @@ export class AnnotationWrapper implements IListable, Record { } } - private static _createContent(annotationWrapper: AnnotationWrapper, entry: RedactionLogEntry) { + static #createContent(annotationWrapper: AnnotationWrapper, entry: RedactionLogEntry) { let content = ''; if (entry.matchedRule) { content += `Rule ${entry.matchedRule} matched \n\n`; @@ -425,13 +425,13 @@ export class AnnotationWrapper implements IListable, Record { content += `${prefix} "${entry.section}"`; } - annotationWrapper.shortContent = this._getShortContent(annotationWrapper, entry) || content; + annotationWrapper.shortContent = this.#getShortContent(annotationWrapper, entry) || content; annotationWrapper.content = content; } - private static _getShortContent(annotationWrapper: AnnotationWrapper, entry: RedactionLogEntry) { + static #getShortContent(annotationWrapper: AnnotationWrapper, entry: RedactionLogEntry) { if (annotationWrapper.legalBasis) { - const lb = entry.legalBasisList?.find(lbm => lbm.reason.toLowerCase().includes(annotationWrapper.legalBasis.toLowerCase())); + const lb = entry.legalBasisList?.find(lbm => lbm.reason?.toLowerCase().includes(annotationWrapper.legalBasis.toLowerCase())); if (lb) { return lb.name; } @@ -440,11 +440,7 @@ export class AnnotationWrapper implements IListable, Record { return annotationWrapper.legalBasis; } - private static _selectSuperType( - redactionLogEntry: RedactionLogEntry, - lastManualChange: IManualChange, - isHintDictionary: boolean, - ): SuperType { + static #selectSuperType(redactionLogEntry: RedactionLogEntry, lastManualChange: IManualChange, isHintDictionary: boolean): SuperType { switch (lastManualChange.manualRedactionType) { case ManualRedactionTypes.ADD_LOCALLY: switch (lastManualChange.annotationStatus) { diff --git a/apps/red-ui/src/app/models/file/redaction-log.entry.ts b/apps/red-ui/src/app/models/file/redaction-log.entry.ts index f6972f3e5..5cfa5f91f 100644 --- a/apps/red-ui/src/app/models/file/redaction-log.entry.ts +++ b/apps/red-ui/src/app/models/file/redaction-log.entry.ts @@ -2,27 +2,27 @@ import { IChange, IComment, ILegalBasis, IManualChange, IRectangle, IRedactionLo // TODO: this should be removed. Use only AnnotationWrapper class export class RedactionLogEntry implements IRedactionLogEntry { - readonly changes?: IChange[]; - readonly imported?: boolean; - readonly manualChanges?: IManualChange[]; - readonly color?: number[]; - readonly comments?: IComment[]; - readonly dictionaryEntry?: boolean; - readonly dossierDictionaryEntry?: boolean; + readonly changes: IChange[]; + readonly imported: boolean; + readonly manualChanges: IManualChange[]; + readonly color: number[]; + readonly comments: IComment[]; + readonly dictionaryEntry: boolean; + readonly dossierDictionaryEntry: boolean; readonly endOffset?: number; - readonly engines?: LogEntryEngine[]; - readonly excluded?: boolean; - readonly hint?: boolean; - readonly rectangle?: boolean; - readonly id?: string; - readonly image?: boolean; - readonly imageHasTransparency?: boolean; + readonly engines: LogEntryEngine[]; + readonly excluded: boolean; + readonly hint: boolean; + readonly rectangle: boolean; + readonly id: string; + readonly image: boolean; + readonly imageHasTransparency: boolean; readonly legalBasis?: string; readonly matchedRule?: number; - readonly positions?: IRectangle[]; - readonly recommendation?: boolean; - readonly redacted?: boolean; - readonly reference?: string[]; + readonly positions: IRectangle[]; + readonly recommendation: boolean; + readonly redacted: boolean; + readonly reference: string[]; readonly section?: string; readonly sectionNumber?: number; readonly startOffset?: number; @@ -37,31 +37,31 @@ export class RedactionLogEntry implements IRedactionLogEntry { constructor( redactionLogEntry: IRedactionLogEntry, - readonly changeLogType: 'ADDED' | 'REMOVED' | 'CHANGED' | null, + readonly changeLogType: 'ADDED' | 'REMOVED' | 'CHANGED' | undefined, readonly legalBasisList: ILegalBasis[], readonly hintDictionary: boolean, ) { - this.changes = redactionLogEntry.changes; - this.manualChanges = redactionLogEntry.manualChanges; - this.color = redactionLogEntry.color; - this.comments = redactionLogEntry.comments; - this.dictionaryEntry = redactionLogEntry.dictionaryEntry; - this.dossierDictionaryEntry = redactionLogEntry.dossierDictionaryEntry; + this.changes = redactionLogEntry.changes ?? []; + this.manualChanges = redactionLogEntry.manualChanges ?? []; + this.color = redactionLogEntry.color ?? []; + this.comments = redactionLogEntry.comments ?? []; + this.dictionaryEntry = !!redactionLogEntry.dictionaryEntry; + this.dossierDictionaryEntry = !!redactionLogEntry.dossierDictionaryEntry; this.endOffset = redactionLogEntry.endOffset; - this.engines = redactionLogEntry.engines; - this.excluded = redactionLogEntry.excluded; - this.hint = redactionLogEntry.hint; - this.rectangle = redactionLogEntry.rectangle; + this.engines = redactionLogEntry.engines ?? []; + this.excluded = !!redactionLogEntry.excluded; + this.hint = !!redactionLogEntry.hint; + this.rectangle = !!redactionLogEntry.rectangle; this.id = redactionLogEntry.id; - this.image = redactionLogEntry.image; - this.imageHasTransparency = redactionLogEntry.imageHasTransparency; + this.image = !!redactionLogEntry.image; + this.imageHasTransparency = !!redactionLogEntry.imageHasTransparency; this.legalBasis = redactionLogEntry.legalBasis; this.matchedRule = redactionLogEntry.matchedRule; - this.positions = redactionLogEntry.positions; + this.positions = redactionLogEntry.positions ?? []; this.reason = redactionLogEntry.reason; - this.recommendation = redactionLogEntry.recommendation; - this.redacted = redactionLogEntry.redacted; - this.reference = redactionLogEntry.reference; + this.recommendation = !!redactionLogEntry.recommendation; + this.redacted = !!redactionLogEntry.redacted; + this.reference = redactionLogEntry.reference ?? []; this.section = redactionLogEntry.section; this.sectionNumber = redactionLogEntry.sectionNumber; this.startOffset = redactionLogEntry.startOffset; @@ -69,7 +69,7 @@ export class RedactionLogEntry implements IRedactionLogEntry { this.textBefore = redactionLogEntry.textBefore; this.type = redactionLogEntry.type; this.value = redactionLogEntry.value; - this.imported = redactionLogEntry.imported; + this.imported = !!redactionLogEntry.imported; this.sourceId = redactionLogEntry.sourceId; this.isChangeLogEntry = !!this.changeLogType; } diff --git a/apps/red-ui/src/app/modules/admin/screens/license/combo-chart/combo-series-vertical.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/combo-chart/combo-series-vertical.component.ts index b8d9fe052..ecc1f2f17 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/combo-chart/combo-series-vertical.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/combo-chart/combo-series-vertical.component.ts @@ -7,6 +7,7 @@ import { Bar, BarOrientation, formatLabel, PlacementTypes, StyleTypes } from '@s selector: 'g[ngx-combo-charts-series-vertical]', template: ` + 0; + const hasManualChanges = redactionLogEntry.manualChanges?.length > 0; if (file.numberOfAnalyses <= 1 && !file.hasUpdates && !hasManualChanges) { return { - changeLogType: null, + changeLogType: undefined, hidden: false, }; } - const viableChanges = redactionLogEntry.changes.filter(c => c.analysisNumber > 1); + const viableChanges = redactionLogEntry.changes?.filter(c => c.analysisNumber > 1); const lastChange = viableChanges.sort(chronologicallyBy(x => x.dateTime)).at(-1); const page = redactionLogEntry.positions?.[0].page; @@ -290,8 +290,8 @@ export class FileDataService extends EntitiesService