From 77c089adb647ee473a9e9b064d6153d7ba6b7922 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Mon, 1 Feb 2021 14:50:15 +0800 Subject: [PATCH] Improve code clarity --- .../src/components/media-upload/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/media-utils/src/components/media-upload/index.js b/packages/media-utils/src/components/media-upload/index.js index 9bc9f618bc434..6ef5617e9cad8 100644 --- a/packages/media-utils/src/components/media-upload/index.js +++ b/packages/media-utils/src/components/media-upload/index.js @@ -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; }