Skip to content

Commit

Permalink
Merge pull request #116 from fogbow/attach-multiple-networks-feature
Browse files Browse the repository at this point in the history
Add feature to attach a vm to multiple networks
  • Loading branch information
fubica authored Jul 18, 2020
2 parents 29c9417 + f7884cf commit 8b4839d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/components/ComputeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const initialState = {
vCPU: 1,
disk: 20,
memory: 1024,
networkIds: '',
networkIds: [],
federatedNetworkId: '',
scriptType: '',
publicKey: '',
Expand Down Expand Up @@ -70,9 +70,16 @@ class ComputeForm extends Component {
let { name, value } = event.target;

if (name === 'networkIds') {
// NOTE(pauloewerton): this will work only with a single network id
let networkIds = this.state.networkIds || [];

if (networkIds.includes(value)) {
networkIds.pop(value);
} else {
networkIds.push(value);
}

this.setState({
[name]: [value]
'networkIds': networkIds
});
} else {
this.setState({
Expand Down Expand Up @@ -286,22 +293,22 @@ class ComputeForm extends Component {
onAddRequirement={this.addRequirement}
onResetRequirements={this.resetRequirements}/>

<label>Network ID</label>
<select value={this.state.networkIds} onChange={this.handleChange}
name='networkIds' className="form-control">
<option value=''>Choose a network</option>
{
this.props.networks.loading ?
<label>Networks</label>
<fieldset className="checkbox-list">
{ !this.state.provider || !this.state.cloudName ? <label>No cloud or provider selected</label> : undefined }
{ this.props.networks.loading ?
this.props.networks.data.map((network, idx) => {
return network.provider === this.state.provider &&
network.cloudName === this.state.cloudName ?
<option key={idx} value={network.instanceId}>
{network.instanceId}
</option> :
undefined; }) :
<div className="checkbox-field">
{ console.log(network) }
<input onChange={this.handleChange} type="checkbox" id={idx} value={network.instanceId} name="networkIds"></input>
<label htmlFor={idx}>{network.instanceName}</label>
</div> : undefined
; }) :
undefined
}
</select>
</fieldset>

<label>Federated Network ID</label>
<select value={this.state.federatedNetworkId} onChange={this.handleChange}
Expand Down
7 changes: 7 additions & 0 deletions src/styles/order-form.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@
max-width: 20rem;
text-overflow: ellipsis;
}

.checkbox-list { margin-bottom: 15px; }
.checkbox-field { display: flex; }
.checkbox-field label {
margin-left: 10px;
display: inline;
}

0 comments on commit 8b4839d

Please sign in to comment.