Add dropdown for boolean inputs (#1845)

This commit is contained in:
HenryNguyen5 2018-05-24 19:22:33 -04:00 committed by Daniel Ternyak
parent 693e1972e5
commit 28da18e84a
No known key found for this signature in database
GPG Key ID: DF212D2DC5D0E245
1 changed files with 37 additions and 8 deletions

View File

@ -109,18 +109,36 @@ class InteractExplorerClass extends Component<Props, State> {
{/* TODO: Use reusable components with validation */}
{selectedFunction.contract.inputs.map(input => {
const { type, name } = input;
const inputState = this.state.inputs[name];
return (
<div key={name} className="input-group-wrapper InteractExplorer-func-in">
<label className="input-group">
<div className="input-group-header">{name + ' ' + type}</div>
<Input
className="InteractExplorer-func-in-input"
isValid={!!(inputs[name] && inputs[name].rawData)}
name={name}
value={(inputs[name] && inputs[name].rawData) || ''}
onChange={this.handleInputChange}
/>
{type === 'bool' ? (
<Dropdown
options={[{ value: false, label: 'false' }, { value: true, label: 'true' }]}
value={
inputState
? {
label: inputState.rawData,
value: inputState.parsedData as any
}
: undefined
}
clearable={false}
onChange={({ value }: { value: boolean }) => {
this.handleBooleanDropdownChange({ value, name });
}}
/>
) : (
<Input
className="InteractExplorer-func-in-input"
isValid={!!(inputs[name] && inputs[name].rawData)}
name={name}
value={(inputs[name] && inputs[name].rawData) || ''}
onChange={this.handleInputChange}
/>
)}
</label>
</div>
);
@ -244,6 +262,17 @@ class InteractExplorerClass extends Component<Props, State> {
}
}
private handleBooleanDropdownChange = ({ value, name }: { value: boolean; name: string }) => {
this.setState({
inputs: {
...this.state.inputs,
[name as any]: {
rawData: value.toString(),
parsedData: value
}
}
});
};
private handleInputChange = (ev: React.FormEvent<HTMLInputElement>) => {
const rawValue: string = ev.currentTarget.value;
const isArr = rawValue.startsWith('[') && rawValue.endsWith(']');