Skip to content

Commit

Permalink
Fix array references
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrozsival committed Nov 6, 2017
1 parent 642e1f1 commit f4f46ed
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/components/forms/Fields/ExpandingTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class ExpandingTextField extends Component {

componentDidMount() {
const { input: { value } } = this.props;
const initialValue = Array.isArray(value) ? value.concat(['']) : [''];
const initialValue = Array.isArray(value)
? value.concat([''])
: [value, ''];
this.setState({ texts: initialValue });
}

Expand All @@ -41,6 +43,8 @@ class ExpandingTextField extends Component {
}
};

isReference = () => {};

render() {
const {
label = '',
Expand Down
15 changes: 12 additions & 3 deletions src/components/forms/Fields/PipelineVariablesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import {
} from '../Fields';
import ResourceRenderer from '../../helpers/ResourceRenderer';

const isArray = (type = '') =>
typeof type === 'string' && type.indexOf('[]') === type.length - 2;
const isArray = (firstValue, type = '') =>
firstValue.length > 0 &&
firstValue[0] !== '$' &&
typeof type === 'string' &&
type.indexOf('[]') === type.length - 2;

const firstValue = value => (Array.isArray(value) ? value[0] : value);

const PipelineVariablesField = ({
input,
Expand Down Expand Up @@ -63,7 +68,11 @@ const PipelineVariablesField = ({
<Field
key={value}
name={`${input.name}.${value}`}
component={isArray(type) ? ExpandingTextField : TextField}
component={
isArray(firstValue(input.value[value]), type)
? ExpandingTextField
: TextField
}
label={`${atob(value)}: `}
/>}
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/components/forms/Fields/PortField.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const getLabelStyle = portType => (isArrayType(portType) ? 'primary' : 'info');
const PortField = ({
input,
meta: { touched, error },
type = 'text',
label,
portType,
...props
Expand All @@ -35,7 +34,7 @@ const PortField = ({
{portType}
</Label>
</ControlLabel>
<FormControl {...input} {...props} type={type} />
<FormControl {...input} {...props} type="text" />
{error &&
<HelpBlock>
{' '}{touched
Expand All @@ -48,7 +47,6 @@ const PortField = ({
</FormGroup>;

PortField.propTypes = {
type: PropTypes.string,
input: PropTypes.shape({
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired
}).isRequired,
Expand Down
15 changes: 12 additions & 3 deletions src/components/forms/Fields/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'react-bootstrap';

const TextField = ({
input,
input: { value, ...input },
meta: { touched, error },
type = 'text',
label,
Expand All @@ -23,7 +23,12 @@ const TextField = ({
<ControlLabel>
{label}
</ControlLabel>
<FormControl {...input} {...props} type={type} />
<FormControl
{...input}
{...props}
type={type}
value={Array.isArray(value) ? value[0] : value}
/>
{error &&
<HelpBlock>
{' '}{touched
Expand All @@ -38,7 +43,11 @@ const TextField = ({
TextField.propTypes = {
type: PropTypes.string,
input: PropTypes.shape({
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired
value: PropTypes.oneOfType([
PropTypes.array,
PropTypes.string,
PropTypes.number
]).isRequired
}).isRequired,
meta: PropTypes.shape({
touched: PropTypes.bool,
Expand Down

0 comments on commit f4f46ed

Please sign in to comment.