From 9b9bda1fb419373e1f466e3552002fddadbd4b73 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 30 Jun 2021 19:37:03 +0100 Subject: [PATCH] Add error handling to builder preview and loading indicator --- packages/builder/assets/error.svg | 34 ++++++++++ .../AppPreview/CurrentItemPreview.svelte | 62 ++++++++++++++++++- .../design/AppPreview/iframeTemplate.js | 18 ++++-- .../client/src/components/ClientApp.svelte | 3 + packages/client/src/store/builder.js | 5 +- 5 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 packages/builder/assets/error.svg diff --git a/packages/builder/assets/error.svg b/packages/builder/assets/error.svg new file mode 100644 index 0000000000..4cc1d753c9 --- /dev/null +++ b/packages/builder/assets/error.svg @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte index 9b461644cc..0cb58ebdf7 100644 --- a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte +++ b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte @@ -5,12 +5,16 @@ import { Screen } from "builderStore/store/screenTemplates/utils/Screen" import { FrontendTypes } from "constants" import ConfirmDialog from "components/common/ConfirmDialog.svelte" + import { ProgressCircle, Layout, Heading, Body } from "@budibase/bbui" + import ErrorSVG from "assets/error.svg?raw" let iframe let layout let screen let confirmDeleteDialog let idToDelete + let loading = true + let error // Create screen slot placeholder for use when a page is selected rather // than a screen @@ -69,11 +73,21 @@ onMount(() => { // Initialise the app when mounted iframe.contentWindow.addEventListener( - "bb-ready", + "ready", () => refreshContent(strippedJson), { once: true } ) + // Catch any app errors + iframe.contentWindow.addEventListener( + "error", + event => { + loading = false + error = event.detail || "An unknown error occurred" + }, + { once: true } + ) + // Add listener for events sent by cliebt library in preview iframe.contentWindow.addEventListener("bb-event", event => { const { type, data } = event.detail @@ -84,8 +98,10 @@ } else if (type === "delete-component" && data.id) { idToDelete = data.id confirmDeleteDialog.show() + } else if (type === "preview-loaded") { + loading = false } else { - console.log(data) + console.warning(`Client sent unknown event type: ${type}`) } }) }) @@ -100,11 +116,25 @@
+ {#if loading} +
+ +
+ {:else if error} +
+ + {@html ErrorSVG} + App preview failed to load + {error} + +
+ {/if}