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 */} {/* TODO: Use reusable components with validation */}
{selectedFunction.contract.inputs.map(input => { {selectedFunction.contract.inputs.map(input => {
const { type, name } = input; const { type, name } = input;
const inputState = this.state.inputs[name];
return ( return (
<div key={name} className="input-group-wrapper InteractExplorer-func-in"> <div key={name} className="input-group-wrapper InteractExplorer-func-in">
<label className="input-group"> <label className="input-group">
<div className="input-group-header">{name + ' ' + type}</div> <div className="input-group-header">{name + ' ' + type}</div>
<Input {type === 'bool' ? (
className="InteractExplorer-func-in-input" <Dropdown
isValid={!!(inputs[name] && inputs[name].rawData)} options={[{ value: false, label: 'false' }, { value: true, label: 'true' }]}
name={name} value={
value={(inputs[name] && inputs[name].rawData) || ''} inputState
onChange={this.handleInputChange} ? {
/> 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> </label>
</div> </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>) => { private handleInputChange = (ev: React.FormEvent<HTMLInputElement>) => {
const rawValue: string = ev.currentTarget.value; const rawValue: string = ev.currentTarget.value;
const isArr = rawValue.startsWith('[') && rawValue.endsWith(']'); const isArr = rawValue.startsWith('[') && rawValue.endsWith(']');