Merge pull request #3543 from Budibase/martin/misc-tasks

Martin/misc tasks
This commit is contained in:
Martin McKeaveney 2021-11-26 11:58:40 +01:00 committed by GitHub
commit c7bf4770a5
6 changed files with 126 additions and 808 deletions

View File

@ -12,7 +12,7 @@ context("Create a automation", () => {
cy.get("[data-cy='new-screen'] > .spectrum-Icon").click() cy.get("[data-cy='new-screen'] > .spectrum-Icon").click()
cy.get(".modal-inner-wrapper").within(() => { cy.get(".modal-inner-wrapper").within(() => {
cy.get("input").type("Add Row") cy.get("input").type("Add Row")
cy.contains("Row Created").click() cy.contains("Row Created").click({ force: true })
cy.wait(500) cy.wait(500)
cy.get(".spectrum-Button--cta").click() cy.get(".spectrum-Button--cta").click()
}) })

View File

@ -3,7 +3,14 @@
import { database } from "stores/backend" import { database } from "stores/backend"
import { automationStore } from "builderStore" import { automationStore } from "builderStore"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import { Input, ModalContent, Layout, Body, Icon } from "@budibase/bbui" import {
Input,
InlineAlert,
ModalContent,
Layout,
Body,
Icon,
} from "@budibase/bbui"
import analytics, { Events } from "analytics" import analytics, { Events } from "analytics"
let name let name
@ -56,6 +63,10 @@
onConfirm={createAutomation} onConfirm={createAutomation}
disabled={!selectedTrigger || !name} disabled={!selectedTrigger || !name}
> >
<InlineAlert
header="You must publish your app to activate your automations."
message="To test your automation before publishing, you can use the 'Run Test' functionality on the next screen."
/>
<Body size="XS" <Body size="XS"
>Please name your automation, then select a trigger. Every automation must >Please name your automation, then select a trigger. Every automation must
start with a trigger. start with a trigger.

View File

@ -32,31 +32,22 @@
import { onMount } from "svelte" import { onMount } from "svelte"
export let query export let query
export let fields = []
let fields = query.schema ? schemaToFields(query.schema) : []
let parameters let parameters
let data = [] let data = []
let roleId let roleId
const transformerDocs = const transformerDocs =
"https://docs.budibase.com/building-apps/data/transformers" "https://docs.budibase.com/building-apps/data/transformers"
const typeOptions = [ const typeOptions = [
{ label: "Text", value: "STRING" }, { label: "Text", value: "string" },
{ label: "Number", value: "NUMBER" }, { label: "Number", value: "number" },
{ label: "Boolean", value: "BOOLEAN" }, { label: "Boolean", value: "boolean" },
{ label: "Datetime", value: "DATETIME" }, { label: "Datetime", value: "datetime" },
] ]
$: datasource = $datasources.list.find(ds => ds._id === query.datasourceId) $: datasource = $datasources.list.find(ds => ds._id === query.datasourceId)
$: query.schema = fields.reduce( $: query.schema = fieldsToSchema(fields)
(acc, next) => ({
...acc,
[next.name]: {
name: next.name,
type: "string",
},
}),
{}
)
$: datasourceType = datasource?.source $: datasourceType = datasource?.source
$: integrationInfo = $integrations[datasourceType] $: integrationInfo = $integrations[datasourceType]
$: queryConfig = integrationInfo?.query $: queryConfig = integrationInfo?.query
@ -135,7 +126,7 @@
// unique fields returned by the server // unique fields returned by the server
fields = json.schemaFields.map(field => ({ fields = json.schemaFields.map(field => ({
name: field, name: field,
type: "STRING", type: "string",
})) }))
} catch (err) { } catch (err) {
notifications.error(`Query Error: ${err.message}`) notifications.error(`Query Error: ${err.message}`)
@ -155,6 +146,26 @@
} }
} }
function schemaToFields(schema) {
return Object.keys(schema).map(key => ({
name: key,
type: query.schema[key].type,
}))
}
function fieldsToSchema(fieldsToConvert) {
return fieldsToConvert.reduce(
(acc, next) => ({
...acc,
[next.name]: {
name: next.name,
type: next.type,
},
}),
{}
)
}
onMount(async () => { onMount(async () => {
if (!query || !query._id) { if (!query || !query._id) {
roleId = Roles.BASIC roleId = Roles.BASIC

View File

@ -83,12 +83,11 @@
} }
async function createNewApp() { async function createNewApp() {
const letTemplateToUse = const templateToUse = Object.keys(template).length === 0 ? null : template
Object.keys(template).length === 0 ? null : template
submitting = true submitting = true
// Check a template exists if we are important // Check a template exists if we are important
if (letTemplateToUse?.fromFile && !$values.file) { if (templateToUse?.fromFile && !$values.file) {
$errors.file = "Please choose a file to import" $errors.file = "Please choose a file to import"
valid = false valid = false
submitting = false submitting = false
@ -99,10 +98,10 @@
// Create form data to create app // Create form data to create app
let data = new FormData() let data = new FormData()
data.append("name", $values.name.trim()) data.append("name", $values.name.trim())
data.append("useTemplate", letTemplateToUse != null) data.append("useTemplate", templateToUse != null)
if (letTemplateToUse) { if (templateToUse) {
data.append("templateName", letTemplateToUse.name) data.append("templateName", templateToUse.name)
data.append("templateKey", letTemplateToUse.key) data.append("templateKey", templateToUse.key)
data.append("templateFile", $values.file) data.append("templateFile", $values.file)
} }
@ -116,7 +115,7 @@
analytics.captureEvent(Events.APP.CREATED, { analytics.captureEvent(Events.APP.CREATED, {
name: $values.name, name: $values.name,
appId: appJson.instance._id, appId: appJson.instance._id,
letTemplateToUse, templateToUse,
}) })
// Select Correct Application/DB in prep for creating user // Select Correct Application/DB in prep for creating user

View File

@ -13,9 +13,11 @@
notifications, notifications,
Search, Search,
} from "@budibase/bbui" } from "@budibase/bbui"
import Spinner from "components/common/Spinner.svelte"
import CreateAppModal from "components/start/CreateAppModal.svelte" import CreateAppModal from "components/start/CreateAppModal.svelte"
import UpdateAppModal from "components/start/UpdateAppModal.svelte" import UpdateAppModal from "components/start/UpdateAppModal.svelte"
import { del } from "builderStore/api" import { store, automationStore } from "builderStore"
import api, { del, post, get } from "builderStore/api"
import { onMount } from "svelte" import { onMount } from "svelte"
import { apps, auth, admin } from "stores/portal" import { apps, auth, admin } from "stores/portal"
import download from "downloadjs" import download from "downloadjs"
@ -24,6 +26,7 @@
import AppCard from "components/start/AppCard.svelte" import AppCard from "components/start/AppCard.svelte"
import AppRow from "components/start/AppRow.svelte" import AppRow from "components/start/AppRow.svelte"
import { AppStatus } from "constants" import { AppStatus } from "constants"
import analytics, { Events } from "analytics"
let layout = "grid" let layout = "grid"
let sortBy = "name" let sortBy = "name"
@ -38,6 +41,7 @@
let searchTerm = "" let searchTerm = ""
let cloud = $admin.cloud let cloud = $admin.cloud
let appName = "" let appName = ""
let creatingFromTemplate = false
$: enrichedApps = enrichApps($apps, $auth.user, sortBy) $: enrichedApps = enrichApps($apps, $auth.user, sortBy)
$: filteredApps = enrichedApps.filter(app => $: filteredApps = enrichedApps.filter(app =>
@ -92,6 +96,62 @@
creatingApp = true creatingApp = true
} }
const autoCreateApp = async () => {
try {
// Auto name app if has same name
let appName = template.key
const appsWithSameName = $apps.filter(app =>
app.name?.startsWith(appName)
)
appName = `${appName}-${appsWithSameName.length + 1}`
// Create form data to create app
let data = new FormData()
data.append("name", appName)
data.append("useTemplate", true)
data.append("templateKey", template.key)
// Create App
const appResp = await post("/api/applications", data, {})
const appJson = await appResp.json()
if (!appResp.ok) {
throw new Error(appJson.message)
}
analytics.captureEvent(Events.APP.CREATED, {
name: appName,
appId: appJson.instance._id,
template,
fromTemplateMarketplace: true,
})
// Select Correct Application/DB in prep for creating user
const applicationPkg = await get(
`/api/applications/${appJson.instance._id}/appPackage`
)
const pkg = await applicationPkg.json()
if (applicationPkg.ok) {
await store.actions.initialise(pkg)
await automationStore.actions.fetch()
// update checklist - incase first app
await admin.init()
} else {
throw new Error(pkg)
}
// Create user
const userResp = await api.post(`/api/users/metadata/self`, {
roleId: "BASIC",
})
await userResp.json()
await auth.setInitInfo({})
$goto(`/builder/app/${appJson.instance._id}`)
} catch (error) {
console.error(error)
notifications.error(error)
}
}
const stopAppCreation = () => { const stopAppCreation = () => {
template = null template = null
creatingApp = false creatingApp = false
@ -194,7 +254,7 @@
template = { template = {
key: templateKey, key: templateKey,
} }
initiateAppCreation() autoCreateApp()
} else { } else {
notifications.error("Your Template URL is invalid. Please try another.") notifications.error("Your Template URL is invalid. Please try another.")
} }
@ -202,12 +262,14 @@
onMount(async () => { onMount(async () => {
await apps.load() await apps.load()
loaded = true
// if the portal is loaded from an external URL with a template param // if the portal is loaded from an external URL with a template param
const initInfo = await auth.getInitInfo() const initInfo = await auth.getInitInfo()
if (initInfo.init_template) { if (initInfo.init_template) {
creatingFromTemplate = true
createAppFromTemplateUrl(initInfo.init_template) createAppFromTemplateUrl(initInfo.init_template)
return
} }
loaded = true
}) })
</script> </script>
@ -285,6 +347,12 @@
</Modal> </Modal>
</div> </div>
{/if} {/if}
{#if creatingFromTemplate}
<div class="empty-wrapper">
<p>Creating your Budibase app from your selected template...</p>
<Spinner size="10" />
</div>
{/if}
</Page> </Page>
<Modal <Modal
bind:this={creationModal} bind:this={creationModal}

File diff suppressed because it is too large Load Diff