Skip to content

Commit

Permalink
ESCKAN-75 Filter list of nerves according to neurons.json provided by…
Browse files Browse the repository at this point in the history
… the client
  • Loading branch information
dvcorreia committed Nov 18, 2024
1 parent 8e398d1 commit e1969ed
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions src/context/DataContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { PropsWithChildren, useEffect, useMemo, useState } from 'react';
import {
PropsWithChildren,
useCallback,
useEffect,
useMemo,
useState,
} from 'react';
import { DataContext, Filters, ConnectionSummary } from './DataContext';
import {
HierarchicalNode,
Expand Down Expand Up @@ -68,27 +74,48 @@ export const DataContextProvider = ({
return colorMap;
}, [phenotypes]);

const updateSelectedConnectionSummary = (
summary:
| Omit<ConnectionSummary, 'filteredKnowledgeStatements'>
| ConnectionSummary
| null,
filters: Filters,
hierarchicalNodes: Record<string, HierarchicalNode>,
) => {
if (summary) {
const filteredKnowledgeStatements = filterKnowledgeStatements(
summary.connections,
hierarchicalNodes,
filters,
);
return {
...summary,
filteredKnowledgeStatements,
};
}
return null;
};
const updateSelectedConnectionSummary = useCallback(
(
summary:
| Omit<ConnectionSummary, 'filteredKnowledgeStatements'>
| ConnectionSummary
| null,
filters: Filters,
hierarchicalNodes: Record<string, HierarchicalNode>,
) => {
if (summary) {
let filteredKnowledgeStatements = filterKnowledgeStatements(
summary.connections,
hierarchicalNodes,
filters,
);

filteredKnowledgeStatements = Object.fromEntries(
Object.entries(filteredKnowledgeStatements).map(
([key, statement]) => [
key,
{
...statement,
vias: statement.vias.map((via) => ({
...via,
anatomical_entities: via.anatomical_entities.filter(
(entity) => majorNerves.has(entity.id),
),
})),
},
],
),
);

return {
...summary,
filteredKnowledgeStatements,
};
}
return null;
},
[majorNerves],
);

const handleSetSelectedConnectionSummary = (
summary: Omit<ConnectionSummary, 'filteredKnowledgeStatements'> | null,
Expand All @@ -105,7 +132,7 @@ export const DataContextProvider = ({
setSelectedConnectionSummary((prevSummary) =>
updateSelectedConnectionSummary(prevSummary, filters, hierarchicalNodes),
);
}, [filters, hierarchicalNodes]);
}, [filters, hierarchicalNodes, updateSelectedConnectionSummary]);

const dataContextValue = {
filters,
Expand Down

0 comments on commit e1969ed

Please sign in to comment.