Merge branch 'VM/RED-10332' into 'master'

RED-10332 - fixed dictionary dropdown that did not update when another dossier...

Closes RED-10332

See merge request redactmanager/red-ui!694
This commit is contained in:
Dan Percic 2024-11-13 08:29:21 +01:00
commit 42d4829f2e

View File

@ -3,16 +3,12 @@ import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
effect, effect,
EventEmitter,
input, input,
Input,
model, model,
OnChanges,
OnInit, OnInit,
output, output,
Output,
signal, signal,
SimpleChanges, untracked,
ViewChild, ViewChild,
} from '@angular/core'; } from '@angular/core';
import { CircleButtonComponent, IconButtonComponent, IconButtonTypes, LoadingService } from '@iqser/common-ui'; import { CircleButtonComponent, IconButtonComponent, IconButtonTypes, LoadingService } from '@iqser/common-ui';
@ -203,7 +199,7 @@ export class DictionaryManagerComponent implements OnInit {
get #templatesWithCurrentEntityType() { get #templatesWithCurrentEntityType() {
return this._dossierTemplatesService.all.filter(t => return this._dossierTemplatesService.all.filter(t =>
this._dictionaryService.hasType(t.dossierTemplateId, this.selectedDictionaryType()), this._dictionaryService.hasType(t.dossierTemplateId, untracked(this.selectedDictionaryType)),
); );
} }
@ -236,53 +232,57 @@ export class DictionaryManagerComponent implements OnInit {
} }
async #onDossierChanged(dossierTemplateId: string, dossierId?: string) { async #onDossierChanged(dossierTemplateId: string, dossierId?: string) {
const selectedDictionaryByType = untracked(this.selectedDictionaryType);
const activeEntryType = untracked(this.activeEntryType);
let dictionary: IDictionary; let dictionary: IDictionary;
if (dossierId === 'template') { if (dossierId === 'template') {
dictionary = await this._dictionaryService.getForType(dossierTemplateId, this.selectedDictionaryType()); dictionary = await this._dictionaryService.getForType(dossierTemplateId, selectedDictionaryByType);
} else { } else {
if (dossierId) { if (dossierId) {
dictionary = ( dictionary = (
await firstValueFrom( await firstValueFrom(
this._dictionaryService.loadDictionaryEntriesByType([this.selectedDictionaryType()], dossierTemplateId, dossierId), this._dictionaryService.loadDictionaryEntriesByType([selectedDictionaryByType], dossierTemplateId, dossierId),
).catch(() => { ).catch(() => {
return [{ entries: [COMPARE_ENTRIES_ERROR], type: '' }]; return [{ entries: [COMPARE_ENTRIES_ERROR], type: '' }];
}) })
)[0]; )[0];
} else { } else {
dictionary = this.selectedDictionaryType() dictionary = selectedDictionaryByType
? await this._dictionaryService.getForType(this.currentDossierTemplateId(), this.selectedDictionaryType()) ? await this._dictionaryService.getForType(this.currentDossierTemplateId(), selectedDictionaryByType)
: { entries: [COMPARE_ENTRIES_ERROR], type: '' }; : { entries: [COMPARE_ENTRIES_ERROR], type: '' };
} }
} }
const activeEntries = const activeEntries =
this.activeEntryType() === DictionaryEntryTypes.ENTRY || this.hint() activeEntryType === DictionaryEntryTypes.ENTRY || this.hint()
? [...dictionary.entries] ? [...dictionary.entries]
: this.activeEntryType() === DictionaryEntryTypes.FALSE_POSITIVE : activeEntryType === DictionaryEntryTypes.FALSE_POSITIVE
? [...dictionary.falsePositiveEntries] ? [...dictionary.falsePositiveEntries]
: [...dictionary.falseRecommendationEntries]; : [...dictionary.falseRecommendationEntries];
return activeEntries.join('\n'); return activeEntries.join('\n');
} }
#updateDropdownsOptions(updateSelectedDossierTemplate = true) { #updateDropdownsOptions(updateSelectedDossierTemplate = true) {
const currentDossierTemplateId = untracked(this.currentDossierTemplateId);
const currentDossierId = untracked(this.currentDossierId);
if (updateSelectedDossierTemplate) { if (updateSelectedDossierTemplate) {
this.currentDossierTemplateId.set(this.initialDossierTemplateId ?? this.currentDossierTemplateId()); this.currentDossierTemplateId.set(this.initialDossierTemplateId ?? currentDossierTemplateId);
this.dossierTemplates = this.currentDossierTemplateId this.dossierTemplates = this.currentDossierTemplateId
? this.#templatesWithCurrentEntityType ? this.#templatesWithCurrentEntityType
: this._dossierTemplatesService.all; : this._dossierTemplatesService.all;
if (!this.currentDossierTemplateId) { if (!this.currentDossierTemplateId) {
this.dossierTemplates = [this.selectDossierTemplate, ...this.dossierTemplates]; this.dossierTemplates = [this.selectDossierTemplate, ...this.dossierTemplates];
} }
this.selectedDossierTemplate = this.dossierTemplates.find(t => t.id === this.currentDossierTemplateId()); this.selectedDossierTemplate = this.dossierTemplates.find(t => t.id === currentDossierTemplateId);
} }
this.dossiers = this._activeDossiersService.all.filter( this.dossiers = this._activeDossiersService.all.filter(
d => d.dossierTemplateId === this.currentDossierTemplateId() && d.id !== this.currentDossierId(), d => d.dossierTemplateId === currentDossierTemplateId && d.id !== currentDossierId,
); );
const templateDictionary = { const templateDictionary = {
id: 'template', id: 'template',
dossierId: 'template', dossierId: 'template',
dossierName: 'Template Dictionary', dossierName: 'Template Dictionary',
dossierTemplateId: this.currentDossierTemplateId(), dossierTemplateId: currentDossierTemplateId,
} as Dossier; } as Dossier;
this.dossiers.push(templateDictionary); this.dossiers.push(templateDictionary);
} }