From a373bb7f0f4e5321f05e18a761e24658eb56def5 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 22 Jun 2020 11:03:43 -0500 Subject: [PATCH] feat: actions, traversal, routines state --- src/client/types/actions.type-renderer.jsx | 61 ++++++++++++-------- src/client/types/routines.type-renderer.jsx | 20 ++++++- src/client/types/traversal.type-renderer.jsx | 20 +++++-- 3 files changed, 70 insertions(+), 31 deletions(-) diff --git a/src/client/types/actions.type-renderer.jsx b/src/client/types/actions.type-renderer.jsx index ac59c02..637603e 100644 --- a/src/client/types/actions.type-renderer.jsx +++ b/src/client/types/actions.type-renderer.jsx @@ -13,30 +13,45 @@ const decorate = compose( const Actions = ({ context, onChange = () => {}, - value, -}) => ( -
-
    - { - value && value.traversals.length > 0 && ( - value.traversals.map( - (traversal, i) => ( - // eslint-disable-next-line react/no-array-index-key -
  1. - -
  2. - ), + value = {}, +}) => { + const {traversals = []} = value; + return ( +
    +
      + { + traversals.length > 0 && ( + traversals.map( + (traversal, i) => ( + // eslint-disable-next-line react/no-array-index-key +
    1. + { + return onChange({ + ...value, + traversals: [ + ...traversals.slice(0, i), + { + ...traversals[i], + ...traversalValue, + }, + ...traversals.slice(i + 1), + ], + }); + }} + type="any" + value={traversal} + /> +
    2. + ), + ) ) - ) - } -
    -
    -); + } +
+
+ ); +}; Actions.propTypes = { ...propTypes, diff --git a/src/client/types/routines.type-renderer.jsx b/src/client/types/routines.type-renderer.jsx index c1a9b08..880aa15 100644 --- a/src/client/types/routines.type-renderer.jsx +++ b/src/client/types/routines.type-renderer.jsx @@ -13,9 +13,10 @@ const decorate = compose( const Routines = ({ context, onChange = () => {}, - value, + value = {}, }) => { - const entries = value.routines ? Object.entries(value.routines) : []; + const {routines = {}} = value; + const entries = Object.entries(routines); return (
    @@ -28,7 +29,20 @@ const Routines = ({ {name} { + return onChange({ + ...value, + routines: { + ...routines, + [name]: { + ...routine, + routine: { + ...actionsValue, + }, + }, + }, + }); + }} value={routine.routine} /> diff --git a/src/client/types/traversal.type-renderer.jsx b/src/client/types/traversal.type-renderer.jsx index b8db68e..3345331 100644 --- a/src/client/types/traversal.type-renderer.jsx +++ b/src/client/types/traversal.type-renderer.jsx @@ -5,7 +5,12 @@ import React from 'react'; import Value from '~/client/value'; import propTypes from './prop-types'; -import {descriptionFromSteps, stepsOptions, typeFromSteps} from './typing'; +import { + descriptionFromSteps, + stepsOptions, + toBehaviorItem, + typeFromSteps, +} from './typing'; const decorate = compose( contempo(require('./traversal.raw.scss')), @@ -16,8 +21,9 @@ const Traversal = (props) => { context, onChange = () => {}, type, - value: {steps, value}, + value = {}, } = props; + const {steps, value: assignValue} = value; const stepsType = type || typeFromSteps(context, steps); const optionsList = stepsOptions(context, steps, stepsType); return ( @@ -72,14 +78,18 @@ const Traversal = (props) => { ))} { - value && ( + assignValue && ( = onChange({ + ...value, + steps, + value: toBehaviorItem(valueValue), + })} type={stepsType} - value={value} + value={assignValue} /> )