fix(xo-web/vm/disks): don't pass null to Size component (#4811)

Fixes support#2181

- `vdi.size` should always be defined
- `null` was passed when `vdi.size` was `0`
This commit is contained in:
Pierre Donias 2020-02-20 15:51:32 +01:00 committed by GitHub
parent 44956dff85
commit 814e08edd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -490,7 +490,8 @@ export class XoSelect extends Editable {
export class Size extends Editable { export class Size extends Editable {
static propTypes = { static propTypes = {
value: PropTypes.number.isRequired, value: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf([null])])
.isRequired,
} }
get value() { get value() {
@ -498,7 +499,15 @@ export class Size extends Editable {
} }
_renderDisplay() { _renderDisplay() {
return this.props.children || formatSize(this.props.value) if (this.props.children !== undefined) {
return this.props.children
}
if (this.props.value != null) {
return formatSize(this.props.value)
}
return null
} }
_saveIfUnfocused = () => { _saveIfUnfocused = () => {

View File

@ -2,6 +2,7 @@ import _, { messages } from 'intl'
import ActionButton from 'action-button' import ActionButton from 'action-button'
import Component from 'base-component' import Component from 'base-component'
import copy from 'copy-to-clipboard' import copy from 'copy-to-clipboard'
import defined from '@xen-orchestra/defined'
import HTML5Backend from 'react-dnd-html5-backend' import HTML5Backend from 'react-dnd-html5-backend'
import Icon from 'icon' import Icon from 'icon'
import IsoDevice from 'iso-device' import IsoDevice from 'iso-device'
@ -131,7 +132,7 @@ const COLUMNS_VM_PV = [
{ {
itemRenderer: ({ vdi }) => ( itemRenderer: ({ vdi }) => (
<Size <Size
value={vdi.size || null} value={defined(vdi.size, null)}
onChange={size => editVdi(vdi, { size })} onChange={size => editVdi(vdi, { size })}
/> />
), ),