Merge pull request #3300 from Budibase/fix/templates

Fix/templates
This commit is contained in:
Martin McKeaveney 2021-11-10 15:19:26 +01:00 committed by GitHub
commit 9f7aba3f19
11 changed files with 79 additions and 29 deletions

View File

@ -11,6 +11,7 @@ it("should rename an unpublished application", () => {
renameApp(appRename)
cy.searchForApplication(appRename)
cy.get(".appGrid").find(".wrapper").should("have.length", 1)
cy.deleteApp(appRename)
})
xit("Should rename a published application", () => {

View File

@ -43,24 +43,26 @@ Cypress.Commands.add("createApp", name => {
})
})
Cypress.Commands.add("deleteApp", () => {
Cypress.Commands.add("deleteApp", appName => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.wait(1000)
cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`)
.its("body")
.then(val => {
console.log(val)
if (val.length > 0) {
cy.get(".title > :nth-child(3) > .spectrum-Icon").click()
cy.contains("Delete").click()
cy.get(".spectrum-Modal").within(() => {
cy.get("input").type(appName)
cy.get(".spectrum-Button--warning").click()
})
}
})
})
Cypress.Commands.add("createTestApp", () => {
const appName = "Cypress Tests"
cy.deleteApp()
cy.deleteApp(appName)
cy.createApp(appName, "This app is used for Cypress testing.")
})

View File

@ -8,6 +8,7 @@
export let onOk = undefined
export let onCancel = undefined
export let warning = true
export let disabled
let modal
@ -26,6 +27,7 @@
confirmText={okText}
{cancelText}
{warning}
{disabled}
>
<Body size="S">
{body}

View File

@ -1,9 +1,16 @@
<script>
import { Icon, Modal, notifications, ModalContent } from "@budibase/bbui"
import {
Icon,
Input,
Modal,
notifications,
ModalContent,
} from "@budibase/bbui"
import { store } from "builderStore"
import api from "builderStore/api"
let revertModal
let appName
$: appId = $store.appId
@ -33,10 +40,17 @@
<Icon name="Revert" hoverable on:click={revertModal.show} />
<Modal bind:this={revertModal}>
<ModalContent title="Revert Changes" confirmText="Revert" onConfirm={revert}>
<ModalContent
title="Revert Changes"
confirmText="Revert"
onConfirm={revert}
disabled={appName !== $store.name}
>
<span
>The changes you have made will be deleted and the application reverted
back to its production state.</span
>
<span>Please enter your app name to continue.</span>
<Input bind:value={appName} />
</ModalContent>
</Modal>

View File

@ -69,6 +69,7 @@
theme: $store.theme,
customTheme: $store.customTheme,
previewDevice: $store.previewDevice,
messagePassing: $store.clientFeatures.messagePassing
}
// Saving pages and screens to the DB causes them to have _revs.
@ -94,12 +95,12 @@
const handlers = {
[MessageTypes.READY]: () => {
// Initialise the app when mounted
// Display preview immediately if the intelligent loading feature
// is not supported
if ($store.clientFeatures.messagePassing) {
if (!loading) return
}
// Display preview immediately if the intelligent loading feature
// is not supported
if (!$store.clientFeatures.intelligentLoading) {
loading = false
}
@ -118,9 +119,8 @@
}
onMount(() => {
if ($store.clientFeatures.messagePassing) {
window.addEventListener("message", receiveMessage)
} else {
if (!$store.clientFeatures.messagePassing) {
// Legacy - remove in later versions of BB
iframe.contentWindow.addEventListener("ready", () => {
receiveMessage({ data: { type: MessageTypes.READY }})
@ -137,9 +137,8 @@
// Remove all iframe event listeners on component destroy
onDestroy(() => {
if (iframe.contentWindow) {
if ($store.clientFeatures.messagePassing) {
window.removeEventListener("message", receiveMessage)
} else {
if (!$store.clientFeatures.messagePassing) {
// Legacy - remove in later versions of BB
iframe.contentWindow.removeEventListener("bb-event", handleBudibaseEvent)
iframe.contentWindow.removeEventListener("keydown", handleKeydownEvent)

View File

@ -97,6 +97,7 @@ export default `
window.addEventListener("keydown", evt => {
window.parent.postMessage({ type: "keydown", key: event.key })
})
window.parent.postMessage({ type: "ready" })
</script>
</head>

View File

@ -157,6 +157,11 @@
}
return title
}
async function onCancel() {
template = null
await auth.setInitInfo({})
}
</script>
{#if showTemplateSelection}
@ -186,7 +191,7 @@
title={getModalTitle()}
confirmText={template?.fromFile ? "Import app" : "Create app"}
onConfirm={createNewApp}
onCancel={inline ? () => (template = null) : null}
onCancel={inline ? onCancel : null}
cancelText={inline ? "Back" : undefined}
showCloseIcon={!inline}
disabled={!valid}

View File

@ -28,9 +28,13 @@
}
if (user && user.tenantId) {
// no tenant in the url - send to account portal to fix this
if (!urlTenantId) {
window.location.href = $admin.accountPortalUrl
// redirect to correct tenantId subdomain
if (!window.location.host.includes("localhost")) {
let redirectUrl = window.location.href
redirectUrl = redirectUrl.replace("://", `://${user.tenantId}.`)
window.location.href = redirectUrl
}
return
}

View File

@ -6,6 +6,7 @@
ActionButton,
ActionGroup,
ButtonGroup,
Input,
Select,
Modal,
Page,
@ -36,6 +37,7 @@
let loaded = false
let searchTerm = ""
let cloud = $admin.cloud
let appName = ""
$: enrichedApps = enrichApps($apps, $auth.user, sortBy)
$: filteredApps = enrichedApps.filter(app =>
@ -296,8 +298,12 @@
title="Confirm deletion"
okText="Delete app"
onOk={confirmDeleteApp}
disabled={appName !== selectedApp?.name}
>
Are you sure you want to delete the app <b>{selectedApp?.name}</b>?
<p>Please enter the app name below to confirm.</p>
<Input bind:value={appName} data-cy="delete-app-confirmation" />
</ConfirmDialog>
<ConfirmDialog
bind:this={unpublishModal}

View File

@ -80,16 +80,30 @@ export function createAuthStore() {
}
}
async function setInitInfo(info) {
await api.post(`/api/global/auth/init`, info)
auth.update(store => {
store.initInfo = info
return store
})
return info
}
async function getInitInfo() {
const response = await api.get(`/api/global/auth/init`)
const json = response.json()
auth.update(store => {
store.initInfo = json
return store
})
return json
}
return {
subscribe: store.subscribe,
setOrganisation: setOrganisation,
getInitInfo: async () => {
const response = await api.get(`/api/global/auth/init`)
return await response.json()
},
setInitInfo: async info => {
await api.post(`/api/global/auth/init`, info)
},
setOrganisation,
getInitInfo,
setInitInfo,
checkQueryString: async () => {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("tenantId")) {
@ -129,6 +143,7 @@ export function createAuthStore() {
throw "Unable to create logout"
}
await response.json()
await setInitInfo({})
setUser(null)
},
updateSelf: async fields => {

View File

@ -323,7 +323,7 @@ exports.delete = async ctx => {
ctx.body = result
}
exports.sync = async ctx => {
exports.sync = async (ctx, next) => {
const appId = ctx.params.appId
if (!isDevAppID(appId)) {
ctx.throw(400, "This action cannot be performed for production apps")
@ -336,10 +336,11 @@ exports.sync = async ctx => {
if (info.error) throw info.error
} catch (err) {
// the database doesn't exist. Don't replicate
ctx.status = 200
ctx.body = {
message: "App sync not required, app not deployed.",
}
return
return next()
}
const replication = new Replication({