Merge pull request #3086 from Budibase/fix/create-app-exp

Make it possible for first app to be an imported one
This commit is contained in:
Michael Drury 2021-10-20 10:24:00 +01:00 committed by GitHub
commit e53dba1997
6 changed files with 1391 additions and 44 deletions

View File

@ -35,7 +35,7 @@ Cypress.Commands.add("login", () => {
Cypress.Commands.add("createApp", name => { Cypress.Commands.add("createApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`) cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.wait(500) cy.wait(500)
cy.contains(/Start from scratch/).click() cy.contains(/Start from scratch/).dblclick()
cy.get(".spectrum-Modal").within(() => { cy.get(".spectrum-Modal").within(() => {
cy.get("input").eq(0).type(name).should("have.value", name).blur() cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.get(".spectrum-ButtonGroup").contains("Create app").click() cy.get(".spectrum-ButtonGroup").contains("Create app").click()

View File

@ -20,6 +20,7 @@
import TemplateList from "./TemplateList.svelte" import TemplateList from "./TemplateList.svelte"
export let template export let template
export let inline
const values = writable({ name: null }) const values = writable({ name: null })
const errors = writable({}) const errors = writable({})
@ -39,9 +40,10 @@
let submitting = false let submitting = false
let valid = false let valid = false
let initialTemplateInfo = template?.fromFile || template?.key
$: checkValidity($values, validator) $: checkValidity($values, validator)
$: showTemplateSelection = !template?.fromFile && !template?.key $: showTemplateSelection = !template && !initialTemplateInfo
onMount(async () => { onMount(async () => {
await hostingStore.actions.fetchDeployedApps() await hostingStore.actions.fetchDeployedApps()
@ -75,10 +77,12 @@
} }
async function createNewApp() { async function createNewApp() {
const letTemplateToUse =
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 (template?.fromFile && !$values.file) { if (letTemplateToUse?.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
@ -89,10 +93,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", template != null) data.append("useTemplate", letTemplateToUse != null)
if (template) { if (letTemplateToUse) {
data.append("templateName", template.name) data.append("templateName", letTemplateToUse.name)
data.append("templateKey", template.key) data.append("templateKey", letTemplateToUse.key)
data.append("templateFile", $values.file) data.append("templateFile", $values.file)
} }
@ -106,7 +110,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,
template, letTemplateToUse,
}) })
// Select Correct Application/DB in prep for creating user // Select Correct Application/DB in prep for creating user
@ -144,19 +148,18 @@
showConfirmButton={false} showConfirmButton={false}
size="L" size="L"
onConfirm={() => { onConfirm={() => {
showTemplateSelection = false template = {}
return false return false
}} }}
showCancelButton={false} showCancelButton={!inline}
showCloseIcon={false} showCloseIcon={!inline}
> >
<TemplateList <TemplateList
onSelect={selected => { onSelect={(selected, { useImport } = {}) => {
if (!selected) { if (!selected) {
showTemplateSelection = false template = useImport ? { fromFile: true } : {}
return return
} }
template = selected template = selected
}} }}
/> />
@ -166,6 +169,9 @@
title={template?.fromFile ? "Import app" : "Create app"} title={template?.fromFile ? "Import app" : "Create app"}
confirmText={template?.fromFile ? "Import app" : "Create app"} confirmText={template?.fromFile ? "Import app" : "Create app"}
onConfirm={createNewApp} onConfirm={createNewApp}
onCancel={inline ? () => (template = null) : null}
cancelText={inline ? "Back" : undefined}
showCloseIcon={!inline}
disabled={!valid} disabled={!valid}
> >
{#if template?.fromFile} {#if template?.fromFile}

View File

@ -7,7 +7,6 @@
async function fetchTemplates() { async function fetchTemplates() {
const response = await api.get("/api/templates?type=app") const response = await api.get("/api/templates?type=app")
console.log("Responded")
return await response.json() return await response.json()
} }
@ -48,6 +47,19 @@
<Heading size="XS">Start from scratch</Heading> <Heading size="XS">Start from scratch</Heading>
<p class="detail">BLANK</p> <p class="detail">BLANK</p>
</div> </div>
<div
class="template import"
on:click={() => onSelect(null, { useImport: true })}
>
<div
class="background-icon"
style={`background: rgb(50, 50, 50); color: white;`}
>
<Icon name="Add" />
</div>
<Heading size="XS">Import an app</Heading>
<p class="detail">BLANK</p>
</div>
</div> </div>
{:catch err} {:catch err}
<h1 style="color:red">{err}</h1> <h1 style="color:red">{err}</h1>
@ -95,4 +107,8 @@
background: var(--spectrum-global-color-gray-50); background: var(--spectrum-global-color-gray-50);
margin-top: 20px; margin-top: 20px;
} }
.import {
background: var(--spectrum-global-color-gray-50);
}
</style> </style>

View File

@ -268,7 +268,7 @@
{#if !enrichedApps.length && !creatingApp && loaded} {#if !enrichedApps.length && !creatingApp && loaded}
<div class="empty-wrapper"> <div class="empty-wrapper">
<Modal inline> <Modal inline>
<CreateAppModal {template} /> <CreateAppModal {template} inline={true} />
</Modal> </Modal>
</div> </div>
{/if} {/if}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff