feat(xo-web/new-vm): hide IP field if IP pools are not configured (#2811)

Fixes #2739
This commit is contained in:
Pierre Donias 2018-03-29 17:19:38 +02:00 committed by Julien Fontanet
parent b47789bf82
commit b3d8ce2041

View File

@ -41,6 +41,7 @@ import {
createVms,
getCloudInitConfig,
subscribeCurrentUser,
subscribeIpPools,
subscribePermissions,
subscribeResourceSets,
XEN_DEFAULT_CPU_CAP,
@ -115,12 +116,21 @@ const Item = ({ label, children, className }) => (
</span>
)
@addSubscriptions({
// eslint-disable-next-line standard/no-callback-literal
ipPoolsConfigured: cb => subscribeIpPools(ipPools => cb(ipPools.length > 0)),
})
@injectIntl
class Vif extends BaseComponent {
_getIpPoolPredicate = createSelector(
() => this.props.vif,
vif => ipPool => includes(ipPool.networks, vif.network)
)
render () {
const {
intl: { formatMessage },
ipPoolPredicate,
ipPoolsConfigured,
networkPredicate,
onChangeAddresses,
onChangeMac,
@ -159,18 +169,19 @@ class Vif extends BaseComponent {
)}
</span>
</Item>
{ipPoolsConfigured && (
<LineItem>
<span className={styles.inlineSelect}>
{pool ? (
<SelectIp
containerPredicate={ipPoolPredicate}
containerPredicate={this._getIpPoolPredicate()}
multi
onChange={onChangeAddresses}
value={vif.addresses}
/>
) : (
<SelectResourceSetIp
containerPredicate={ipPoolPredicate}
containerPredicate={this._getIpPoolPredicate()}
multi
onChange={onChangeAddresses}
resourceSetId={resourceSet.id}
@ -179,6 +190,7 @@ class Vif extends BaseComponent {
)}
</span>
</LineItem>
)}
<Item>
<Button onClick={onDelete}>
<Icon icon='new-vm-remove' />
@ -531,25 +543,6 @@ export default class NewVm extends BaseComponent {
poolId => sr =>
(poolId == null || poolId === sr.$pool) && sr.SR_type === 'iso'
)
_getIpPoolPredicate = createSelector(
() => !!this.props.pool,
() => {
const { resourceSet } = this.props
return resourceSet && resourceSet.ipPools
},
() => this.props.vif,
(pool, ipPools, vif) => ipPool => {
if (!ipPool) {
return false
}
return (
pool ||
(ipPools &&
includes(ipPools, ipPool.id) &&
find(ipPool.networks, ipPoolNetwork => ipPoolNetwork === vif.network))
)
}
)
_getNetworkPredicate = createSelector(
this._getIsInPool,
this._getIsInResourceSet,