Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipelines references #133

Merged
merged 3 commits into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
81 changes: 49 additions & 32 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 All @@ -30,36 +35,48 @@ const PipelineVariablesField = ({
id="app.portsField.empty"
defaultMessage="There are no ports."
/>}
{variables.map(({ value, type }, i) =>
<div key={i}>
{(type === 'remote-file' || type === 'remote-file[]') &&
<ResourceRenderer resource={supplementaryFiles.toArray()}>
{(...supplementaryFiles) =>
<Field
name={`${input.name}.${value}`}
component={isArray(type) ? ExpandingSelectField : SelectField}
options={[{ key: '', name: '...' }].concat(
supplementaryFiles
.sort((a, b) => a.name.localeCompare(b.name, intl.locale))
.filter((item, pos, arr) => arr.indexOf(item) === pos)
.map(data => ({
key: data.hashName,
name: data.name
}))
)}
label={`${atob(value)}: `}
/>}
</ResourceRenderer>}
{type !== 'remote-file' &&
type !== 'remote-file[]' &&
<Field
key={value}
name={`${input.name}.${value}`}
component={isArray(type) ? ExpandingTextField : TextField}
label={`${atob(value)}: `}
/>}
</div>
)}
{variables
.reduce(
(acc, variable) =>
acc.find(used => used.value === variable.value)
? acc
: [...acc, variable],
[]
)
.map(({ value, type }, i) =>
<div key={i}>
{(type === 'remote-file' || type === 'remote-file[]') &&
<ResourceRenderer resource={supplementaryFiles.toArray()}>
{(...supplementaryFiles) =>
<Field
name={`${input.name}.${value}`}
component={isArray(type) ? ExpandingSelectField : SelectField}
options={[{ key: '', name: '...' }].concat(
supplementaryFiles
.sort((a, b) => a.name.localeCompare(b.name, intl.locale))
.filter((item, pos, arr) => arr.indexOf(item) === pos)
.map(data => ({
key: data.hashName,
name: data.name
}))
)}
label={`${atob(value)}: `}
/>}
</ResourceRenderer>}
{type !== 'remote-file' &&
type !== 'remote-file[]' &&
<Field
key={value}
name={`${input.name}.${value}`}
component={
isArray(firstValue(input.value[value]), type)
? ExpandingTextField
: TextField
}
label={`${atob(value)}: `}
/>}
</div>
)}
</div>;

PipelineVariablesField.propTypes = {
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
19 changes: 16 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,16 @@ const TextField = ({
<ControlLabel>
{label}
</ControlLabel>
<FormControl {...input} {...props} type={type} />
<FormControl
{...input}
{...props}
type={type}
value={
typeof value === 'string' || typeof value === 'number'
? value
: value[0]
}
/>
{error &&
<HelpBlock>
{' '}{touched
Expand All @@ -38,7 +47,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