Merge pull request #3543 from Budibase/martin/misc-tasks
Martin/misc tasks
This commit is contained in:
commit
c7bf4770a5
|
@ -12,7 +12,7 @@ context("Create a automation", () => {
|
|||
cy.get("[data-cy='new-screen'] > .spectrum-Icon").click()
|
||||
cy.get(".modal-inner-wrapper").within(() => {
|
||||
cy.get("input").type("Add Row")
|
||||
cy.contains("Row Created").click()
|
||||
cy.contains("Row Created").click({ force: true })
|
||||
cy.wait(500)
|
||||
cy.get(".spectrum-Button--cta").click()
|
||||
})
|
||||
|
|
|
@ -3,7 +3,14 @@
|
|||
import { database } from "stores/backend"
|
||||
import { automationStore } from "builderStore"
|
||||
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"
|
||||
|
||||
let name
|
||||
|
@ -56,6 +63,10 @@
|
|||
onConfirm={createAutomation}
|
||||
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"
|
||||
>Please name your automation, then select a trigger. Every automation must
|
||||
start with a trigger.
|
||||
|
|
|
@ -32,31 +32,22 @@
|
|||
import { onMount } from "svelte"
|
||||
|
||||
export let query
|
||||
export let fields = []
|
||||
|
||||
let fields = query.schema ? schemaToFields(query.schema) : []
|
||||
let parameters
|
||||
let data = []
|
||||
let roleId
|
||||
const transformerDocs =
|
||||
"https://docs.budibase.com/building-apps/data/transformers"
|
||||
const typeOptions = [
|
||||
{ label: "Text", value: "STRING" },
|
||||
{ label: "Number", value: "NUMBER" },
|
||||
{ label: "Boolean", value: "BOOLEAN" },
|
||||
{ label: "Datetime", value: "DATETIME" },
|
||||
{ label: "Text", value: "string" },
|
||||
{ label: "Number", value: "number" },
|
||||
{ label: "Boolean", value: "boolean" },
|
||||
{ label: "Datetime", value: "datetime" },
|
||||
]
|
||||
|
||||
$: datasource = $datasources.list.find(ds => ds._id === query.datasourceId)
|
||||
$: query.schema = fields.reduce(
|
||||
(acc, next) => ({
|
||||
...acc,
|
||||
[next.name]: {
|
||||
name: next.name,
|
||||
type: "string",
|
||||
},
|
||||
}),
|
||||
{}
|
||||
)
|
||||
$: query.schema = fieldsToSchema(fields)
|
||||
$: datasourceType = datasource?.source
|
||||
$: integrationInfo = $integrations[datasourceType]
|
||||
$: queryConfig = integrationInfo?.query
|
||||
|
@ -135,7 +126,7 @@
|
|||
// unique fields returned by the server
|
||||
fields = json.schemaFields.map(field => ({
|
||||
name: field,
|
||||
type: "STRING",
|
||||
type: "string",
|
||||
}))
|
||||
} catch (err) {
|
||||
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 () => {
|
||||
if (!query || !query._id) {
|
||||
roleId = Roles.BASIC
|
||||
|
|
|
@ -83,12 +83,11 @@
|
|||
}
|
||||
|
||||
async function createNewApp() {
|
||||
const letTemplateToUse =
|
||||
Object.keys(template).length === 0 ? null : template
|
||||
const templateToUse = Object.keys(template).length === 0 ? null : template
|
||||
submitting = true
|
||||
|
||||
// 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"
|
||||
valid = false
|
||||
submitting = false
|
||||
|
@ -99,10 +98,10 @@
|
|||
// Create form data to create app
|
||||
let data = new FormData()
|
||||
data.append("name", $values.name.trim())
|
||||
data.append("useTemplate", letTemplateToUse != null)
|
||||
if (letTemplateToUse) {
|
||||
data.append("templateName", letTemplateToUse.name)
|
||||
data.append("templateKey", letTemplateToUse.key)
|
||||
data.append("useTemplate", templateToUse != null)
|
||||
if (templateToUse) {
|
||||
data.append("templateName", templateToUse.name)
|
||||
data.append("templateKey", templateToUse.key)
|
||||
data.append("templateFile", $values.file)
|
||||
}
|
||||
|
||||
|
@ -116,7 +115,7 @@
|
|||
analytics.captureEvent(Events.APP.CREATED, {
|
||||
name: $values.name,
|
||||
appId: appJson.instance._id,
|
||||
letTemplateToUse,
|
||||
templateToUse,
|
||||
})
|
||||
|
||||
// Select Correct Application/DB in prep for creating user
|
||||
|
|
|
@ -13,9 +13,11 @@
|
|||
notifications,
|
||||
Search,
|
||||
} from "@budibase/bbui"
|
||||
import Spinner from "components/common/Spinner.svelte"
|
||||
import CreateAppModal from "components/start/CreateAppModal.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 { apps, auth, admin } from "stores/portal"
|
||||
import download from "downloadjs"
|
||||
|
@ -24,6 +26,7 @@
|
|||
import AppCard from "components/start/AppCard.svelte"
|
||||
import AppRow from "components/start/AppRow.svelte"
|
||||
import { AppStatus } from "constants"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
let layout = "grid"
|
||||
let sortBy = "name"
|
||||
|
@ -38,6 +41,7 @@
|
|||
let searchTerm = ""
|
||||
let cloud = $admin.cloud
|
||||
let appName = ""
|
||||
let creatingFromTemplate = false
|
||||
|
||||
$: enrichedApps = enrichApps($apps, $auth.user, sortBy)
|
||||
$: filteredApps = enrichedApps.filter(app =>
|
||||
|
@ -92,6 +96,62 @@
|
|||
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 = () => {
|
||||
template = null
|
||||
creatingApp = false
|
||||
|
@ -194,7 +254,7 @@
|
|||
template = {
|
||||
key: templateKey,
|
||||
}
|
||||
initiateAppCreation()
|
||||
autoCreateApp()
|
||||
} else {
|
||||
notifications.error("Your Template URL is invalid. Please try another.")
|
||||
}
|
||||
|
@ -202,12 +262,14 @@
|
|||
|
||||
onMount(async () => {
|
||||
await apps.load()
|
||||
loaded = true
|
||||
// if the portal is loaded from an external URL with a template param
|
||||
const initInfo = await auth.getInitInfo()
|
||||
if (initInfo.init_template) {
|
||||
creatingFromTemplate = true
|
||||
createAppFromTemplateUrl(initInfo.init_template)
|
||||
return
|
||||
}
|
||||
loaded = true
|
||||
})
|
||||
</script>
|
||||
|
||||
|
@ -285,6 +347,12 @@
|
|||
</Modal>
|
||||
</div>
|
||||
{/if}
|
||||
{#if creatingFromTemplate}
|
||||
<div class="empty-wrapper">
|
||||
<p>Creating your Budibase app from your selected template...</p>
|
||||
<Spinner size="10" />
|
||||
</div>
|
||||
{/if}
|
||||
</Page>
|
||||
<Modal
|
||||
bind:this={creationModal}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue