diff --git a/packages/builder/src/components/deploy/DeploymentHistory.svelte b/packages/builder/src/components/deploy/DeploymentHistory.svelte index f6bbcef4d4..8917161539 100644 --- a/packages/builder/src/components/deploy/DeploymentHistory.svelte +++ b/packages/builder/src/components/deploy/DeploymentHistory.svelte @@ -3,7 +3,7 @@ import Spinner from "components/common/Spinner.svelte" import { slide } from "svelte/transition" import { Heading, Button, Modal, ModalContent } from "@budibase/bbui" - import api from "builderStore/api" + import { API } from "api" import { notifications } from "@budibase/bbui" import CreateWebhookDeploymentModal from "./CreateWebhookDeploymentModal.svelte" import { store, hostingStore } from "builderStore" @@ -63,20 +63,14 @@ async function fetchDeployments() { try { - const response = await api.get(`/api/deployments`) - const json = await response.json() - + const newDeployments = await API.getAppDeployments() if (deployments.length > 0) { - checkIncomingDeploymentStatus(deployments, json) + checkIncomingDeploymentStatus(deployments, newDeployments) } - - deployments = json + deployments = newDeployments } catch (err) { - console.error(err) clearInterval(poll) - notifications.error( - "Error fetching deployment history. Please try again." - ) + notifications.error("Error fetching deployment history") } } diff --git a/packages/builder/src/components/deploy/RevertModal.svelte b/packages/builder/src/components/deploy/RevertModal.svelte index bc2ad0d0aa..4207fcad00 100644 --- a/packages/builder/src/components/deploy/RevertModal.svelte +++ b/packages/builder/src/components/deploy/RevertModal.svelte @@ -7,7 +7,7 @@ ModalContent, } from "@budibase/bbui" import { store } from "builderStore" - import api from "builderStore/api" + import { API } from "api" let revertModal let appName @@ -16,24 +16,14 @@ const revert = async () => { try { - const response = await api.post(`/api/dev/${appId}/revert`) - const json = await response.json() - if (response.status !== 200) throw json.message + await API.revertApp(appId) // Reset frontend state after revert - const applicationPkg = await api.get( - `/api/applications/${appId}/appPackage` - ) - const pkg = await applicationPkg.json() - if (applicationPkg.ok) { - await store.actions.initialise(pkg) - } else { - throw new Error(pkg) - } - - notifications.info("Changes reverted.") - } catch (err) { - notifications.error(`Error reverting changes: ${err}`) + const applicationPkg = await API.fetchAppPackage(appId) + await store.actions.initialise(applicationPkg) + notifications.info("Changes reverted successfully") + } catch (error) { + notifications.error(`Error reverting changes: ${error}`) } } diff --git a/packages/frontend-core/src/api/app.js b/packages/frontend-core/src/api/app.js index 882bd837ef..4edd76d9b1 100644 --- a/packages/frontend-core/src/api/app.js +++ b/packages/frontend-core/src/api/app.js @@ -9,7 +9,7 @@ export const buildAppEndpoints = API => ({ }, /** - * Saves and patches metadata about an app + * Saves and patches metadata about an app. * @param metadata the app metadata to save */ saveAppMetadata: async metadata => { @@ -40,4 +40,13 @@ export const buildAppEndpoints = API => ({ url: `/api/dev/${appId}/revert`, }) }, + + /** + * Gets a list of app deployments. + */ + getAppDeployments: async () => { + return await API.get({ + url: "/api/deployments", + }) + }, })