From eded9a301c9ee1a574cdfb0dd369fa2877d56539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souk=C3=A9ina=20Bojabza?= Date: Mon, 7 Aug 2023 16:36:36 +0000 Subject: [PATCH] [FIX] web_editor, *: correctly set the ProgressBar component props *: web_unsplash Before this commit, if we were in debug mode, when we tried to replace or add an image, a traceback appeared when selecting an Unsplash image for the first time or when uploading an image of size 0 (also for the first time). Note that once the traceback was closed, it did not reappear until the page was refreshed, but the progress bar was not displayed anymore. It happened because in debug mode, there is a validation of the different owl components props and some props of the `ProgressBar` component were not correctly set when adding Unsplash images or empty image files, causing the props validation to fail. Those props definition were incorrectly added with [1]. The traceback was not reappearing because the `UploadProgressToast` component (= the parent of `ProgressBar`) has been destroyed and so the props validation was not done anymore since the components were not there. This commit fixes these issues by correctly setting the `ProgressBar` props and by adding default props, in order for them to always have a value when omitted. Steps to reproduce: - Activate the debug mode. - In edit mode, drop the Text-Image snippet. - Double-click on the image to replace it. - Type something in the search bar and select an Unsplash image or upload an empty image file. => A traceback appears. [1]: https://github.com/odoo/odoo/commit/886f3de768b647f4b402c97098abf274d6258f75 opw-3413299 closes odoo/odoo#132377 X-original-commit: 425dfb07f21288caf56bceea3a86e0b7ecac4a91 Signed-off-by: Quentin Smetz (qsm) --- .../upload_progress_toast.js | 17 ++++++++++++----- .../upload_progress_toast/upload_service.js | 6 +----- .../components/media_dialog/image_selector.js | 2 -- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/addons/web_editor/static/src/components/upload_progress_toast/upload_progress_toast.js b/addons/web_editor/static/src/components/upload_progress_toast/upload_progress_toast.js index cb23e0943b4..5625a1c21e7 100644 --- a/addons/web_editor/static/src/components/upload_progress_toast/upload_progress_toast.js +++ b/addons/web_editor/static/src/components/upload_progress_toast/upload_progress_toast.js @@ -10,12 +10,19 @@ export class ProgressBar extends Component { } ProgressBar.template = 'web_editor.ProgressBar'; ProgressBar.props = { - progress: Number, - hasError: Boolean, - uploaded: Boolean, + progress: { type: Number, optional: true }, + hasError: { type: Boolean, optional: true }, + uploaded: { type: Boolean, optional: true }, name: String, - size: String, - errorMessage: String, + size: { type: String, optional: true }, + errorMessage: { type: String, optional: true }, +}; +ProgressBar.defaultProps = { + progress: 0, + hasError: false, + uploaded: false, + size: "", + errorMessage: "", }; export class UploadProgressToast extends Component { diff --git a/addons/web_editor/static/src/components/upload_progress_toast/upload_service.js b/addons/web_editor/static/src/components/upload_progress_toast/upload_service.js index 8aa461caf4b..5dcf3dc82cd 100644 --- a/addons/web_editor/static/src/components/upload_progress_toast/upload_service.js +++ b/addons/web_editor/static/src/components/upload_progress_toast/upload_service.js @@ -74,7 +74,7 @@ export const uploadService = { return null; } if (!fileSize) { - fileSize = null; + fileSize = ""; } else { fileSize = humanNumber(fileSize) + "B"; } @@ -87,10 +87,6 @@ export const uploadService = { id, name: file.name, size: fileSize, - progress: 0, - hasError: false, - uploaded: false, - errorMessage: '', }); } diff --git a/addons/web_unsplash/static/src/components/media_dialog/image_selector.js b/addons/web_unsplash/static/src/components/media_dialog/image_selector.js index e716dc7afef..cf1ad7b29cb 100644 --- a/addons/web_unsplash/static/src/components/media_dialog/image_selector.js +++ b/addons/web_unsplash/static/src/components/media_dialog/image_selector.js @@ -246,8 +246,6 @@ patch(uploadService, { name: records.length > 1 ? _t("Uploading %s '%s' images.", records.length, records[0].query) : _t("Uploading '%s' image.", records[0].query), - size: null, - progress: 0, }); try {