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; image?: boolean;
manual?: boolean; manual?: boolean;
pending = false; pending = false;
hintDictionary?: boolean; hintDictionary = false;
textAfter?: string; textAfter?: string;
textBefore?: string; textBefore?: string;
isChangeLogEntry?: boolean; isChangeLogEntry = false;
changeLogType?: 'ADDED' | 'REMOVED' | 'CHANGED'; changeLogType?: 'ADDED' | 'REMOVED' | 'CHANGED';
engines?: string[]; engines?: string[];
hasBeenResized: boolean; 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, c => c.manualRedactionType === ManualRedactionTypes.LEGAL_BASIS_CHANGE && c.annotationStatus === LogEntryStatuses.REQUESTED,
)?.propertyChanges.legalBasis; )?.propertyChanges.legalBasis;
this._createContent(annotationWrapper, redactionLogEntry); this.#createContent(annotationWrapper, redactionLogEntry);
this._setSuperType(annotationWrapper, redactionLogEntry); this.#setSuperType(annotationWrapper, redactionLogEntry);
this._handleRecommendations(annotationWrapper, redactionLogEntry); this.#handleRecommendations(annotationWrapper, redactionLogEntry);
annotationWrapper.typeLabel = this.#getTypeLabel(redactionLogEntry, annotationWrapper); annotationWrapper.typeLabel = this.#getTypeLabel(redactionLogEntry, annotationWrapper);
const entity = dictionaries.find(d => d.type === annotationWrapper.typeValue); 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 const colorKey = annotationWrapper.isSuperTypeBasedColor
? annotationDefaultColorConfig[annotationWrapper.superType] ? annotationDefaultColorConfig[annotationWrapper.superType]
@ -349,23 +349,23 @@ export class AnnotationWrapper implements IListable, Record<string, unknown> {
return annotationTypesTranslations[annotation.superType]; return annotationTypesTranslations[annotation.superType];
} }
private static _handleRecommendations(annotationWrapper: AnnotationWrapper, redactionLogEntry: RedactionLogEntry) { static #handleRecommendations(annotationWrapper: AnnotationWrapper, redactionLogEntry: RedactionLogEntry) {
if (annotationWrapper.superType === SuperTypes.Recommendation) { if (annotationWrapper.superType === SuperTypes.Recommendation) {
annotationWrapper.recommendationType = redactionLogEntry.type; annotationWrapper.recommendationType = redactionLogEntry.type;
} }
} }
private static _getLastRelevantManualChange(manualChanges: IManualChange[]) { static #getLastRelevantManualChange(manualChanges: IManualChange[]) {
return manualChanges[manualChanges.length - 1]; return manualChanges[manualChanges.length - 1];
} }
private static _setSuperType(annotationWrapper: AnnotationWrapper, redactionLogEntryWrapper: RedactionLogEntry) { static #setSuperType(annotationWrapper: AnnotationWrapper, redactionLogEntryWrapper: RedactionLogEntry) {
if (redactionLogEntryWrapper.manualChanges?.length) { 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 viableChanges = redactionLogEntryWrapper.changes.filter(c => c.analysisNumber > 1);
const lastChange = viableChanges.sort(chronologicallyBy(x => x.dateTime)).at(-1); const lastChange = viableChanges.sort(chronologicallyBy(x => x.dateTime)).at(-1);
const lastChangeOccurredAfterLastManualChange = const lastChangeOccurredAfterLastManualChange =
timestampOf(lastChange.dateTime) > timestampOf(lastRelevantManualChange.processedDate); lastChange && timestampOf(lastChange.dateTime) > timestampOf(lastRelevantManualChange.processedDate);
if (lastChangeOccurredAfterLastManualChange && lastChange.type === ChangeTypes.ADDED && redactionLogEntryWrapper.redacted) { if (lastChangeOccurredAfterLastManualChange && lastChange.type === ChangeTypes.ADDED && redactionLogEntryWrapper.redacted) {
annotationWrapper.superType = SuperTypes.Redaction; annotationWrapper.superType = SuperTypes.Redaction;
@ -374,7 +374,7 @@ export class AnnotationWrapper implements IListable, Record<string, unknown> {
annotationWrapper.pending = !lastRelevantManualChange.processed; annotationWrapper.pending = !lastRelevantManualChange.processed;
annotationWrapper.superType = AnnotationWrapper._selectSuperType( annotationWrapper.superType = AnnotationWrapper.#selectSuperType(
redactionLogEntryWrapper, redactionLogEntryWrapper,
lastRelevantManualChange, lastRelevantManualChange,
annotationWrapper.hintDictionary, 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 = ''; let content = '';
if (entry.matchedRule) { if (entry.matchedRule) {
content += `Rule ${entry.matchedRule} matched \n\n`; content += `Rule ${entry.matchedRule} matched \n\n`;
@ -425,13 +425,13 @@ export class AnnotationWrapper implements IListable, Record<string, unknown> {
content += `${prefix} "${entry.section}"`; content += `${prefix} "${entry.section}"`;
} }
annotationWrapper.shortContent = this._getShortContent(annotationWrapper, entry) || content; annotationWrapper.shortContent = this.#getShortContent(annotationWrapper, entry) || content;
annotationWrapper.content = content; annotationWrapper.content = content;
} }
private static _getShortContent(annotationWrapper: AnnotationWrapper, entry: RedactionLogEntry) { static #getShortContent(annotationWrapper: AnnotationWrapper, entry: RedactionLogEntry) {
if (annotationWrapper.legalBasis) { 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) { if (lb) {
return lb.name; return lb.name;
} }
@ -440,11 +440,7 @@ export class AnnotationWrapper implements IListable, Record<string, unknown> {
return annotationWrapper.legalBasis; return annotationWrapper.legalBasis;
} }
private static _selectSuperType( static #selectSuperType(redactionLogEntry: RedactionLogEntry, lastManualChange: IManualChange, isHintDictionary: boolean): SuperType {
redactionLogEntry: RedactionLogEntry,
lastManualChange: IManualChange,
isHintDictionary: boolean,
): SuperType {
switch (lastManualChange.manualRedactionType) { switch (lastManualChange.manualRedactionType) {
case ManualRedactionTypes.ADD_LOCALLY: case ManualRedactionTypes.ADD_LOCALLY:
switch (lastManualChange.annotationStatus) { 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 // TODO: this should be removed. Use only AnnotationWrapper class
export class RedactionLogEntry implements IRedactionLogEntry { export class RedactionLogEntry implements IRedactionLogEntry {
readonly changes?: IChange[]; readonly changes: IChange[];
readonly imported?: boolean; readonly imported: boolean;
readonly manualChanges?: IManualChange[]; readonly manualChanges: IManualChange[];
readonly color?: number[]; readonly color: number[];
readonly comments?: IComment[]; readonly comments: IComment[];
readonly dictionaryEntry?: boolean; readonly dictionaryEntry: boolean;
readonly dossierDictionaryEntry?: boolean; readonly dossierDictionaryEntry: boolean;
readonly endOffset?: number; readonly endOffset?: number;
readonly engines?: LogEntryEngine[]; readonly engines: LogEntryEngine[];
readonly excluded?: boolean; readonly excluded: boolean;
readonly hint?: boolean; readonly hint: boolean;
readonly rectangle?: boolean; readonly rectangle: boolean;
readonly id?: string; readonly id: string;
readonly image?: boolean; readonly image: boolean;
readonly imageHasTransparency?: boolean; readonly imageHasTransparency: boolean;
readonly legalBasis?: string; readonly legalBasis?: string;
readonly matchedRule?: number; readonly matchedRule?: number;
readonly positions?: IRectangle[]; readonly positions: IRectangle[];
readonly recommendation?: boolean; readonly recommendation: boolean;
readonly redacted?: boolean; readonly redacted: boolean;
readonly reference?: string[]; readonly reference: string[];
readonly section?: string; readonly section?: string;
readonly sectionNumber?: number; readonly sectionNumber?: number;
readonly startOffset?: number; readonly startOffset?: number;
@ -37,31 +37,31 @@ export class RedactionLogEntry implements IRedactionLogEntry {
constructor( constructor(
redactionLogEntry: IRedactionLogEntry, redactionLogEntry: IRedactionLogEntry,
readonly changeLogType: 'ADDED' | 'REMOVED' | 'CHANGED' | null, readonly changeLogType: 'ADDED' | 'REMOVED' | 'CHANGED' | undefined,
readonly legalBasisList: ILegalBasis[], readonly legalBasisList: ILegalBasis[],
readonly hintDictionary: boolean, readonly hintDictionary: boolean,
) { ) {
this.changes = redactionLogEntry.changes; this.changes = redactionLogEntry.changes ?? [];
this.manualChanges = redactionLogEntry.manualChanges; this.manualChanges = redactionLogEntry.manualChanges ?? [];
this.color = redactionLogEntry.color; this.color = redactionLogEntry.color ?? [];
this.comments = redactionLogEntry.comments; this.comments = redactionLogEntry.comments ?? [];
this.dictionaryEntry = redactionLogEntry.dictionaryEntry; this.dictionaryEntry = !!redactionLogEntry.dictionaryEntry;
this.dossierDictionaryEntry = redactionLogEntry.dossierDictionaryEntry; this.dossierDictionaryEntry = !!redactionLogEntry.dossierDictionaryEntry;
this.endOffset = redactionLogEntry.endOffset; this.endOffset = redactionLogEntry.endOffset;
this.engines = redactionLogEntry.engines; this.engines = redactionLogEntry.engines ?? [];
this.excluded = redactionLogEntry.excluded; this.excluded = !!redactionLogEntry.excluded;
this.hint = redactionLogEntry.hint; this.hint = !!redactionLogEntry.hint;
this.rectangle = redactionLogEntry.rectangle; this.rectangle = !!redactionLogEntry.rectangle;
this.id = redactionLogEntry.id; this.id = redactionLogEntry.id;
this.image = redactionLogEntry.image; this.image = !!redactionLogEntry.image;
this.imageHasTransparency = redactionLogEntry.imageHasTransparency; this.imageHasTransparency = !!redactionLogEntry.imageHasTransparency;
this.legalBasis = redactionLogEntry.legalBasis; this.legalBasis = redactionLogEntry.legalBasis;
this.matchedRule = redactionLogEntry.matchedRule; this.matchedRule = redactionLogEntry.matchedRule;
this.positions = redactionLogEntry.positions; this.positions = redactionLogEntry.positions ?? [];
this.reason = redactionLogEntry.reason; this.reason = redactionLogEntry.reason;
this.recommendation = redactionLogEntry.recommendation; this.recommendation = !!redactionLogEntry.recommendation;
this.redacted = redactionLogEntry.redacted; this.redacted = !!redactionLogEntry.redacted;
this.reference = redactionLogEntry.reference; this.reference = redactionLogEntry.reference ?? [];
this.section = redactionLogEntry.section; this.section = redactionLogEntry.section;
this.sectionNumber = redactionLogEntry.sectionNumber; this.sectionNumber = redactionLogEntry.sectionNumber;
this.startOffset = redactionLogEntry.startOffset; this.startOffset = redactionLogEntry.startOffset;
@ -69,7 +69,7 @@ export class RedactionLogEntry implements IRedactionLogEntry {
this.textBefore = redactionLogEntry.textBefore; this.textBefore = redactionLogEntry.textBefore;
this.type = redactionLogEntry.type; this.type = redactionLogEntry.type;
this.value = redactionLogEntry.value; this.value = redactionLogEntry.value;
this.imported = redactionLogEntry.imported; this.imported = !!redactionLogEntry.imported;
this.sourceId = redactionLogEntry.sourceId; this.sourceId = redactionLogEntry.sourceId;
this.isChangeLogEntry = !!this.changeLogType; 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]', selector: 'g[ngx-combo-charts-series-vertical]',
template: ` template: `
<svg:g <svg:g
xmlns:svg="http://www.w3.org/2000/svg"
ngx-charts-bar ngx-charts-bar
*ngFor="let bar of bars; trackBy: trackBy" *ngFor="let bar of bars; trackBy: trackBy"
[@animationState]="'active'" [@animationState]="'active'"
@ -64,7 +65,7 @@ export class ComboSeriesVerticalComponent implements OnChanges {
@Output() deactivate = new EventEmitter(); @Output() deactivate = new EventEmitter();
@Output() bandwidth = new EventEmitter(); @Output() bandwidth = new EventEmitter();
bars: any; bars: Bar[];
x: any; x: any;
y: any; y: any;
readonly tooltipTypes = StyleTypes; readonly tooltipTypes = StyleTypes;
@ -193,7 +194,7 @@ export class ComboSeriesVerticalComponent implements OnChanges {
return item !== undefined; return item !== undefined;
} }
trackBy(_index, bar): string { trackBy(_index: number, bar: Bar): string {
return bar.label; 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'; import { Orientation, ViewDimensions, YAxisTicksComponent } from '@swimlane/ngx-charts';
@Component({ @Component({
selector: 'g[red-ngx-charts-y-axis]', selector: 'g[red-ngx-charts-y-axis]',
template: ` 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 <svg:g
ngx-charts-y-axis-ticks ngx-charts-y-axis-ticks
*ngIf="yScale" *ngIf="yScale"

View File

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

View File

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

View File

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