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

Fixed state changes on type changes #788

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions webapp/components/general/NetPyNECoordsRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,24 @@ export default class NetPyNECoordsRange extends Component {

const rangeType = event.target.value ;

const pythonMessageDelAll = `netpyne_geppetto.${model}['${name}']['${conds}'] = {}`;
Utils.execPythonMessage(
pythonMessageDelAll
);

const rangeValue = this.state.rangeValue ;

if (!rangeValue.some(e => e === undefined))
if (this.state.rangeType && this.state.rangeType.length > 0)
{
const pythonMessage = `netpyne_geppetto.${model}['${name}']['${conds}']['${rangeType}'] = [${rangeValue}]` ;
const pyPath = `netpyne_geppetto.${model}['${name}']['${conds}']`;
const startLetter = String(this.state.rangeType)[0];
const pythonMessageDelOpposite = `${pyPath} = {k: v for k, v in ${pyPath}.items() if not k.startswith('${startLetter}')}`;
Utils.execPythonMessage(
pythonMessage
pythonMessageDelOpposite
);

const rangeValue = this.state.rangeValue ;

if (!rangeValue.some(e => e === undefined))
{
const pythonMessage = `netpyne_geppetto.${model}['${name}']['${conds}']['${rangeType}'] = [${rangeValue}]` ;
Utils.execPythonMessage(
pythonMessage
);
}
}

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

function getOppositeObject(list, givenValue) {
const index = list.findIndex(obj => obj.value === givenValue);

if (index === -1 || list.length !== 2) {
return null;
}
return list[1 - index];
}

if (newValue === '' || (/^\d+$/.test(newValue))) {
const opossiteRangeType = getOppositeObject(this.props.items, this.state.rangeType) ;

if (opossiteRangeType)
if (this.state.rangeType && this.state.rangeType.length > 0)
{
const pythonMessageDelOpposite = `netpyne_geppetto.${model}['${name}']['${conds}'].pop('${opossiteRangeType.value}', None)`;
const pyPath = `netpyne_geppetto.${model}['${name}']['${conds}']`;
const startLetter = String(this.state.rangeType)[0];
const pythonMessageDelOpposite = `${pyPath} = {k: v for k, v in ${pyPath}.items() if not k.startswith('${startLetter}')}`;
Utils.execPythonMessage(
pythonMessageDelOpposite
);
}

const rangeValue = this.state.rangeValue ;
rangeValue[index] = newValue ;
const pythonMessage = `netpyne_geppetto.${model}['${name}']['${conds}']['${this.state.rangeType}'] = [${rangeValue}]` ;
Utils.execPythonMessage(
pythonMessage
);

if (!rangeValue.some(e => e === undefined))
{
const pythonMessage = `netpyne_geppetto.${model}['${name}']['${conds}']['${this.state.rangeType}'] = [${rangeValue}]` ;
Utils.execPythonMessage(
pythonMessage
);
}

this.setState({ rangeValue })
}
}
Expand Down
Loading