From 5cb6dc6d92968aa2ad5389d9cf09e31dbb6c7d15 Mon Sep 17 00:00:00 2001 From: "Rajaa.BARHTAOUI" Date: Fri, 6 Apr 2018 13:54:32 +0200 Subject: [PATCH] feat(xo-web): create new disk from SR view (#2726) Fixes #2229 --- packages/xo-web/src/xo-app/sr/tab-disks.js | 111 ++++++++++++++++++++- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/packages/xo-web/src/xo-app/sr/tab-disks.js b/packages/xo-web/src/xo-app/sr/tab-disks.js index a22eecebb..42f4e93da 100644 --- a/packages/xo-web/src/xo-app/sr/tab-disks.js +++ b/packages/xo-web/src/xo-app/sr/tab-disks.js @@ -1,19 +1,29 @@ -import _ from 'intl' +import _, { messages } from 'intl' +import ActionButton from 'action-button' import ActionRowButton from 'action-row-button' import ButtonGroup from 'button-group' import Component from 'base-component' import Icon from 'icon' import Link from 'link' +import propTypes from 'prop-types-decorator' import React from 'react' import renderXoItem from 'render-xo-item' import SortedTable from 'sorted-table' +import TabButton from 'tab-button' +import { injectIntl } from 'react-intl' import { Text } from 'editable' -import { concat, isEmpty, map, some } from 'lodash' -import { connectStore, formatSize } from 'utils' +import { SizeInput, Toggle } from 'form' import { Container, Row, Col } from 'grid' -import { createGetObjectsOfType, createSelector } from 'selectors' +import { connectStore, formatSize, noop } from 'utils' +import { concat, isEmpty, map, some } from 'lodash' +import { + createGetObjectsOfType, + createSelector, + getCheckPermissions, +} from 'selectors' import { connectVbd, + createDisk, deleteVbd, deleteVdi, deleteVdis, @@ -173,7 +183,72 @@ const FILTERS = { // =================================================================== +@injectIntl +@propTypes({ + onClose: propTypes.func, + sr: propTypes.object.isRequired, +}) +class NewDisk extends Component { + _createDisk = () => { + const { sr, onClose = noop } = this.props + const { name, readOnly, size } = this.state + + return createDisk(name, size, sr, { + mode: readOnly ? 'RO' : 'RW', + }).then(onClose) + } + + render () { + const { formatMessage } = this.props.intl + const { name, readOnly, size } = this.state + + return ( +
+
+ +
+
+ +
+
+ + {_('vbdReadonly')}{' '} + + +
+ + {_('vbdCreate')} + +
+ ) + } +} + +@connectStore(() => ({ + checkPermissions: getCheckPermissions, +})) export default class SrDisks extends Component { + _closeNewDiskForm = () => this.setState({ newDisk: false }) + _getAllVdis = createSelector( () => this.props.vdis, () => this.props.vdiSnapshots, @@ -181,10 +256,38 @@ export default class SrDisks extends Component { concat ) + _getIsSrAdmin = createSelector( + () => this.props.checkPermissions, + () => this.props.sr.id, + (check, id) => check(id, 'administrate') + ) + render () { const vdis = this._getAllVdis() + const { newDisk } = this.state + return ( + {this._getIsSrAdmin() && [ + + + + + , + newDisk && ( + + + +
+ +
+ ), + ]} {!isEmpty(vdis) ? (