Skip to content

Commit

Permalink
Merge pull request #861 from trendscenter/fix/pipeline-default-value
Browse files Browse the repository at this point in the history
Default values were not committed on pipeline edit
  • Loading branch information
rssk authored Apr 14, 2020
2 parents f39b332 + d5dd7da commit c314333
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,55 @@ import PropTypes from 'prop-types';
import Select from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem';

function PipelineStepInputArray({
objKey, objParams, owner, updateStep, getNewObj, getSelectList, step,
}) {
return (
<Select
disabled={!owner}
multiple
onChange={event => updateStep({
class PipelineStepInputArray extends React.Component {
componentDidMount() {
const {
objKey, objParams, owner, updateStep, getNewObj, getSelectList, step,
} = this.props;

if (!step.inputMap[objKey] && 'default' in objParams && owner) {
updateStep({
...step,
inputMap: getNewObj(
objKey,
event.target.value
? { value: getSelectList(step.inputMap[objKey].value, event.target.value) }
: 'DELETE_VAR'
{ value: getSelectList(step.inputMap[objKey].value, objParams.default) }
),
})}
value={
step.inputMap[objKey] && 'value' in step.inputMap[objKey]
? step.inputMap[objKey].value
: [objParams.default]
}
>
{
objParams.values.map(val => (
<MenuItem key={`${val}-select-option`} value={val}>{val}</MenuItem>
))
}
</Select>
);
});
}
}

render() {
const {
objKey, objParams, owner, updateStep, getNewObj, getSelectList, step,
} = this.props;

return (
<Select
disabled={!owner}
multiple
onChange={event => updateStep({
...step,
inputMap: getNewObj(
objKey,
event.target.value
? { value: getSelectList(step.inputMap[objKey].value, event.target.value) }
: 'DELETE_VAR'
),
})}
value={
step.inputMap[objKey] && 'value' in step.inputMap[objKey]
? step.inputMap[objKey].value
: [objParams.default]
}
>
{
objParams.values.map(val => (
<MenuItem key={`${val}-select-option`} value={val}>{val}</MenuItem>
))
}
</Select>
);
}
}

PipelineStepInputArray.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,57 @@ import React from 'react';
import PropTypes from 'prop-types';
import TextField from '@material-ui/core/TextField';

function PipelineStepInputNumberTextField({
objKey, objParams, owner, isFromCache, updateStep, getNewObj, step,
}) {
if (!step) {
return null;
}
class PipelineStepInputNumberTextField extends React.Component {
componentDidMount() {
const {
objKey,
objParams,
owner,
updateStep,
getNewObj,
step,
} = this.props;

return (
<TextField
disabled={!owner || isFromCache}
name={`step-${objKey}`}
type="number"
onChange={event => updateStep({
if (!step.inputMap[objKey] && 'default' in objParams && owner) {
updateStep({
...step,
inputMap: getNewObj(objKey, event.target.value ? { value: parseFloat(event.target.value) } : 'DELETE_VAR'),
})}
value={
step.inputMap[objKey] && 'value' in step.inputMap[objKey]
? step.inputMap[objKey].value
: objParams.default
}
/>
);
inputMap: getNewObj(objKey, { value: parseFloat(objParams.default) }),
});
}
}

render() {
const {
objKey,
objParams,
owner,
isFromCache,
updateStep,
getNewObj,
step,
} = this.props;

if (!step) {
return null;
}

return (
<TextField
disabled={!owner || isFromCache}
name={`step-${objKey}`}
type="number"
onChange={event => updateStep({
...step,
inputMap: getNewObj(objKey, event.target.value ? { value: parseFloat(event.target.value) } : 'DELETE_VAR'),
})}
value={
step.inputMap[objKey] && 'value' in step.inputMap[objKey]
? step.inputMap[objKey].value
: objParams.default
}
/>
);
}
}

PipelineStepInputNumberTextField.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,51 @@ import RadioGroup from '@material-ui/core/RadioGroup';
import Radio from '@material-ui/core/Radio';
import FormControlLabel from '@material-ui/core/FormControlLabel';

function PipelineStepInputRadio({
objKey, objParams, owner, updateStep, getNewObj, step,
}) {
if (!step || !objParams.values) {
return null;
}
class PipelineStepInputRadio extends React.Component {
componentDidMount() {
const {
objKey, objParams, owner, updateStep, getNewObj, step,
} = this.props;

return (
<RadioGroup
disabled={!owner}
onChange={event => updateStep({
if (!step.inputMap[objKey] && 'default' in objParams && owner) {
updateStep({
...step,
inputMap: getNewObj(objKey, event.target.checked ? { value: event.target.checked } : 'DELETE_VAR'),
})}
value={
step.inputMap[objKey] && 'value' in step.inputMap[objKey]
? step.inputMap[objKey].value
: objParams.default
}
>
{
objParams.values.map(val => (
<FormControlLabel
value={val}
control={<Radio />}
label={val}
labelPlacement="start"
/>
))
}
</RadioGroup>
);
inputMap: getNewObj(objKey, { value: objParams.default }),
});
}
}

render() {
const {
objKey, objParams, owner, updateStep, getNewObj, step,
} = this.props;

return (
<RadioGroup
disabled={!owner}
onChange={event => updateStep({
...step,
inputMap: getNewObj(objKey, event.target.checked ? { value: event.target.checked } : 'DELETE_VAR'),
})}
value={
step.inputMap[objKey] && 'value' in step.inputMap[objKey]
? step.inputMap[objKey].value
: objParams.default
}
>
{
objParams.values.map(val => (
<FormControlLabel
value={val}
control={<Radio />}
label={val}
labelPlacement="start"
/>
))
}
</RadioGroup>
);
}
}

PipelineStepInputRadio.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,64 @@ function makeNumberRange(min, max, step) {
return range;
}

function PipelineStepInputRange({
objKey, objParams, owner, updateStep, getNewObj, step,
}) {
if (!step || !objParams.min || !objParams.max || !objParams.step) {
return null;
}
class PipelineStepInputRange extends React.Component {
componentDidMount() {
const {
objKey, objParams, owner, updateStep, getNewObj, step,
} = this.props;

return (
<Select
disabled={!owner}
onChange={event => updateStep({
if (!step.inputMap[objKey] && 'default' in objParams && owner) {
updateStep({
...step,
inputMap: getNewObj(
objKey,
event.target.value
? { value: event.target.value }
: 'DELETE_VAR'
{ value: objParams.default }
),
})}
value={step.inputMap[objKey] && 'value' in step.inputMap[objKey]
? step.inputMap[objKey].value
: parseFloat(objParams.default)
}
>
{
makeNumberRange(objParams.min, objParams.max, objParams.step).map(val => (
<MenuItem
key={`${val}-select-option`}
value={parseFloat(val)}
selected={val === objParams.default}
>
{val.toString()}
</MenuItem>
))
}
</Select>
);
});
}
}

render() {
const {
objKey, objParams, owner, updateStep, getNewObj, step,
} = this.props;

if (!step || !objParams.min || !objParams.max || !objParams.step) {
return null;
}

const value = step.inputMap[objKey] && 'value' in step.inputMap[objKey]
? step.inputMap[objKey].value
: parseFloat(objParams.default);

return (
<Select
disabled={!owner}
onChange={event => updateStep({
...step,
inputMap: getNewObj(
objKey,
event.target.value
? { value: event.target.value }
: 'DELETE_VAR'
),
})}
value={value}
>
{
makeNumberRange(objParams.min, objParams.max, objParams.step).map(val => (
<MenuItem
key={`${val}-select-option`}
value={parseFloat(val)}
selected={val === value}
>
{val.toString()}
</MenuItem>
))
}
</Select>
);
}
}

PipelineStepInputRange.propTypes = {
Expand Down
Loading

0 comments on commit c314333

Please sign in to comment.