1
0
Fork 0
mirror of synced 2024-07-03 13:30:46 +12:00

Add more builder API refactor updates

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

View file

@ -3,7 +3,7 @@
import Spinner from "components/common/Spinner.svelte" import Spinner from "components/common/Spinner.svelte"
import { slide } from "svelte/transition" import { slide } from "svelte/transition"
import { Heading, Button, Modal, ModalContent } from "@budibase/bbui" import { Heading, Button, Modal, ModalContent } from "@budibase/bbui"
import api from "builderStore/api" import { API } from "api"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import CreateWebhookDeploymentModal from "./CreateWebhookDeploymentModal.svelte" import CreateWebhookDeploymentModal from "./CreateWebhookDeploymentModal.svelte"
import { store, hostingStore } from "builderStore" import { store, hostingStore } from "builderStore"
@ -63,20 +63,14 @@
async function fetchDeployments() { async function fetchDeployments() {
try { try {
const response = await api.get(`/api/deployments`) const newDeployments = await API.getAppDeployments()
const json = await response.json()
if (deployments.length > 0) { if (deployments.length > 0) {
checkIncomingDeploymentStatus(deployments, json) checkIncomingDeploymentStatus(deployments, newDeployments)
} }
deployments = newDeployments
deployments = json
} catch (err) { } catch (err) {
console.error(err)
clearInterval(poll) clearInterval(poll)
notifications.error( notifications.error("Error fetching deployment history")
"Error fetching deployment history. Please try again."
)
} }
} }

View file

@ -7,7 +7,7 @@
ModalContent, ModalContent,
} from "@budibase/bbui" } from "@budibase/bbui"
import { store } from "builderStore" import { store } from "builderStore"
import api from "builderStore/api" import { API } from "api"
let revertModal let revertModal
let appName let appName
@ -16,24 +16,14 @@
const revert = async () => { const revert = async () => {
try { try {
const response = await api.post(`/api/dev/${appId}/revert`) await API.revertApp(appId)
const json = await response.json()
if (response.status !== 200) throw json.message
// Reset frontend state after revert // Reset frontend state after revert
const applicationPkg = await api.get( const applicationPkg = await API.fetchAppPackage(appId)
`/api/applications/${appId}/appPackage` await store.actions.initialise(applicationPkg)
) notifications.info("Changes reverted successfully")
const pkg = await applicationPkg.json() } catch (error) {
if (applicationPkg.ok) { notifications.error(`Error reverting changes: ${error}`)
await store.actions.initialise(pkg)
} else {
throw new Error(pkg)
}
notifications.info("Changes reverted.")
} catch (err) {
notifications.error(`Error reverting changes: ${err}`)
} }
} }
</script> </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 * @param metadata the app metadata to save
*/ */
saveAppMetadata: async metadata => { saveAppMetadata: async metadata => {
@ -40,4 +40,13 @@ export const buildAppEndpoints = API => ({
url: `/api/dev/${appId}/revert`, url: `/api/dev/${appId}/revert`,
}) })
}, },
/**
* Gets a list of app deployments.
*/
getAppDeployments: async () => {
return await API.get({
url: "/api/deployments",
})
},
}) })