Skip to content

Commit

Permalink
Improve code clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Feb 2, 2021
1 parent d024e9a commit aec3e93
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/media-utils/src/components/media-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,13 @@ class MediaUpload extends Component {
onOpen() {
this.updateCollection();

// For a media uploader that selects only a single item (e.g. the image
// block ), `this.props.value` is a number that represents the `id` of
// the media. For galleries, the value is an array of ids. This early
// return statement should handle both when no media is present.
if (
! this.props.value ||
( this.props.gallery && this.props.value?.length )
) {
// Handle both this.props.value being either (number[]) multiple ids
// (for galleries) or a (number) singular id (e.g. image block).
const hasMedia = Array.isArray( this.props.value )
? !! this.props.value?.length
: !! this.props.value;

if ( ! hasMedia ) {
return;
}

Expand Down

0 comments on commit aec3e93

Please sign in to comment.