Skip to content

Commit 070baef

Browse files
committed
#417 plugging filter
1 parent ad258bb commit 070baef

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

webapp/components/general/ExperimentControlPanel.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,48 @@ const ExperimentControlPanel = (props) => {
2828
const onNodeSelect = (nodeId) => {
2929
console.log(`Node with id ${nodeId} clicked`);
3030
};
31+
const instancesMap = new Map();
3132

3233
const onVisibilityClick = (event, nodeId) => {
3334
console.log(`Visibility of node with id of ${nodeId} clicked.`);
3435
};
3536

37+
const traverseInstances = (instance) => {
38+
if (instance.getPath().includes(filter)) {
39+
instancesMap.set(
40+
instance.getPath(),
41+
(
42+
<ControlPanelTreeItem
43+
key={instance.id}
44+
nodeId={instance.getPath()}
45+
label={instance.id}
46+
type={instance.getType().getId()}
47+
onNodeSelect={onNodeSelect}
48+
onVisibilityClick={onVisibilityClick}
49+
/>
50+
),
51+
);
52+
}
53+
54+
if (instance.getChildren() && instance.getChildren().length > 0) {
55+
const children = instance.getChildren();
56+
for (let i = 0; i < children.length; i += 1) {
57+
traverseInstances(children[i]);
58+
}
59+
}
60+
};
61+
62+
const getFlatFilteredList = (instances) => {
63+
instancesMap.clear();
64+
instances.forEach((instance) => traverseInstances(instance));
65+
66+
const flatList = [];
67+
instancesMap.forEach((value, key) => {
68+
flatList.push(value);
69+
});
70+
return flatList;
71+
};
72+
3673
const getTreeItemsFromData = (treeItems) => treeItems.map((treeItemData) => {
3774
let children;
3875
if (treeItemData.getChildren() && treeItemData.getChildren().length > 0) {
@@ -74,7 +111,10 @@ const ExperimentControlPanel = (props) => {
74111
defaultExpandIcon={<ChevronRightIcon />}
75112
>
76113
<TreeItem nodeId="network" label="network_netpyne">
77-
{getTreeItemsFromData(window.Instances.network.getChildren())}
114+
{filter === ''
115+
? getTreeItemsFromData(window.Instances.network.getChildren())
116+
: getFlatFilteredList(window.Instances.network.getChildren())
117+
}
78118
</TreeItem>
79119
</TreeView>
80120
</Box>

webapp/components/instantiation/NetPyNEInstantiated.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class NetPyNEInstantiated extends React.Component {
8181
}
8282

8383
applySelection (data, selectedInstances) {
84-
const smap = new Map(selectedInstances.map((i) => [i, true]))
84+
const smap = new Map(selectedInstances.map((i) => [i, true]));
8585
const newData = data.map((item) => {
8686
if (smap.get(item.instancePath)) {
8787
return {
@@ -94,7 +94,8 @@ class NetPyNEInstantiated extends React.Component {
9494
const dmap = new Map(newData.map((i) => [i.instancePath, true]));
9595

9696
smap.forEach((value, key) => {
97-
if (!dmap.get(key)) {
97+
const item = dmap.get(key);
98+
if (!item) {
9899
newData.push({
99100
instancePath: key,
100101
color: undefined,

0 commit comments

Comments
 (0)