From 05f9026d2fef45420f604e0275e28f271189ff1d Mon Sep 17 00:00:00 2001 From: Joshua Melville Date: Wed, 18 Sep 2019 17:12:40 +0100 Subject: [PATCH] revert changes to withEditHandlers that caused sociogram prompt editing to break --- src/components/EditableList/withEditHandlers.js | 7 +++---- .../sections/CategoricalBinPrompts/helpers.js | 7 ++++++- src/components/sections/Form/helpers.js | 11 ++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/EditableList/withEditHandlers.js b/src/components/EditableList/withEditHandlers.js index d99ad788e..0e94b69d2 100644 --- a/src/components/EditableList/withEditHandlers.js +++ b/src/components/EditableList/withEditHandlers.js @@ -35,11 +35,10 @@ const mapDispatchToProps = (dispatch, { form }) => ({ }); const mapItemStateToProps = (state, { form, itemSelector, editField, template }) => { - const item = formValueSelector(form)(state, editField); + const item = itemSelector(state, { form, editField }); + const initialValues = item || { ...template(), id: uuid() }; - if (!item) { return { initialValues: { ...template(), id: uuid() } }; } - - return { initialValues: itemSelector(state, item) }; + return { initialValues }; }; const stateHandlers = withStateHandlers( diff --git a/src/components/sections/CategoricalBinPrompts/helpers.js b/src/components/sections/CategoricalBinPrompts/helpers.js index fc8e88ef9..b247e06e7 100644 --- a/src/components/sections/CategoricalBinPrompts/helpers.js +++ b/src/components/sections/CategoricalBinPrompts/helpers.js @@ -1,9 +1,14 @@ /* eslint-disable import/prefer-default-export */ +import { formValueSelector } from 'redux-form'; import { getOptionsForVariable } from '../../../selectors/codebook'; export const itemSelector = (entity, type) => - (state, prompt) => { + (state, { form, editField }) => { + const prompt = formValueSelector(form)(state, editField); + + if (!prompt) { return null; } + const variableOptions = getOptionsForVariable( state, { entity, type, variable: prompt.variable }, diff --git a/src/components/sections/Form/helpers.js b/src/components/sections/Form/helpers.js index c53a20128..a2e571502 100644 --- a/src/components/sections/Form/helpers.js +++ b/src/components/sections/Form/helpers.js @@ -1,4 +1,5 @@ +import { formValueSelector } from 'redux-form'; import { omit, get, reduce } from 'lodash'; import { getVariablesForSubject } from '../../../selectors/codebook'; @@ -23,15 +24,19 @@ export const normalizeField = field => // Merge item with variable info from codebook export const itemSelector = (entity, type) => - (state, prompt) => { - const variable = prompt.variable; + (state, { form, editField }) => { + const item = formValueSelector(form)(state, editField); + + if (!item) { return null; } + + const variable = item && item.variable; const codebookVariables = getVariablesForSubject(state, { entity, type }); const codebookVariable = get(codebookVariables, variable, {}); const codebookProperties = getCodebookProperties(codebookVariable); return { - ...prompt, + ...item, ...codebookProperties, }; };