|
@@ -24,6 +24,8 @@ import TextInput from '../../atoms/TextInput'
|
|
|
import LabelDictionary from '../../../utils/LabelDictionary'
|
|
import LabelDictionary from '../../../utils/LabelDictionary'
|
|
|
import Palette from '../../styleUtils/Palette'
|
|
import Palette from '../../styleUtils/Palette'
|
|
|
import StyleProps from '../../styleUtils/StyleProps'
|
|
import StyleProps from '../../styleUtils/StyleProps'
|
|
|
|
|
+import Dropdown from '../../molecules/Dropdown'
|
|
|
|
|
+import type { Field } from '../../../types/Field'
|
|
|
|
|
|
|
|
const Wrapper = styled.div`
|
|
const Wrapper = styled.div`
|
|
|
display: flex;
|
|
display: flex;
|
|
@@ -32,7 +34,7 @@ const Wrapper = styled.div`
|
|
|
border-radius: ${StyleProps.borderRadius};
|
|
border-radius: ${StyleProps.borderRadius};
|
|
|
`
|
|
`
|
|
|
const Column = styled.div`
|
|
const Column = styled.div`
|
|
|
- width: 50%;
|
|
|
|
|
|
|
+ ${StyleProps.exactWidth('calc(50% - 16px)')}
|
|
|
height: 32px;
|
|
height: 32px;
|
|
|
display: flex;
|
|
display: flex;
|
|
|
align-items: center;
|
|
align-items: center;
|
|
@@ -47,7 +49,7 @@ const Row = styled.div`
|
|
|
align-items: center;
|
|
align-items: center;
|
|
|
border-bottom: 1px solid ${Palette.grayscale[2]};
|
|
border-bottom: 1px solid ${Palette.grayscale[2]};
|
|
|
&:last-child {
|
|
&:last-child {
|
|
|
- border-bottom-color: transparent;
|
|
|
|
|
|
|
+ border-bottom: 0;
|
|
|
}
|
|
}
|
|
|
&:first-child ${Column} {
|
|
&:first-child ${Column} {
|
|
|
border-top-left-radius: ${StyleProps.borderRadius};
|
|
border-top-left-radius: ${StyleProps.borderRadius};
|
|
@@ -57,21 +59,25 @@ const Row = styled.div`
|
|
|
}
|
|
}
|
|
|
`
|
|
`
|
|
|
|
|
|
|
|
-type PropertyType = {
|
|
|
|
|
- name: string,
|
|
|
|
|
- type: string,
|
|
|
|
|
-}
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
|
- properties: PropertyType[],
|
|
|
|
|
- onChange: (property: PropertyType, value: any) => void,
|
|
|
|
|
- valueCallback: (property: PropertyType) => any,
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ properties: Field[],
|
|
|
|
|
+ onChange: (property: Field, value: any) => void,
|
|
|
|
|
+ valueCallback: (property: Field) => any,
|
|
|
|
|
+ }
|
|
|
@observer
|
|
@observer
|
|
|
class PropertiesTable extends React.Component<Props> {
|
|
class PropertiesTable extends React.Component<Props> {
|
|
|
- renderSwitch(prop: PropertyType) {
|
|
|
|
|
|
|
+ getName(propName: string): string {
|
|
|
|
|
+ if (propName.indexOf('/') > -1) {
|
|
|
|
|
+ return LabelDictionary.get(propName.substr(propName.lastIndexOf('/') + 1))
|
|
|
|
|
+ }
|
|
|
|
|
+ return LabelDictionary.get(propName)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ renderSwitch(prop: Field, opts: { triState: boolean }) {
|
|
|
return (
|
|
return (
|
|
|
<Switch
|
|
<Switch
|
|
|
secondary
|
|
secondary
|
|
|
|
|
+ triState={opts.triState}
|
|
|
height={16}
|
|
height={16}
|
|
|
checked={this.props.valueCallback(prop)}
|
|
checked={this.props.valueCallback(prop)}
|
|
|
onChange={checked => { this.props.onChange(prop, checked) }}
|
|
onChange={checked => { this.props.onChange(prop, checked) }}
|
|
@@ -79,20 +85,63 @@ class PropertiesTable extends React.Component<Props> {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- renderTextInput() {
|
|
|
|
|
|
|
+ renderTextInput(prop: Field) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <TextInput
|
|
|
|
|
+ width="100%"
|
|
|
|
|
+ embedded
|
|
|
|
|
+ value={this.props.valueCallback(prop)}
|
|
|
|
|
+ onChange={e => { this.props.onChange(prop, e.target.value) }}
|
|
|
|
|
+ placeholder={this.getName(prop.name)}
|
|
|
|
|
+ required={typeof prop.required === 'boolean' ? prop.required : false}
|
|
|
|
|
+ />
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ renderEnumDropdown(prop: Field) {
|
|
|
|
|
+ if (!prop.enum) {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ let items = prop.enum.map(e => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ label: this.getName(e),
|
|
|
|
|
+ value: e,
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ items = [
|
|
|
|
|
+ { label: 'Choose a value', value: null },
|
|
|
|
|
+ ...items,
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ let selectedItem = items.find(i => i.value === this.props.valueCallback(prop))
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
- <TextInput />
|
|
|
|
|
|
|
+ <Dropdown
|
|
|
|
|
+ width={320}
|
|
|
|
|
+ noSelectionMessage="Choose a value"
|
|
|
|
|
+ selectedItem={selectedItem ? selectedItem.label : null}
|
|
|
|
|
+ items={items}
|
|
|
|
|
+ onChange={item => this.props.onChange(prop, item.value)}
|
|
|
|
|
+ />
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- renderInput(prop: PropertyType) {
|
|
|
|
|
|
|
+ renderInput(prop: Field) {
|
|
|
let input = null
|
|
let input = null
|
|
|
switch (prop.type) {
|
|
switch (prop.type) {
|
|
|
case 'boolean':
|
|
case 'boolean':
|
|
|
- input = this.renderSwitch(prop)
|
|
|
|
|
|
|
+ input = this.renderSwitch(prop, { triState: true })
|
|
|
|
|
+ break
|
|
|
|
|
+ case 'strict-boolean':
|
|
|
|
|
+ input = this.renderSwitch(prop, { triState: false })
|
|
|
break
|
|
break
|
|
|
case 'string':
|
|
case 'string':
|
|
|
- input = this.renderTextInput()
|
|
|
|
|
|
|
+ if (prop.enum) {
|
|
|
|
|
+ input = this.renderEnumDropdown(prop)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ input = this.renderTextInput(prop)
|
|
|
|
|
+ }
|
|
|
break
|
|
break
|
|
|
default:
|
|
default:
|
|
|
}
|
|
}
|
|
@@ -106,7 +155,7 @@ class PropertiesTable extends React.Component<Props> {
|
|
|
{this.props.properties.map(prop => {
|
|
{this.props.properties.map(prop => {
|
|
|
return (
|
|
return (
|
|
|
<Row key={prop.name}>
|
|
<Row key={prop.name}>
|
|
|
- <Column header>{LabelDictionary.get(prop.name)}</Column>
|
|
|
|
|
|
|
+ <Column header>{this.getName(prop.name)}</Column>
|
|
|
<Column input>{this.renderInput(prop)}</Column>
|
|
<Column input>{this.renderInput(prop)}</Column>
|
|
|
</Row>
|
|
</Row>
|
|
|
)
|
|
)
|