Add more builder API refactor updates

This commit is contained in:
Andrew Kingston 2022-01-20 19:53:55 +00:00
parent 6319760b8c
commit e6cddcca3e
3 changed files with 22 additions and 29 deletions

View File

@ -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")
}
}

View File

@ -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}`)
}
}
</script>

View File

@ -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",
})
},
})