From e8f28113da9b14cb13bf39b81330877fd73f36d0 Mon Sep 17 00:00:00 2001 From: Dean Date: Thu, 15 Jun 2023 10:56:46 +0100 Subject: [PATCH] Merge commit --- .../src/components/deploy/AppActions.svelte | 371 +++++++++++++----- 1 file changed, 271 insertions(+), 100 deletions(-) diff --git a/packages/builder/src/components/deploy/AppActions.svelte b/packages/builder/src/components/deploy/AppActions.svelte index 9813237317..6a381608bd 100644 --- a/packages/builder/src/components/deploy/AppActions.svelte +++ b/packages/builder/src/components/deploy/AppActions.svelte @@ -7,9 +7,15 @@ Body, Button, ActionButton, + Icon, + Link, + Modal, + StatusLight, } from "@budibase/bbui" import RevertModal from "components/deploy/RevertModal.svelte" import VersionModal from "components/deploy/VersionModal.svelte" + import UpdateAppModal from "components/start/UpdateAppModal.svelte" + import { processStringSync } from "@budibase/string-templates" import ConfirmDialog from "components/common/ConfirmDialog.svelte" import analytics, { Events, EventSource } from "analytics" @@ -21,16 +27,22 @@ import { store } from "builderStore" import TourWrap from "components/portal/onboarding/TourWrap.svelte" import { TOUR_STEP_KEYS } from "components/portal/onboarding/tours.js" + import { url, goto } from "@roxi/routify" export let application - let publishPopover - let publishPopoverAnchor let unpublishModal + let updateAppModal + let revertModal + let versionModal - $: filteredApps = $apps.filter( - app => app.devId === application && app.status === "published" - ) + let appActionPopover + let appActionPopoverOpen = false + let appActionPopoverAnchor + + let publishing + + $: filteredApps = $apps.filter(app => app.devId === application) $: selectedApp = filteredApps?.length ? filteredApps[0] : null $: deployments = [] @@ -38,7 +50,30 @@ .filter(deployment => deployment.status === "SUCCESS") .sort((a, b) => a.updatedAt > b.updatedAt) - $: isPublished = selectedApp && latestDeployments?.length > 0 + $: isPublished = + selectedApp?.status === "published" && latestDeployments?.length > 0 + + $: updateAvailable = + $store.upgradableVersion && + $store.version && + $store.upgradableVersion !== $store.version + + const initialiseApp = async () => { + console.log("AppActions :: Reinitialise") + const applicationPkg = await API.fetchAppPackage($store.devId) + await store.actions.initialise(applicationPkg) + } + + const updateDeploymentString = () => { + return deployments?.length + ? processStringSync("Published {{ duration time 'millisecond' }} ago", { + time: + new Date().getTime() - new Date(deployments[0].updatedAt).getTime(), + }) + : "" + } + + $: deploymentString = updateDeploymentString(deployments) const reviewPendingDeployments = (deployments, newDeployments) => { if (deployments.length > 0) { @@ -77,11 +112,35 @@ } } + async function publishApp() { + try { + publishing = true + + let published = await API.publishAppChanges($store.appId) + + notifications.send("App published", { + type: "success", + icon: "GlobeCheck", + }) + + await completePublish() + } catch (error) { + analytics.captureException(error) + notifications.error("Error publishing app") + } + publishing = false + } + const unpublishApp = () => { - publishPopover.hide() + appActionPopover.hide() unpublishModal.show() } + const revertApp = () => { + appActionPopover.hide() + revertModal.show() + } + const confirmUnpublishApp = async () => { if (!application || !isPublished) { //confirm the app has loaded. @@ -90,7 +149,10 @@ try { await API.unpublishApp(selectedApp.prodId) await apps.load() - notifications.success("App unpublished successfully") + notifications.send("App unpublished", { + type: "success", + icon: "GlobeStrike", + }) } catch (err) { notifications.error("Error unpublishing app") } @@ -116,81 +178,25 @@ {#if $store.hasLock}
-
- -
- - - {#if isPublished} -
-
- + + {#if updateAvailable} +
+
+ + Update
- -
- - Your published app - - - {processStringSync( - "Last published {{ duration time 'millisecond' }} ago", - { - time: - new Date().getTime() - - new Date(latestDeployments[0].updatedAt).getTime(), - } - )} - - -
- - -
-
-
-
{/if} - - {#if !isPublished} - - {/if} - - - + +
{ store.update(state => { state.builderSidePanel = true @@ -198,13 +204,124 @@ }) }} > + Users - - +
+
+ +
+ +
+ + + Preview +
+
+ +
+
+ +
{ + appActionPopover.show() + }} + > + + + + Publish + + + +
+
+ { + appActionPopoverOpen = false + }} + on:open={() => { + appActionPopoverOpen = true + }} + > +
+ + + + { + if (isPublished) { + viewApp() + } else { + appActionPopover.hide() + updateAppModal.show() + } + }} + > + {selectedApp ? `${selectedApp?.url}` : ""} + {#if isPublished} + + {:else} + + {/if} + + + + + + {#if isPublished} + {deploymentString} + + Unpublish + + + Revert + + {:else} + Not published + {/if} + + +
+ {#if $store.hasLock} + + + {/if} +
+
+
+
+
+ Are you sure you want to unpublish the app {selectedApp?.name}? + + + { + await initialiseApp() + }} + /> + + + + {/if} -
- - {#if $store.hasLock} - - {/if} -
-