RED-6813: check for undefined

This commit is contained in:
Dan Percic 2023-05-24 01:34:59 +03:00
parent f7f8ef5752
commit bf41ec9bf9
7 changed files with 72 additions and 75 deletions

View File

@ -57,10 +57,10 @@ export class AnnotationWrapper implements IListable, Record<string, unknown> {
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<string, unknown> {
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<string, unknown> {
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<string, unknown> {
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<string, unknown> {
}
}
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<string, unknown> {
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<string, unknown> {
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) {

View File

@ -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;
}

View File

@ -7,6 +7,7 @@ import { Bar, BarOrientation, formatLabel, PlacementTypes, StyleTypes } from '@s
selector: 'g[ngx-combo-charts-series-vertical]',
template: `
<svg:g
xmlns:svg="http://www.w3.org/2000/svg"
ngx-charts-bar
*ngFor="let bar of bars; trackBy: trackBy"
[@animationState]="'active'"
@ -64,7 +65,7 @@ export class ComboSeriesVerticalComponent implements OnChanges {
@Output() deactivate = new EventEmitter();
@Output() bandwidth = new EventEmitter();
bars: any;
bars: Bar[];
x: any;
y: any;
readonly tooltipTypes = StyleTypes;
@ -193,7 +194,7 @@ export class ComboSeriesVerticalComponent implements OnChanges {
return item !== undefined;
}
trackBy(_index, bar): string {
trackBy(_index: number, bar: Bar): string {
return bar.label;
}
}

View File

@ -1,10 +1,10 @@
import { Component, Input, Output, EventEmitter, OnChanges, ViewChild, SimpleChanges, ChangeDetectionStrategy } from '@angular/core';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewChild } from '@angular/core';
import { Orientation, ViewDimensions, YAxisTicksComponent } from '@swimlane/ngx-charts';
@Component({
selector: 'g[red-ngx-charts-y-axis]',
template: `
<svg:g [attr.class]="yAxisClassName" [attr.transform]="transform">
<svg:g xmlns:svg="http://www.w3.org/2000/svg" [attr.class]="yAxisClassName" [attr.transform]="transform">
<svg:g
ngx-charts-y-axis-ticks
*ngIf="yScale"

View File

@ -248,7 +248,7 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
const redactionLogEntryWrapper: RedactionLogEntry = new RedactionLogEntry(
redactionLogEntry,
changeLogValues.changeLogType,
redactionLog.legalBasis,
redactionLog.legalBasis ?? [],
!!dictionary?.hint,
);
@ -272,17 +272,17 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
file: File,
): {
hidden: boolean;
changeLogType: ChangeType;
changeLogType?: ChangeType;
} {
const hasManualChanges = redactionLogEntry.manualChanges.length > 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<AnnotationWrapper, Annotati
if (!viewedPage) {
return {
changeLogType: null,
hidden: lastChange && lastChange.type === ChangeTypes.REMOVED,
changeLogType: undefined,
hidden: lastChange ? lastChange.type === ChangeTypes.REMOVED : false,
};
}
@ -302,7 +302,7 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
if (changeOccurredAfterPageIsViewed) {
this.#markPageAsUnseenIfNeeded(viewedPage, lastChange.dateTime);
return {
changeLogType: lastChange.type,
changeLogType: lastChange?.type,
hidden: false,
};
}
@ -325,8 +325,8 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
// Page doesn't have a view-time or no relevant changes - hide removed anyway
return {
changeLogType: null,
hidden: lastChange && lastChange.type === ChangeTypes.REMOVED,
changeLogType: undefined,
hidden: lastChange ? lastChange.type === ChangeTypes.REMOVED : false,
};
}

View File

@ -1,9 +1,9 @@
import { ValuesOf } from '@iqser/common-ui';
export interface IChange {
dateTime?: string;
analysisNumber?: number;
type?: ChangeType;
dateTime: string;
analysisNumber: number;
type: ChangeType;
}
export const ChangeTypes = {

View File

@ -17,7 +17,7 @@ export interface IRedactionLogEntry {
excluded?: boolean;
hint?: boolean;
rectangle?: boolean;
id?: string;
id: string;
image?: boolean;
imageHasTransparency?: boolean;
legalBasis?: string;