Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ontologies displayed twice (DEV-1325) #832

Merged
merged 2 commits into from Sep 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/app/project/ontology/ontology.component.ts
@@ -1,3 +1,4 @@
import { O } from '@angular/cdk/keycodes';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-import FTW?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got to love it

import { Component, HostListener, Inject, OnInit, ViewChild, ViewContainerRef } from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
Expand Down Expand Up @@ -382,7 +383,26 @@ export class OntologyComponent implements OnInit {
(ontologies: ReadOntology[]) => {
// update current list of project ontologies
ontologies[ontologies.findIndex(onto => onto.id === ontology.id)] = ontology;
this._cache.set('currentProjectOntologies', ontologies);
// avoid duplicates
const temp: ReadOntology[] = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename these temp variables to something a bit more meaningful

const tempIds: String[] = [];
for (const onto of ontologies){
if (tempIds.indexOf(onto.id) !== -1){
let oldOntoIndex: number;
temp.forEach((o, index) => {
if (o.id === onto.id) {
oldOntoIndex = index;
}
});
if (Object.keys(onto.properties).length > Object.keys(temp[oldOntoIndex].properties).length){ // new onto has more props -> replace
temp[oldOntoIndex] = onto;
}
} else {
tempIds.push(onto.id);
temp.push(onto);
}
}
this._cache.set('currentProjectOntologies', temp);
},
() => {} // don't log error to rollbar if 'currentProjectOntologies' does not exist in the cache
);
Expand Down