fix(select-objects): display missing objects (#2059)

Fixes #2052
This commit is contained in:
badrAZ
2017-04-05 14:52:21 +02:00
committed by Julien Fontanet
parent bfe4c45fcf
commit e6f140f575
3 changed files with 32 additions and 34 deletions

View File

@@ -182,6 +182,10 @@ const renderXoItem = (item, {
} = {}) => {
const { id, type, label } = item
if (item.removed) {
return <span key={id} className='text-danger'> <Icon icon='alarm' /> {id}</span>
}
if (!type) {
if (process.env.NODE_ENV !== 'production' && !label) {
throw new Error(`an item must have at least either a type or a label`)

View File

@@ -42,7 +42,6 @@ import {
import {
addSubscriptions,
connectStore,
mapPlus,
resolveResourceSets
} from './utils'
import {
@@ -135,37 +134,6 @@ const options = props => ({
]).isRequired
})
export class GenericSelect extends Component {
componentDidUpdate (prevProps) {
const { onChange, xoObjects } = this.props
if (!onChange || prevProps.xoObjects === xoObjects) {
return
}
const ids = this._getSelectValue()
const objectsById = this._getObjectsById()
if (!isArray(ids)) {
ids && !objectsById[ids] && onChange(undefined)
} else {
let shouldTriggerOnChange
const newValue = isArray(ids) && mapPlus(ids, (id, push) => {
const object = objectsById[id]
if (object) {
push(object)
} else {
shouldTriggerOnChange = true
}
})
if (shouldTriggerOnChange) {
this.props.onChange(newValue)
}
}
}
_getObjectsById = createSelector(
() => this.props.xoObjects,
objects => keyBy(
@@ -205,6 +173,21 @@ export class GenericSelect extends Component {
options.push(getOption(object, container))
})
})
const values = this._getSelectValue()
const objectsById = this._getObjectsById()
forEach(values, val => {
if (!objectsById[val]) {
options.push({
id: val,
label: val,
value: val,
xoItem: {
id: val,
removed: true
}
})
}
})
return options
}
)

View File

@@ -361,7 +361,18 @@ export default class New extends Component {
} else {
// Normal backup.
backupInput.value = values[1].values[0]
vmsInput.value = { vms: values[0].values }
// xo-web v5.7.1 introduced a bug where an extra level ({ id: { id: <id> } }) was introduced for the VM param.
//
// This code automatically unbox the ids.
const vms = map(values[0].values, id => {
while (typeof id === 'object') {
id = id.id
}
return id
})
vmsInput.value = { vms }
}
}
}
@@ -390,7 +401,7 @@ export default class New extends Component {
type: 'crossProduct',
items: [{
type: 'set',
values: map(vmsInputValue.vms, vm => ({ id: vm }))
values: map(vmsInputValue.vms, vm => ({ id: vm.id || vm }))
}, {
type: 'set',
values: [ callArgs ]