Skip to content

Commit

Permalink
Merge pull request #579 from codaco/fix/sociogram-prompt-editing
Browse files Browse the repository at this point in the history
Fix sociogram prompt editing
  • Loading branch information
jthrilly authored Sep 19, 2019
2 parents 675ed61 + 05f9026 commit ce8dd3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/components/EditableList/withEditHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion src/components/sections/CategoricalBinPrompts/helpers.js
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
11 changes: 8 additions & 3 deletions src/components/sections/Form/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import { formValueSelector } from 'redux-form';
import { omit, get, reduce } from 'lodash';
import { getVariablesForSubject } from '../../../selectors/codebook';

Expand All @@ -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,
};
};

0 comments on commit ce8dd3b

Please sign in to comment.