From 6c269bf091d12f65b6916850f45f398b05d099d3 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 22 Mar 2022 11:38:17 +0000 Subject: [PATCH 1/8] Initial commit of home screen modifications and template browsing --- .../src/components/common/TemplateCard.svelte | 124 +++++++ .../components/common/TemplateDisplay.svelte | 147 ++++++++ .../components/start/CreateAppModal.svelte | 74 +++- .../pages/builder/portal/apps/create.svelte | 141 +++++++ .../pages/builder/portal/apps/index.svelte | 348 +++++++----------- .../builder/portal/apps/templates.svelte | 41 +++ 6 files changed, 649 insertions(+), 226 deletions(-) create mode 100644 packages/builder/src/components/common/TemplateCard.svelte create mode 100644 packages/builder/src/components/common/TemplateDisplay.svelte create mode 100644 packages/builder/src/pages/builder/portal/apps/create.svelte create mode 100644 packages/builder/src/pages/builder/portal/apps/templates.svelte diff --git a/packages/builder/src/components/common/TemplateCard.svelte b/packages/builder/src/components/common/TemplateCard.svelte new file mode 100644 index 0000000000..b016397400 --- /dev/null +++ b/packages/builder/src/components/common/TemplateCard.svelte @@ -0,0 +1,124 @@ + + +
+
+ {name} +
+ + + +
+
+ +
+
+
+
{name}
+
+
+ + diff --git a/packages/builder/src/components/common/TemplateDisplay.svelte b/packages/builder/src/components/common/TemplateDisplay.svelte new file mode 100644 index 0000000000..0cc3b1ea77 --- /dev/null +++ b/packages/builder/src/components/common/TemplateDisplay.svelte @@ -0,0 +1,147 @@ + + +
+ + Templates + +
+ + + {#each templateCategories as templateCategoryKey} + + {/each} +
+
+
+ +
+ + {#each filteredTemplateCategories as templateCategoryKey} +
+ {templateCategoryKey} +
+ {#each filteredTemplates[templateCategoryKey] as templateEntry} + + + + Details + + + {/each} +
+
+ {/each} +
+
+ + + + + + diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 91c4807dc8..6ed5bf8244 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -9,6 +9,7 @@ import { goto } from "@roxi/routify" import { createValidationStore } from "helpers/validation/yup" import * as appValidation from "helpers/validation/yup/app" + import TemplateCard from "components/common/TemplateCard.svelte" export let template @@ -17,9 +18,30 @@ $: validation.check($values) onMount(async () => { + $values.url = resolveAppUrl(template, $values.name, $values.url) + $values.name = resolveAppName(template, $values.name) await setupValidation() }) + $: appUrl = `${window.location.origin}${ + $values.url ? $values.url : `/${resolveAppUrl(template, $values.name)}` + }` + + const resolveAppUrl = (template, name) => { + let parsedName + const resolvedName = resolveAppName(template, name) + parsedName = resolvedName ? resolvedName.toLowerCase() : "" + const parsedUrl = parsedName ? parsedName.replace(/\s+/g, "-") : "" + return encodeURI(parsedUrl) + } + + const resolveAppName = (template, name) => { + if (template && !name) { + return template.name + } + return name.trim() + } + const setupValidation = async () => { const applications = svelteGet(apps) appValidation.name(validation, { apps: applications }) @@ -83,6 +105,15 @@ onConfirm={createNewApp} disabled={!$validation.valid} > + {#if template && !template?.fromFile} + + {/if} {#if template?.fromFile} - ($validation.touched.url = true)} - label="URL" - placeholder={$values.name - ? "/" + encodeURIComponent($values.name).toLowerCase() - : "/"} - /> + + ($validation.touched.url = true)} + label="URL" + placeholder={$values.url + ? $values.url + : `/${resolveAppUrl(template, $values.name)}`} + /> + {#if $values.name} +
+ + {window.location.origin} + + {$values.url + ? $values.url + : `/${resolveAppUrl(template, $values.name)}`} +
+ {/if} +
+ + diff --git a/packages/builder/src/pages/builder/portal/apps/create.svelte b/packages/builder/src/pages/builder/portal/apps/create.svelte new file mode 100644 index 0000000000..bb5329978d --- /dev/null +++ b/packages/builder/src/pages/builder/portal/apps/create.svelte @@ -0,0 +1,141 @@ + + + + + + + + +
+
+ + {createAppTitle} + + {welcomeBody} + + + +
+ + +
+
+ +
+ + {#if loaded && $templates?.length} + + {/if} +
+
+ + + + + + diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index b05aa1b659..eb303a0f38 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -11,8 +11,9 @@ notifications, Body, Search, - Icon, + Divider, } from "@budibase/bbui" + import TemplateDisplay from "components/common/TemplateDisplay.svelte" import Spinner from "components/common/Spinner.svelte" import CreateAppModal from "components/start/CreateAppModal.svelte" import UpdateAppModal from "components/start/UpdateAppModal.svelte" @@ -45,6 +46,21 @@ let appName = "" let creatingFromTemplate = false + const resolveWelcomeMessage = (auth, apps) => { + const userWelcome = auth?.user?.firstName + ? `Welcome ${auth?.user?.firstName}!` + : "Welcome back!" + return apps?.length ? userWelcome : "Let's create your first app!" + } + $: welcomeHeader = resolveWelcomeMessage($auth, $apps) + $: welcomeBody = $apps?.length + ? "Manage your apps and get a head start with templates" + : "Start from scratch or get a head start with one of our templates" + + $: createAppButtonText = $apps?.length + ? "Create new app" + : "Start from scratch" + $: enrichedApps = enrichApps($apps, $auth.user, sortBy) $: filteredApps = enrichedApps.filter(app => app?.name?.toLowerCase().includes(searchTerm.toLowerCase()) @@ -79,9 +95,13 @@ } const initiateAppCreation = () => { - template = null - creationModal.show() - creatingApp = true + if ($apps?.length) { + $goto("/builder/portal/apps/create") + } else { + template = null + creationModal.show() + creatingApp = true + } } const initiateAppsExport = () => { @@ -268,148 +288,113 @@ -
- - Welcome to Budibase - - Manage your apps and get a head start with templates - - + {#if loaded} +
+
+ + {welcomeHeader} + + {welcomeBody} + + -
- {#if cloud} - - {/if} - - +
+ + {#if $apps?.length > 0} + + {/if} + {#if !$apps?.length} + + {/if} +
+
+
+ + + +
+
-
- - Quick start templates -
- {#each $templates as item} -
{ - template = item - creationModal.show() - creatingApp = true - }} - class="template-card" - > - - - -
-
- - - -
-
- {item.name} -
- {item.category.toUpperCase()} + {#if !$apps?.length && $templates?.length} + + {/if} + + {#if enrichedApps.length} + +
+ My apps + {#if enrichedApps.length > 1} +
+ {#if cloud} + + {/if} +
+ - +
+ {#each filteredApps as app (app.appId)} + + {/each}
-
- -
- {#each filteredApps as app (app.appId)} - - {/each} -
- - {/if} - - {#if !enrichedApps.length && !creatingApp && loaded} -
-
-
- - logo -
- Create a business app in minutes! -
- -
-
-
-
+ + {/if} {/if} {#if creatingFromTemplate}
+

Creating your Budibase app from your selected template...

@@ -459,6 +444,15 @@ diff --git a/packages/builder/src/pages/builder/portal/apps/templates.svelte b/packages/builder/src/pages/builder/portal/apps/templates.svelte new file mode 100644 index 0000000000..c77b869c6e --- /dev/null +++ b/packages/builder/src/pages/builder/portal/apps/templates.svelte @@ -0,0 +1,41 @@ + + + + + + + + {#if loaded && $templates?.length} + + {/if} + + From f6cbe01b07002d0886cd489ea45891b63f04ec5d Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 22 Mar 2022 11:40:45 +0000 Subject: [PATCH 2/8] Code formatting --- .../src/components/common/TemplateCard.svelte | 5 ++--- .../src/components/common/TemplateDisplay.svelte | 2 +- .../src/pages/builder/portal/apps/index.svelte | 16 ++++++++-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/components/common/TemplateCard.svelte b/packages/builder/src/components/common/TemplateCard.svelte index b016397400..dc8cdc9610 100644 --- a/packages/builder/src/components/common/TemplateCard.svelte +++ b/packages/builder/src/components/common/TemplateCard.svelte @@ -47,7 +47,6 @@
diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 6ed5bf8244..623e30e73b 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -13,18 +13,20 @@ export let template + let creating = false + const values = writable({ name: "", url: null }) const validation = createValidationStore() $: validation.check($values) onMount(async () => { - $values.url = resolveAppUrl(template, $values.name, $values.url) $values.name = resolveAppName(template, $values.name) + nameToUrl($values.name) await setupValidation() }) $: appUrl = `${window.location.origin}${ - $values.url ? $values.url : `/${resolveAppUrl(template, $values.name)}` + $values.url ? $values.url : `${resolveAppUrl(template, $values.name)}` }` const resolveAppUrl = (template, name) => { @@ -39,7 +41,19 @@ if (template && !name) { return template.name } - return name.trim() + return name ? name.trim() : null + } + + const tidyUrl = url => { + if (url && !url.startsWith("/")) { + url = `/${url}` + } + $values.url = url === "" ? null : url + } + + const nameToUrl = appName => { + let resolvedUrl = resolveAppUrl(template, appName) + tidyUrl(resolvedUrl) } const setupValidation = async () => { @@ -52,6 +66,8 @@ } async function createNewApp() { + creating = true + try { // Create form data to create app let data = new FormData() @@ -86,17 +102,11 @@ await auth.setInitInfo({}) $goto(`/builder/app/${createdApp.instance._id}`) } catch (error) { + creating = false console.error(error) notifications.error("Error creating app") } } - - // auto add slash to url - $: { - if ($values.url && !$values.url.startsWith("/")) { - $values.url = `/${$values.url}` - } - } ($validation.touched.name = true)} + on:change={nameToUrl($values.name)} label="Name" - placeholder={$auth.user.firstName + placeholder={$auth.user?.firstName ? `${$auth.user.firstName}s app` : "My app"} /> ($validation.touched.url = true)} + on:change={tidyUrl($values.url)} label="URL" placeholder={$values.url ? $values.url : `/${resolveAppUrl(template, $values.name)}`} /> - {#if $values.name} -
- - {window.location.origin} - - {$values.url - ? $values.url - : `/${resolveAppUrl(template, $values.name)}`} + {#if $values.url && $values.url !== "" && !$validation.errors.url} +
+ {`${window.location.origin}${$values.url}`}
{/if}