Skip to content

Commit

Permalink
remove duplicate API call in ReferenceArrayInput
Browse files Browse the repository at this point in the history
  • Loading branch information
fargito committed May 20, 2019
1 parent 26765f3 commit 86e7bfa
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export class UnconnectedReferenceArrayInputController extends Component<
}

componentDidMount() {
this.fetchReferencesAndOptions(this.props);
this.fetchReferences(this.props, true)
this.fetchOptions(this.props)
}

componentWillReceiveProps(nextProps: Props & EnhancedProps) {
Expand Down Expand Up @@ -223,7 +224,7 @@ export class UnconnectedReferenceArrayInputController extends Component<
}
};

fetchReferences = (props = this.props) => {
fetchReferences = (props = this.props, isInitialCall = false) => {
const { crudGetMany, input, reference } = props;
const ids = input.value;
if (ids) {
Expand All @@ -232,7 +233,8 @@ export class UnconnectedReferenceArrayInputController extends Component<
'The value of ReferenceArrayInput should be an array'
);
}
crudGetMany(reference, ids);
const idsToFetch = isInitialCall ? ids : ids.filter(id => !this.props.input.value.includes(id))
crudGetMany(reference, idsToFetch);
}
};

Expand All @@ -255,9 +257,9 @@ export class UnconnectedReferenceArrayInputController extends Component<
);
};

fetchReferencesAndOptions(nextProps) {
this.fetchReferences(nextProps);
this.fetchOptions(nextProps);
fetchReferencesAndOptions(props = this.props) {
this.fetchReferences(props);
this.fetchOptions(props);
}

render() {
Expand Down

0 comments on commit 86e7bfa

Please sign in to comment.