Skip to content

Commit

Permalink
Fix ArrayWidget to support static supermodel vocabulary (#1333)
Browse files Browse the repository at this point in the history
* Fix ArrayWidget to support static supermodel vocabulary

* Update changelog

* Refactor to use optional chaining

* Make prettier
  • Loading branch information
datakurre authored Apr 6, 2020
1 parent f346b14 commit 883865d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Bugfix

- Fix ArrayWidget to support static supermodel vocabulary @datakurre

### Internal

- Improve the i18n script, only write the pot file if it's really different
Expand Down
16 changes: 12 additions & 4 deletions src/components/manage/Widgets/ArrayWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class ArrayWidget extends Component {
required: PropTypes.bool,
error: PropTypes.arrayOf(PropTypes.string),
getVocabulary: PropTypes.func.isRequired,
choices: PropTypes.arrayOf(PropTypes.object),
choices: PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
),
loading: PropTypes.bool,
items: PropTypes.shape({
vocabulary: PropTypes.object,
Expand Down Expand Up @@ -124,7 +126,7 @@ class ArrayWidget extends Component {
* @returns {undefined}
*/
componentDidMount() {
if (this.vocabBaseUrl) {
if (!this.props.items?.choices && this.vocabBaseUrl) {
this.props.getVocabulary(this.vocabBaseUrl);
}
}
Expand Down Expand Up @@ -201,7 +203,7 @@ class ArrayWidget extends Component {
</div>
</Grid.Column>
<Grid.Column width="8">
{this.vocabBaseUrl ? (
{!this.props.items?.choices && this.vocabBaseUrl ? (
<AsyncPaginate
className="react-select-container"
classNamePrefix="react-select"
Expand Down Expand Up @@ -282,7 +284,13 @@ export default compose(
getVocabFromField(props) ||
getVocabFromItems(props);
const vocabState = state.vocabularies[vocabBaseUrl];
if (vocabState) {
// If the schema already has the choices in it, then do not try to get the vocab,
// even if there is one
if (props.items?.choices) {
return {
choices: props.items.choices,
};
} else if (vocabState) {
return {
choices: vocabState.items,
itemsTotal: vocabState.itemsTotal,
Expand Down

0 comments on commit 883865d

Please sign in to comment.