Skip to content
Snippets Groups Projects
Commit 3ca1ac9a authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

SSDM-7569 NEW openBIS UI - General Template/Infrastructure for Forms -...

SSDM-7569 NEW openBIS UI - General Template/Infrastructure for Forms - Visualisation/Creation/Edit - improve form layout
parent c583b204
No related branches found
No related tags found
No related merge requests found
import _ from 'lodash' import _ from 'lodash'
import React from 'react' import React from 'react'
import FormControl from '@material-ui/core/FormControl'
import FormControlLabel from '@material-ui/core/FormControlLabel' import FormControlLabel from '@material-ui/core/FormControlLabel'
import FormHelperText from '@material-ui/core/FormHelperText'
import TextField from '@material-ui/core/TextField' import TextField from '@material-ui/core/TextField'
import Select from '@material-ui/core/Select'
import MenuItem from '@material-ui/core/MenuItem' import MenuItem from '@material-ui/core/MenuItem'
import Checkbox from '@material-ui/core/Checkbox' import Checkbox from '@material-ui/core/Checkbox'
import InfoIcon from '@material-ui/icons/InfoOutlined'
import Tooltip from '@material-ui/core/Tooltip'
import {withStyles} from '@material-ui/core/styles' import {withStyles} from '@material-ui/core/styles'
import logger from '../../../common/logger.js' import logger from '../../../common/logger.js'
const styles = () => ({ const styles = () => ({
container: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center'
},
boolean: {
width: '100%'
}
}) })
class ObjectTypePropertyPreview extends React.Component { class ObjectTypePropertyPreview extends React.Component {
...@@ -39,6 +46,19 @@ class ObjectTypePropertyPreview extends React.Component { ...@@ -39,6 +46,19 @@ class ObjectTypePropertyPreview extends React.Component {
render(){ render(){
logger.log(logger.DEBUG, 'ObjectTypePropertyPreview.render') logger.log(logger.DEBUG, 'ObjectTypePropertyPreview.render')
const {classes} = this.props
return (
<div className={classes.container}>
{this.renderField()}
<Tooltip title={this.getDescription()}>
<InfoIcon />
</Tooltip>
</div>
)
}
renderField(){
const {propertyType} = this.props const {propertyType} = this.props
switch(propertyType.dataType){ switch(propertyType.dataType){
...@@ -59,14 +79,12 @@ class ObjectTypePropertyPreview extends React.Component { ...@@ -59,14 +79,12 @@ class ObjectTypePropertyPreview extends React.Component {
} }
renderBoolean(){ renderBoolean(){
const {classes} = this.props
return ( return (
<FormControl> <FormControlLabel classes={{ root: classes.boolean }}
<FormControlLabel control={<Checkbox />}
control={<Checkbox />} label={this.getLabel()}
label={this.getLabel()} />
/>
<FormHelperText>{this.getDescription()}</FormHelperText>
</FormControl>
) )
} }
...@@ -74,7 +92,7 @@ class ObjectTypePropertyPreview extends React.Component { ...@@ -74,7 +92,7 @@ class ObjectTypePropertyPreview extends React.Component {
return ( return (
<TextField <TextField
label={this.getLabel()} label={this.getLabel()}
helperText={this.getDescription()} fullWidth={true}
variant="filled" variant="filled"
/> />
) )
...@@ -84,8 +102,8 @@ class ObjectTypePropertyPreview extends React.Component { ...@@ -84,8 +102,8 @@ class ObjectTypePropertyPreview extends React.Component {
return ( return (
<TextField <TextField
label={this.getLabel()} label={this.getLabel()}
helperText={this.getDescription()}
multiline={true} multiline={true}
fullWidth={true}
variant="filled" variant="filled"
/> />
) )
...@@ -95,8 +113,8 @@ class ObjectTypePropertyPreview extends React.Component { ...@@ -95,8 +113,8 @@ class ObjectTypePropertyPreview extends React.Component {
return ( return (
<TextField <TextField
label={this.getLabel()} label={this.getLabel()}
helperText={this.getDescription()}
type="number" type="number"
fullWidth={true}
variant="filled" variant="filled"
/> />
) )
...@@ -104,21 +122,19 @@ class ObjectTypePropertyPreview extends React.Component { ...@@ -104,21 +122,19 @@ class ObjectTypePropertyPreview extends React.Component {
renderVocabulary(){ renderVocabulary(){
return ( return (
<FormControl> <TextField
<FormControlLabel select
control={ label={this.getLabel()}
<Select value={this.getValue('vocabulary')} onChange={this.handleChange('vocabulary')}> value={this.getValue('vocabulary')}
<MenuItem value=""></MenuItem> onChange={this.handleChange('vocabulary')}
{this.getTerms().map(term => ( fullWidth={true}
<MenuItem key={term.code} value={term.code}>{term.label || term.code}</MenuItem> variant="filled"
))} >
</Select> <MenuItem value=""></MenuItem>
} {this.getTerms().map(term => (
label={this.getLabel()} <MenuItem key={term.code} value={term.code}>{term.label || term.code}</MenuItem>
labelPlacement="top" ))}
/> </TextField>
<FormHelperText>{this.getDescription()}</FormHelperText>
</FormControl>
) )
} }
......
...@@ -5,9 +5,7 @@ import { DropTarget } from 'react-dnd' ...@@ -5,9 +5,7 @@ import { DropTarget } from 'react-dnd'
import MenuItem from '@material-ui/core/MenuItem' import MenuItem from '@material-ui/core/MenuItem'
import TableCell from '@material-ui/core/TableCell' import TableCell from '@material-ui/core/TableCell'
import TableRow from '@material-ui/core/TableRow' import TableRow from '@material-ui/core/TableRow'
import FormControl from '@material-ui/core/FormControl' import TextField from '@material-ui/core/TextField'
import FormHelperText from '@material-ui/core/FormHelperText'
import Select from '@material-ui/core/Select'
import Checkbox from '@material-ui/core/Checkbox' import Checkbox from '@material-ui/core/Checkbox'
import DragHandleIcon from '@material-ui/icons/DragHandle' import DragHandleIcon from '@material-ui/icons/DragHandle'
import RootRef from '@material-ui/core/RootRef' import RootRef from '@material-ui/core/RootRef'
...@@ -147,21 +145,20 @@ class ObjectTypeTableRow extends React.Component { ...@@ -147,21 +145,20 @@ class ObjectTypeTableRow extends React.Component {
const {property, propertyTypes} = this.props const {property, propertyTypes} = this.props
return ( return (
<FormControl error={property.errors['propertyType'] ? true : false}> <TextField
<Select select
value={property.propertyType ? property.propertyType.code : ''} value={property.propertyType ? property.propertyType.code : ''}
onClick={event => {event.stopPropagation()}} onClick={event => {event.stopPropagation()}}
onChange={this.handleChangePropertyType} onChange={this.handleChangePropertyType}
> fullWidth={true}
<MenuItem value=""></MenuItem> error={property.errors['propertyType'] ? true : false}
{propertyTypes && propertyTypes.map(propertyType => ( helperText={property.errors['propertyType']}
<MenuItem key={propertyType.code} value={propertyType.code}>{propertyType.code}</MenuItem> >
))} <MenuItem value=""></MenuItem>
</Select> {propertyTypes && propertyTypes.map(propertyType => (
{property.errors['type'] && <MenuItem key={propertyType.code} value={propertyType.code}>{propertyType.code}</MenuItem>
<FormHelperText>{property.errors['type']}</FormHelperText> ))}
} </TextField>
</FormControl>
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment