Prevent the selection of an already selected dataset Templates

This commit is contained in:
George Kalampokis 2021-10-13 16:10:56 +03:00
parent 32e299fc45
commit 045dd51014
1 changed files with 10 additions and 0 deletions

View File

@ -248,6 +248,16 @@ export class DatasetInfoComponent extends BaseComponent implements OnInit {
onOptionSelected(){
try{
const profiles = this.formGroup.get('profiles').value as {id:string, label:string}[];
const profileCounts: Map<String, number> = new Map<String, number>();
profiles.forEach((value) => profileCounts.set(value.id, (profileCounts.get(value.id) !== undefined ? profileCounts.get(value.id): 0 ) + 1));
const duplicateProfiles = profiles.filter((value) => {
let isOk = profileCounts.get(value.id) > 1;
if (isOk) {
profileCounts.set(value.id, 0);
}
return isOk;
});
duplicateProfiles.forEach((value) => profiles.splice(profiles.lastIndexOf(value), 1));
profiles.sort((a,b)=> a.label.localeCompare(b.label));
}catch{
console.info('Could not sort Dataset Templates')