Skip to content

Commit

Permalink
remove nodenorm call for NodeSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
Woozl committed Mar 19, 2024
1 parent 6ff5b56 commit 675c142
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
13 changes: 6 additions & 7 deletions src/pages/queryBuilder/textEditor/textEditorRow/NodeSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ export default function NodeSelector({
if (includeCuries) {
if (searchTerm.includes(':')) { // user is typing a specific curie
newOptions.push({ name: searchTerm, ids: [searchTerm] });
} else {
if (cancel) {
cancel.cancel();
}
cancel = CancelToken.source();
const curies = await fetchCuries(searchTerm, displayAlert, cancel.token);
newOptions.push(...curies);
}
if (cancel) {
cancel.cancel();
}
cancel = CancelToken.source();
const curies = await fetchCuries(searchTerm, displayAlert, cancel.token);
newOptions.push(...curies);
}
toggleLoading(false);
setOptions(newOptions);
Expand Down
26 changes: 4 additions & 22 deletions src/utils/fetchCuries.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,10 @@ export default async function fetchCuries(entity, displayAlert, cancel) {
if (!Array.isArray(response)) {
return [];
}
const curieResponse = response.map((node) => node.curie);
if (!curieResponse.length) {
return [];
}

// Pass curies to nodeNormalizer to get category information and
// a better curie identifier
const normalizationResponse = await API.nodeNormalization.getNormalizedNodes({ curies: curieResponse }, cancel);

if (normalizationResponse.status === 'error') {
displayAlert('error',
'Failed to contact node normalizer to search curies. Please try again later.');
return [];
}

// Sometimes the nodeNormalizer returns null responses
// so we use a filter to remove those
const newOptions = Object.values(normalizationResponse).filter((c) => c).map((c) => ({
name: c.id.label || c.id.identifier,
categories: c.type,
ids: [c.id.identifier],
return response.map(({ curie, label, types }) => ({
name: label,
categories: types,
ids: [curie],
}));

return newOptions;
}

0 comments on commit 675c142

Please sign in to comment.