Skip to content

Commit

Permalink
Default fields to solve empty array issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Apr 17, 2020
1 parent a1843fa commit b674013
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/containers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,28 @@ class IndexContainer extends Component {
this.state.action
&& this.state.action !== nextState.action
) {
const { abi, action } = nextState;
const { structs } = abi;
const struct = find(structs, { name: action });
if (struct) {
const { fields } = struct;
const defaultFields = {};
fields.forEach((field) => {
this.updateFields(nextState)
}
}

updateFields = (state) => {
const { abi, action } = state;
const { structs } = abi;
const struct = find(structs, { name: action });
if (struct) {
const { fields } = struct;
const defaultFields = {};
fields.forEach((field) => {
if (field.type && field.type.substr(field.type.length - 2) === "[]") {
defaultFields[field.name] = [];
} else {
defaultFields[field.name] = '';
});
this.setState({
uri: undefined,
fields: defaultFields
});
}
}
});
this.setState({
uri: undefined,
fields: defaultFields
});
}
}

Expand Down

0 comments on commit b674013

Please sign in to comment.