Skip to content

Commit 945ead1

Browse files
authored
Merge pull request #788 from MetaCell/feature/fix-coords-range-update
Fixed state changes on type changes
2 parents 1119234 + 354b9ba commit 945ead1

1 file changed

Lines changed: 28 additions & 26 deletions

File tree

webapp/components/general/NetPyNECoordsRange.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,24 @@ export default class NetPyNECoordsRange extends Component {
101101

102102
const rangeType = event.target.value ;
103103

104-
const pythonMessageDelAll = `netpyne_geppetto.${model}['${name}']['${conds}'] = {}`;
105-
Utils.execPythonMessage(
106-
pythonMessageDelAll
107-
);
108-
109-
const rangeValue = this.state.rangeValue ;
110-
111-
if (!rangeValue.some(e => e === undefined))
104+
if (this.state.rangeType && this.state.rangeType.length > 0)
112105
{
113-
const pythonMessage = `netpyne_geppetto.${model}['${name}']['${conds}']['${rangeType}'] = [${rangeValue}]` ;
106+
const pyPath = `netpyne_geppetto.${model}['${name}']['${conds}']`;
107+
const startLetter = String(this.state.rangeType)[0];
108+
const pythonMessageDelOpposite = `${pyPath} = {k: v for k, v in ${pyPath}.items() if not k.startswith('${startLetter}')}`;
114109
Utils.execPythonMessage(
115-
pythonMessage
110+
pythonMessageDelOpposite
116111
);
112+
113+
const rangeValue = this.state.rangeValue ;
114+
115+
if (!rangeValue.some(e => e === undefined))
116+
{
117+
const pythonMessage = `netpyne_geppetto.${model}['${name}']['${conds}']['${rangeType}'] = [${rangeValue}]` ;
118+
Utils.execPythonMessage(
119+
pythonMessage
120+
);
121+
}
117122
}
118123

119124
this.setState({ rangeType})
@@ -127,32 +132,29 @@ export default class NetPyNECoordsRange extends Component {
127132
name,
128133
} = this.props;
129134

130-
function getOppositeObject(list, givenValue) {
131-
const index = list.findIndex(obj => obj.value === givenValue);
132-
133-
if (index === -1 || list.length !== 2) {
134-
return null;
135-
}
136-
return list[1 - index];
137-
}
138135

139136
if (newValue === '' || (/^\d+$/.test(newValue))) {
140-
const opossiteRangeType = getOppositeObject(this.props.items, this.state.rangeType) ;
141-
142-
if (opossiteRangeType)
137+
if (this.state.rangeType && this.state.rangeType.length > 0)
143138
{
144-
const pythonMessageDelOpposite = `netpyne_geppetto.${model}['${name}']['${conds}'].pop('${opossiteRangeType.value}', None)`;
139+
const pyPath = `netpyne_geppetto.${model}['${name}']['${conds}']`;
140+
const startLetter = String(this.state.rangeType)[0];
141+
const pythonMessageDelOpposite = `${pyPath} = {k: v for k, v in ${pyPath}.items() if not k.startswith('${startLetter}')}`;
145142
Utils.execPythonMessage(
146143
pythonMessageDelOpposite
147144
);
148145
}
149146

150147
const rangeValue = this.state.rangeValue ;
151148
rangeValue[index] = newValue ;
152-
const pythonMessage = `netpyne_geppetto.${model}['${name}']['${conds}']['${this.state.rangeType}'] = [${rangeValue}]` ;
153-
Utils.execPythonMessage(
154-
pythonMessage
155-
);
149+
150+
if (!rangeValue.some(e => e === undefined))
151+
{
152+
const pythonMessage = `netpyne_geppetto.${model}['${name}']['${conds}']['${this.state.rangeType}'] = [${rangeValue}]` ;
153+
Utils.execPythonMessage(
154+
pythonMessage
155+
);
156+
}
157+
156158
this.setState({ rangeValue })
157159
}
158160
}

0 commit comments

Comments
 (0)