Skip to content

Commit

Permalink
fix: update schema to re-render when idschema changes (#1493)
Browse files Browse the repository at this point in the history
* fix: update arrays correctly when changing index

* fix: Update anyOf schema to correctly update items in an array

* fix: update schema to re-render when idschema changes
  • Loading branch information
SuriGill authored and epicfaace committed Nov 9, 2019
1 parent 29c704e commit 70c3a03
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,7 @@ function SchemaFieldRender(props) {

class SchemaField extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
// if schemas are equal idSchemas will be equal as well,
// so it is not necessary to compare
return !deepEquals(
{ ...this.props, idSchema: undefined },
{ ...nextProps, idSchema: undefined }
);
return !deepEquals(this.props, nextProps);
}

render() {
Expand Down
47 changes: 47 additions & 0 deletions test/anyOf_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,53 @@ describe("anyOf", () => {
expect(selects[1].value).eql("0");
});

it("should correctly update inputs for anyOf inside array items after being moved down", () => {
const schema = {
type: "object",
properties: {
items: {
type: "array",
items: {
type: "object",
anyOf: [
{
properties: {
foo: {
type: "string",
},
},
},
{
properties: {
bar: {
type: "string",
},
},
},
],
},
},
},
};

const { node } = createFormComponent({
schema,
formData: {
items: [{}, {}],
},
});

const moveDownBtns = node.querySelectorAll(".array-item-move-down");
Simulate.click(moveDownBtns[0]);

const strInputs = node.querySelectorAll(
"fieldset .field-string input[type=text]"
);

Simulate.change(strInputs[1], { target: { value: "bar" } });
expect(strInputs[1].value).eql("bar");
});

it("should correctly render mixed types for anyOf inside array items", () => {
const schema = {
type: "object",
Expand Down

0 comments on commit 70c3a03

Please sign in to comment.