This commit is contained in:
Martin McKeaveney 2021-10-01 13:00:31 +01:00
commit 3fa29228af
4 changed files with 11 additions and 76 deletions

View File

@ -1,21 +1,10 @@
<script> <script>
import { onMount, onDestroy } from "svelte"
import { Button, Modal, notifications, ModalContent } from "@budibase/bbui" import { Button, Modal, notifications, ModalContent } from "@budibase/bbui"
import api from "builderStore/api" import api from "builderStore/api"
import analytics, { Events } from "analytics" import analytics, { Events } from "analytics"
import { store } from "builderStore" import { store } from "builderStore"
const DeploymentStatus = {
SUCCESS: "SUCCESS",
PENDING: "PENDING",
FAILURE: "FAILURE",
}
const POLL_INTERVAL = 10000
let feedbackModal let feedbackModal
let deployments = []
let poll
let publishModal let publishModal
async function deployApp() { async function deployApp() {
@ -34,62 +23,6 @@
notifications.error(`Error publishing app: ${err}`) notifications.error(`Error publishing app: ${err}`)
} }
} }
async function fetchDeployments() {
try {
const response = await api.get(`/api/deployments`)
const json = await response.json()
if (deployments.length > 0) {
checkIncomingDeploymentStatus(deployments, json)
}
deployments = json
} catch (err) {
console.error(err)
clearInterval(poll)
notifications.error(
"Error fetching deployment history. Please try again."
)
}
}
// Required to check any updated deployment statuses between polls
function checkIncomingDeploymentStatus(current, incoming) {
for (let incomingDeployment of incoming) {
if (
incomingDeployment.status === DeploymentStatus.FAILURE ||
incomingDeployment.status === DeploymentStatus.SUCCESS
) {
const currentDeployment = current.find(
deployment => deployment._id === incomingDeployment._id
)
// We have just been notified of an ongoing deployments status change
if (
!currentDeployment ||
currentDeployment.status === DeploymentStatus.PENDING
) {
if (incomingDeployment.status === DeploymentStatus.FAILURE) {
notifications.error(incomingDeployment.err)
} else {
notifications.send(
"Published to Production.",
"success",
"CheckmarkCircle"
)
}
}
}
}
}
onMount(() => {
fetchDeployments()
poll = setInterval(fetchDeployments, POLL_INTERVAL)
})
onDestroy(() => clearInterval(poll))
</script> </script>
<Button secondary on:click={publishModal.show}>Publish</Button> <Button secondary on:click={publishModal.show}>Publish</Button>

View File

@ -4,9 +4,6 @@
import { onMount } from "svelte" import { onMount } from "svelte"
let loaded = false let loaded = false
// don't react to these
let cloud = $admin.cloud
let shouldRedirect = !cloud || $admin.disableAccountPortal
$: multiTenancyEnabled = $admin.multiTenancy $: multiTenancyEnabled = $admin.multiTenancy
$: hasAdminUser = $admin?.checklist?.adminUser?.checked $: hasAdminUser = $admin?.checklist?.adminUser?.checked
@ -14,6 +11,8 @@
$: cloud = $admin.cloud $: cloud = $admin.cloud
$: user = $auth.user $: user = $auth.user
$: useAccountPortal = cloud && !$admin.disableAccountPortal
const validateTenantId = async () => { const validateTenantId = async () => {
// set the tenant from the url in the cloud // set the tenant from the url in the cloud
const tenantId = window.location.host.split(".")[0] const tenantId = window.location.host.split(".")[0]
@ -41,12 +40,11 @@
}) })
$: { $: {
// We should never see the org or admin user creation screens in the cloud
const apiReady = $admin.loaded && $auth.loaded const apiReady = $admin.loaded && $auth.loaded
// if tenant is not set go to it // if tenant is not set go to it
if ( if (
loaded && loaded &&
shouldRedirect && !useAccountPortal &&
apiReady && apiReady &&
multiTenancyEnabled && multiTenancyEnabled &&
!tenantSet !tenantSet
@ -54,7 +52,7 @@
$redirect("./auth/org") $redirect("./auth/org")
} }
// Force creation of an admin user if one doesn't exist // Force creation of an admin user if one doesn't exist
else if (loaded && shouldRedirect && apiReady && !hasAdminUser) { else if (loaded && !useAccountPortal && apiReady && !hasAdminUser) {
$redirect("./admin") $redirect("./admin")
} }
// Redirect to log in at any time if the user isn't authenticated // Redirect to log in at any time if the user isn't authenticated

View File

@ -5,8 +5,11 @@
let loaded = false let loaded = false
$: cloud = $admin.cloud
$: useAccountPortal = cloud && !$admin.disableAccountPortal
onMount(() => { onMount(() => {
if ($admin?.checklist?.adminUser.checked) { if ($admin?.checklist?.adminUser.checked || useAccountPortal) {
$redirect("../") $redirect("../")
} else { } else {
loaded = true loaded = true

View File

@ -9,7 +9,8 @@
let tenantId = get(auth).tenantSet ? get(auth).tenantId : "" let tenantId = get(auth).tenantSet ? get(auth).tenantId : ""
$: multiTenancyEnabled = $admin.multiTenancy $: multiTenancyEnabled = $admin.multiTenancy
$: cloud = $admin.cloud $: cloud = $admin.cloud
$: disableAccountPortal = $admin.disableAccountPortal
$: useAccountPortal = cloud && !$admin.disableAccountPortal
async function setOrg() { async function setOrg() {
if (tenantId == null || tenantId === "") { if (tenantId == null || tenantId === "") {
@ -27,7 +28,7 @@
onMount(async () => { onMount(async () => {
await auth.checkQueryString() await auth.checkQueryString()
if (!multiTenancyEnabled || (cloud && !disableAccountPortal)) { if (!multiTenancyEnabled || useAccountPortal) {
$goto("../") $goto("../")
} else { } else {
admin.unload() admin.unload()