From f0dd2ca416ff9273df5783b286303c091d95e9fd Mon Sep 17 00:00:00 2001 From: Mael Date: Sat, 3 Aug 2019 15:30:19 +0200 Subject: [PATCH] =?UTF-8?q?Passer=20donne=20la=20valeur=20par=20d=C3=A9fau?= =?UTF-8?q?t,=20pas=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #610 --- source/actions/actions.js | 11 +++++---- .../components/conversation/Conversation.js | 23 +++++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/source/actions/actions.js b/source/actions/actions.js index 395706a18..ea25b89e7 100644 --- a/source/actions/actions.js +++ b/source/actions/actions.js @@ -8,7 +8,7 @@ import type { SetSituationBranchAction } from 'Types/ActionsTypes' // $FlowFixMe -import { clearFields, reset } from 'redux-form' +import { change, reset } from 'redux-form' import { deletePersistedSimulation } from '../storage/persistSimulation' import type { Thunk } from 'Types/ActionsTypes' @@ -25,14 +25,15 @@ export const goToQuestion = (question: string): StepAction => ({ name: 'unfold', step: question }) -export const skipQuestion = ( - question: string +export const validateStepWithValue = ( + dottedName, + value: any ): Thunk => dispatch => { - dispatch(clearFields('conversation', false, false, question)) + dispatch(change('conversation', dottedName, value)) dispatch({ type: 'STEP_ACTION', name: 'fold', - step: question + step: dottedName }) } diff --git a/source/components/conversation/Conversation.js b/source/components/conversation/Conversation.js index 70847684e..42e0547ff 100644 --- a/source/components/conversation/Conversation.js +++ b/source/components/conversation/Conversation.js @@ -1,4 +1,8 @@ -import { goToQuestion, resetSimulation, skipQuestion } from 'Actions/actions' +import { + goToQuestion, + resetSimulation, + validateStepWithValue +} from 'Actions/actions' import { T } from 'Components' import QuickLinks from 'Components/QuickLinks' import { getInputComponent } from 'Engine/generateQuestions' @@ -15,6 +19,7 @@ import { import * as Animate from 'Ui/animate' import Aide from './Aide' import './conversation.css' +import { findRuleByDottedName } from 'Engine/rules' export default compose( reduxForm({ @@ -28,7 +33,7 @@ export default compose( previousAnswers: state.conversationSteps.foldedSteps, nextSteps: nextStepsSelector(state) }), - { resetSimulation, skipQuestion, goToQuestion } + { resetSimulation, validateStepWithValue, goToQuestion } ) )(function Conversation({ nextSteps, @@ -37,14 +42,18 @@ export default compose( customEndMessages, flatRules, resetSimulation, - skipQuestion, - goToQuestion + goToQuestion, + validateStepWithValue }) { - const goToNext = () => skipQuestion(nextSteps[0]) + const setDefault = () => + validateStepWithValue( + currentQuestion, + findRuleByDottedName(flatRules, currentQuestion).defaultValue + ) const goToPrevious = () => goToQuestion(previousAnswers.slice(-1)[0]) const handleKeyDown = ({ key }) => { if (['Escape'].includes(key)) { - goToNext() + setDefault() } } return nextSteps.length ? ( @@ -67,7 +76,7 @@ export default compose( )}