From b363a3d898d76769c9182e2380d2ec49e486f2a1 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 3 Mar 2022 09:07:53 +0400 Subject: [PATCH 1/4] Image: Display errors after failed upload --- packages/block-library/src/image/edit.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index bcef8caefe829..3952fda137219 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -171,6 +171,12 @@ export function ImageEdit( { function onUploadError( message ) { noticeOperations.removeAllNotices(); noticeOperations.createErrorNotice( message ); + setAttributes( { + src: undefined, + id: undefined, + url: undefined, + } ); + setTemporaryURL( undefined ); } function onSelectImage( media ) { @@ -287,7 +293,7 @@ export function ImageEdit( { } ); } - let isTemp = isTemporaryImage( id, url ); + const isTemp = isTemporaryImage( id, url ); // Upload a temporary image on mount. useEffect( () => { @@ -304,15 +310,7 @@ export function ImageEdit( { onSelectImage( img ); }, allowedTypes: ALLOWED_MEDIA_TYPES, - onError: ( message ) => { - isTemp = false; - noticeOperations.createErrorNotice( message ); - setAttributes( { - src: undefined, - id: undefined, - url: undefined, - } ); - }, + onError: onUploadError, } ); } }, [] ); From 8eee50522a6a70f0e793478396d66060647f089f Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 4 Mar 2022 09:03:26 +0400 Subject: [PATCH 2/4] Set isTemp to false on error --- packages/block-library/src/image/edit.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 3952fda137219..96ef7c29943c4 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -293,7 +293,7 @@ export function ImageEdit( { } ); } - const isTemp = isTemporaryImage( id, url ); + let isTemp = isTemporaryImage( id, url ); // Upload a temporary image on mount. useEffect( () => { @@ -310,7 +310,10 @@ export function ImageEdit( { onSelectImage( img ); }, allowedTypes: ALLOWED_MEDIA_TYPES, - onError: onUploadError, + onError: ( message ) => { + isTemp = false; + onUploadError( message ); + }, } ); } }, [] ); From de17283b98005198a3337423196f133ed4237b25 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 4 Mar 2022 12:50:32 +0400 Subject: [PATCH 3/4] Only reset temp URL state --- packages/block-library/src/image/edit.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 96ef7c29943c4..f2f874137aaea 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -171,11 +171,6 @@ export function ImageEdit( { function onUploadError( message ) { noticeOperations.removeAllNotices(); noticeOperations.createErrorNotice( message ); - setAttributes( { - src: undefined, - id: undefined, - url: undefined, - } ); setTemporaryURL( undefined ); } From 1f262139c6b964d4cb9d57c2be5a84d7403366ae Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 7 Mar 2022 11:01:21 +0400 Subject: [PATCH 4/4] Reset attributes on error --- packages/block-library/src/image/edit.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index f2f874137aaea..96ef7c29943c4 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -171,6 +171,11 @@ export function ImageEdit( { function onUploadError( message ) { noticeOperations.removeAllNotices(); noticeOperations.createErrorNotice( message ); + setAttributes( { + src: undefined, + id: undefined, + url: undefined, + } ); setTemporaryURL( undefined ); }