Skip to content

Commit

Permalink
Merge pull request #954 from codaco/fix/consecutive-alter-forms
Browse files Browse the repository at this point in the history
ensure unique form names
  • Loading branch information
jthrilly authored Aug 22, 2019
2 parents 9c4439c + 2055b3c commit 1253350
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 36 deletions.
8 changes: 5 additions & 3 deletions src/containers/AlterForms/SlideFormEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class SlideFormEdge extends PureComponent {
edge,
edgeColor,
nodes,
index,
edgeIndex,
subject,
stageIndex,
} = this.props;

const fromNode = find(nodes, [entityPrimaryKeyProperty, edge.from]);
Expand All @@ -42,7 +43,7 @@ class SlideFormEdge extends PureComponent {
initialValues={edge[entityAttributesProperty]}
autoFocus={false}
subject={subject}
form={`EDGE_FORM_${index + 1}`}
form={`EDGE_FORM_${stageIndex}_${edgeIndex + 1}`}
onSubmit={this.handleSubmit}
/>
</Scroller>
Expand All @@ -66,7 +67,8 @@ SlideFormEdge.propTypes = {
updateEdge: PropTypes.func.isRequired,
subject: PropTypes.object.isRequired,
edge: PropTypes.object.isRequired,
index: PropTypes.number.isRequired,
edgeIndex: PropTypes.number.isRequired,
stageIndex: PropTypes.number.isRequired,
};

export { SlideFormEdge };
Expand Down
10 changes: 6 additions & 4 deletions src/containers/AlterForms/SlideFormNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class SlideForm extends PureComponent {
const {
form,
node,
index,
nodeIndex,
subject,
stageIndex,
} = this.props;

return (
Expand All @@ -32,7 +33,7 @@ class SlideForm extends PureComponent {
initialValues={node[entityAttributesProperty]}
autoFocus={false}
subject={subject}
form={`NODE_FORM_${index + 1}`}
form={`NODE_FORM_${stageIndex}_${nodeIndex + 1}`}
onSubmit={this.handleSubmit}
/>
</Scroller>
Expand All @@ -48,12 +49,13 @@ SlideForm.propTypes = {
subject: PropTypes.object.isRequired,
node: PropTypes.object,
onUpdate: PropTypes.func,
index: PropTypes.number,
nodeIndex: PropTypes.number,
stageIndex: PropTypes.number.isRequired,
};

SlideForm.defaultProps = {
form: {},
index: 0,
nodeIndex: 0,
node: {},
onUpdate: () => {},
};
Expand Down
2 changes: 2 additions & 0 deletions src/containers/AlterForms/__tests__/SlideFormEdge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const mockProps = {
entity: 'edge',
type: 'friend',
},
edgeIndex: 1,
stageIndex: 1,
};

describe('<SlideFormEdge />', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/containers/AlterForms/__tests__/SlideFormNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const mockProps = {
entity: 'node',
type: 'person',
},
nodeIndex: 1,
stageIndex: 1,
};

describe('<SlideFormNode />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ShallowWrapper {
}
}
edgeColor="blue"
edgeIndex={1}
form={
Object {
"entity": "edge",
Expand All @@ -28,6 +29,7 @@ ShallowWrapper {
},
}
}
stageIndex={1}
/>,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
Expand Down Expand Up @@ -63,7 +65,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="edge"
form="EDGE_FORM_NaN"
form="EDGE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand Down Expand Up @@ -100,7 +102,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="edge"
form="EDGE_FORM_NaN"
form="EDGE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand Down Expand Up @@ -156,7 +158,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="edge"
form="EDGE_FORM_NaN"
form="EDGE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand All @@ -176,7 +178,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="edge"
form="EDGE_FORM_NaN"
form="EDGE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand All @@ -193,7 +195,7 @@ ShallowWrapper {
"autoFocus": false,
"className": "alter-form__form",
"entity": "edge",
"form": "EDGE_FORM_NaN",
"form": "EDGE_FORM_1_2",
"initialValues": undefined,
"onSubmit": [Function],
"subject": undefined,
Expand Down Expand Up @@ -240,7 +242,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="edge"
form="EDGE_FORM_NaN"
form="EDGE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand Down Expand Up @@ -277,7 +279,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="edge"
form="EDGE_FORM_NaN"
form="EDGE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand Down Expand Up @@ -333,7 +335,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="edge"
form="EDGE_FORM_NaN"
form="EDGE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand All @@ -353,7 +355,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="edge"
form="EDGE_FORM_NaN"
form="EDGE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand All @@ -370,7 +372,7 @@ ShallowWrapper {
"autoFocus": false,
"className": "alter-form__form",
"entity": "edge",
"form": "EDGE_FORM_NaN",
"form": "EDGE_FORM_1_2",
"initialValues": undefined,
"onSubmit": [Function],
"subject": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ ShallowWrapper {
"type": "person",
}
}
index={0}
node={
Object {
"name": "Bob",
}
}
nodeIndex={1}
onUpdate={[Function]}
stageIndex={1}
/>,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
Expand Down Expand Up @@ -46,7 +47,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="node"
form="NODE_FORM_1"
form="NODE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand Down Expand Up @@ -76,7 +77,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="node"
form="NODE_FORM_1"
form="NODE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand Down Expand Up @@ -111,7 +112,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="node"
form="NODE_FORM_1"
form="NODE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand All @@ -131,7 +132,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="node"
form="NODE_FORM_1"
form="NODE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand All @@ -148,7 +149,7 @@ ShallowWrapper {
"autoFocus": false,
"className": "alter-form__form",
"entity": "node",
"form": "NODE_FORM_1",
"form": "NODE_FORM_1_2",
"initialValues": undefined,
"onSubmit": [Function],
"subject": undefined,
Expand Down Expand Up @@ -188,7 +189,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="node"
form="NODE_FORM_1"
form="NODE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand Down Expand Up @@ -218,7 +219,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="node"
form="NODE_FORM_1"
form="NODE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand Down Expand Up @@ -253,7 +254,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="node"
form="NODE_FORM_1"
form="NODE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand All @@ -273,7 +274,7 @@ ShallowWrapper {
autoFocus={false}
className="alter-form__form"
entity="node"
form="NODE_FORM_1"
form="NODE_FORM_1_2"
initialValues={undefined}
onSubmit={[Function]}
subject={undefined}
Expand All @@ -290,7 +291,7 @@ ShallowWrapper {
"autoFocus": false,
"className": "alter-form__form",
"entity": "node",
"form": "NODE_FORM_1",
"form": "NODE_FORM_1_2",
"initialValues": undefined,
"onSubmit": [Function],
"subject": undefined,
Expand Down
11 changes: 7 additions & 4 deletions src/containers/Interfaces/AlterEdgeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AlterEdgeForm extends Component {
};
}

getEdgeFormName = activeIndex => `EDGE_FORM_${activeIndex}`;
getEdgeFormName = activeIndex => `EDGE_FORM_${this.props.stageIndex}_${activeIndex}`;

formSubmitAllowed = index => (
this.props.formEnabled(this.getEdgeFormName(index))
Expand Down Expand Up @@ -79,6 +79,7 @@ class AlterEdgeForm extends Component {
form,
stage,
stageEdges,
stageIndex,
updateEdge,
} = this.props;

Expand Down Expand Up @@ -116,12 +117,13 @@ class AlterEdgeForm extends Component {
</div>
</div>

{stageEdges.map((edge, index) => (
{stageEdges.map((edge, edgeIndex) => (
<SlideFormEdge
key={index}
key={edgeIndex}
subject={stage.subject}
edge={edge}
index={index}
edgeIndex={edgeIndex}
stageIndex={stageIndex}
updateEdge={updateEdge}
form={form}
/>
Expand All @@ -143,6 +145,7 @@ AlterEdgeForm.propTypes = {
formEnabled: PropTypes.func.isRequired,
stage: PropTypes.object.isRequired,
stageEdges: PropTypes.array,
stageIndex: PropTypes.number.isRequired,
submitForm: PropTypes.func.isRequired,
updateEdge: PropTypes.func.isRequired,
};
Expand Down
11 changes: 7 additions & 4 deletions src/containers/Interfaces/AlterForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AlterForm extends Component {
};
}

getNodeFormName = activeIndex => `NODE_FORM_${activeIndex}`;
getNodeFormName = activeIndex => `NODE_FORM_${this.props.stageIndex}_${activeIndex}`;

formSubmitAllowed = index => (
this.props.formEnabled(this.getNodeFormName(index))
Expand Down Expand Up @@ -84,6 +84,7 @@ class AlterForm extends Component {
form,
stage,
stageNodes,
stageIndex,
} = this.props;

const swiperParams = {
Expand Down Expand Up @@ -120,12 +121,13 @@ class AlterForm extends Component {
</div>
</div>

{stageNodes.map((node, index) => (
{stageNodes.map((node, nodeIndex) => (
<SlideFormNode
key={index}
key={nodeIndex}
subject={stage.subject}
node={node}
index={index}
nodeIndex={nodeIndex}
stageIndex={stageIndex}
onUpdate={this.handleUpdate}
form={form}
/>
Expand All @@ -147,6 +149,7 @@ AlterForm.propTypes = {
formEnabled: PropTypes.func.isRequired,
stage: PropTypes.object.isRequired,
stageNodes: PropTypes.array,
stageIndex: PropTypes.number.isRequired,
submitForm: PropTypes.func.isRequired,
updateNode: PropTypes.func.isRequired,
};
Expand Down

0 comments on commit 1253350

Please sign in to comment.