diff --git a/.eslintignore b/.eslintignore index 8d4c64d960..f2c53c2fdc 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,6 +6,7 @@ packages/server/coverage packages/worker/coverage packages/backend-core/coverage packages/server/client +packages/server/coverage packages/builder/.routify packages/sdk/sdk packages/account-portal/packages/server/build diff --git a/packages/backend-core/src/context/mainContext.ts b/packages/backend-core/src/context/mainContext.ts index ae86695168..6cea7efeba 100644 --- a/packages/backend-core/src/context/mainContext.ts +++ b/packages/backend-core/src/context/mainContext.ts @@ -10,7 +10,7 @@ import { StaticDatabases, DEFAULT_TENANT_ID, } from "../constants" -import { Database, IdentityContext } from "@budibase/types" +import { Database, IdentityContext, Snippet, App } from "@budibase/types" import { ContextMap } from "./types" let TEST_APP_ID: string | null = null @@ -122,10 +122,10 @@ export async function doInAutomationContext(params: { automationId: string task: () => T }): Promise { - const tenantId = getTenantIDFromAppID(params.appId) + await ensureSnippetContext() return newContext( { - tenantId, + tenantId: getTenantIDFromAppID(params.appId), appId: params.appId, automationId: params.automationId, }, @@ -281,6 +281,27 @@ export function doInScimContext(task: any) { return newContext(updates, task) } +export async function ensureSnippetContext() { + const ctx = getCurrentContext() + + // If we've already added snippets to context, continue + if (!ctx || ctx.snippets) { + return + } + + // Otherwise get snippets for this app and update context + let snippets: Snippet[] | undefined + const db = getAppDB() + if (db && !env.isTest()) { + const app = await db.get(DocumentType.APP_METADATA) + snippets = app.snippets + } + + // Always set snippets to a non-null value so that we can tell we've attempted + // to load snippets + ctx.snippets = snippets || [] +} + export function getEnvironmentVariables() { const context = Context.get() if (!context.environmentVariables) { diff --git a/packages/backend-core/src/context/types.ts b/packages/backend-core/src/context/types.ts index 8ea544a53c..f297d3089f 100644 --- a/packages/backend-core/src/context/types.ts +++ b/packages/backend-core/src/context/types.ts @@ -1,4 +1,4 @@ -import { IdentityContext, VM } from "@budibase/types" +import { IdentityContext, Snippet, VM } from "@budibase/types" // keep this out of Budibase types, don't want to expose context info export type ContextMap = { @@ -11,4 +11,5 @@ export type ContextMap = { isMigrating?: boolean vm?: VM cleanup?: (() => void | Promise)[] + snippets?: Snippet[] } diff --git a/packages/backend-core/src/events/publishers/app.ts b/packages/backend-core/src/events/publishers/app.ts index d08d59b5f1..af26b09e72 100644 --- a/packages/backend-core/src/events/publishers/app.ts +++ b/packages/backend-core/src/events/publishers/app.ts @@ -13,6 +13,7 @@ import { AppVersionRevertedEvent, AppRevertedEvent, AppExportedEvent, + AppDuplicatedEvent, } from "@budibase/types" const created = async (app: App, timestamp?: string | number) => { @@ -77,6 +78,17 @@ async function fileImported(app: App) { await publishEvent(Event.APP_FILE_IMPORTED, properties) } +async function duplicated(app: App, duplicateAppId: string) { + const properties: AppDuplicatedEvent = { + duplicateAppId, + appId: app.appId, + audited: { + name: app.name, + }, + } + await publishEvent(Event.APP_DUPLICATED, properties) +} + async function templateImported(app: App, templateKey: string) { const properties: AppTemplateImportedEvent = { appId: app.appId, @@ -147,6 +159,7 @@ export default { published, unpublished, fileImported, + duplicated, templateImported, versionUpdated, versionReverted, diff --git a/packages/backend-core/tests/core/utilities/mocks/events.ts b/packages/backend-core/tests/core/utilities/mocks/events.ts index fef730768a..96f351de10 100644 --- a/packages/backend-core/tests/core/utilities/mocks/events.ts +++ b/packages/backend-core/tests/core/utilities/mocks/events.ts @@ -15,6 +15,7 @@ beforeAll(async () => { jest.spyOn(events.app, "created") jest.spyOn(events.app, "updated") + jest.spyOn(events.app, "duplicated") jest.spyOn(events.app, "deleted") jest.spyOn(events.app, "published") jest.spyOn(events.app, "unpublished") diff --git a/packages/bbui/src/ActionMenu/ActionMenu.svelte b/packages/bbui/src/ActionMenu/ActionMenu.svelte index 642ec4932a..c55d1cb43d 100644 --- a/packages/bbui/src/ActionMenu/ActionMenu.svelte +++ b/packages/bbui/src/ActionMenu/ActionMenu.svelte @@ -38,7 +38,7 @@
- + diff --git a/packages/bbui/src/Actions/click_outside.js b/packages/bbui/src/Actions/click_outside.js index 1961dca47c..12c4c4d002 100644 --- a/packages/bbui/src/Actions/click_outside.js +++ b/packages/bbui/src/Actions/click_outside.js @@ -32,6 +32,13 @@ const handleClick = event => { return } + // Ignore clicks for drawers, unless the handler is registered from a drawer + const sourceInDrawer = handler.anchor.closest(".drawer-wrapper") != null + const clickInDrawer = event.target.closest(".drawer-wrapper") != null + if (clickInDrawer && !sourceInDrawer) { + return + } + handler.callback?.(event) }) } diff --git a/packages/bbui/src/Actions/position_dropdown.js b/packages/bbui/src/Actions/position_dropdown.js index d259b9197a..770d1bd507 100644 --- a/packages/bbui/src/Actions/position_dropdown.js +++ b/packages/bbui/src/Actions/position_dropdown.js @@ -15,6 +15,7 @@ export default function positionDropdown(element, opts) { align, maxHeight, maxWidth, + minWidth, useAnchorWidth, offset = 5, customUpdate, @@ -28,7 +29,7 @@ export default function positionDropdown(element, opts) { const elementBounds = element.getBoundingClientRect() let styles = { maxHeight: null, - minWidth: null, + minWidth, maxWidth, left: null, top: null, @@ -41,8 +42,13 @@ export default function positionDropdown(element, opts) { }) } else { // Determine vertical styles - if (align === "right-outside") { - styles.top = anchorBounds.top + if (align === "right-outside" || align === "left-outside") { + styles.top = + anchorBounds.top + anchorBounds.height / 2 - elementBounds.height / 2 + styles.maxHeight = maxHeight + if (styles.top + elementBounds.height > window.innerHeight) { + styles.top = window.innerHeight - elementBounds.height + } } else if ( window.innerHeight - anchorBounds.bottom < (maxHeight || 100) diff --git a/packages/bbui/src/Drawer/Drawer.svelte b/packages/bbui/src/Drawer/Drawer.svelte index 8976bfb81e..89ee92726d 100644 --- a/packages/bbui/src/Drawer/Drawer.svelte +++ b/packages/bbui/src/Drawer/Drawer.svelte @@ -1,28 +1,111 @@ + + {#if visible} - -
- {#if !headless} + + +
+
+
0} + class:modal={$modal} + transition:drawerSlide|local + {style} + >
-
- {title} - - - -
+ {#if $$slots.title} + + {:else} +
{title || "Bindings"}
+ {/if}
+ {#if $resizable} + modal.set(!$modal)} + > + + + {/if}
- {/if} - -
+ +
+
+
{/if} diff --git a/packages/bbui/src/Drawer/DrawerContent.svelte b/packages/bbui/src/Drawer/DrawerContent.svelte index 944a3f4313..490dfecc31 100644 --- a/packages/bbui/src/Drawer/DrawerContent.svelte +++ b/packages/bbui/src/Drawer/DrawerContent.svelte @@ -1,4 +1,8 @@ -
+ + +
{#if $$slots.sidebar}
- +
diff --git a/packages/builder/src/components/common/NavItem.svelte b/packages/builder/src/components/common/NavItem.svelte index 0819bcb86b..66b21e95a1 100644 --- a/packages/builder/src/components/common/NavItem.svelte +++ b/packages/builder/src/components/common/NavItem.svelte @@ -8,6 +8,7 @@ export let iconTooltip export let withArrow = false export let withActions = true + export let showActions = false export let indentLevel = 0 export let text export let border = true @@ -68,6 +69,8 @@ class:border class:selected class:withActions + class:showActions + class:actionsOpen={highlighted && withActions} class:scrollable class:highlighted class:selectedBy @@ -168,8 +171,10 @@ --avatars-background: var(--spectrum-global-color-gray-300); } .nav-item:hover .actions, - .hovering .actions { - visibility: visible; + .hovering .actions, + .nav-item.withActions.actionsOpen .actions, + .nav-item.withActions.showActions .actions { + opacity: 1; } .nav-item-content { flex: 1 1 auto; @@ -272,7 +277,6 @@ position: relative; display: grid; place-items: center; - visibility: hidden; order: 3; opacity: 0; width: 20px; diff --git a/packages/builder/src/components/common/bindings/BindingPanel.svelte b/packages/builder/src/components/common/bindings/BindingPanel.svelte index 7b567e052b..21d389357f 100644 --- a/packages/builder/src/components/common/bindings/BindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/BindingPanel.svelte @@ -1,74 +1,194 @@ - - + +
- { - if (selectedMode == mode) { - return true - } - - //Get the current mode value - const editorValue = usingJS ? decodeJSBinding(jsValue) : hbsValue - - if (editorValue) { - targetMode = selectedMode - return false - } - return true - }} - > - -
-
-
- {#if targetMode} -
-
- - {`Switch to ${targetMode}?`} - - This will discard anything in your binding -
- - -
-
-
- {/if} - -
- -
- - {#if sidebar} -
- -
- {/if} + {#if showTabBar} +
+
+ {#each editorModeOptions as editorMode} + changeMode(editorMode)} + > + {capitalise(editorMode)} + + {/each} +
+
+ {#each sidePanelOptions as panel} + changeSidePanel(panel)} + > + + + {/each}
- - {#if allowJS} - -
-
-
- {#if targetMode} -
-
- - {`Switch to ${targetMode}?`} - - This will discard anything in your binding -
- - -
-
-
- {/if} - - -
- -
- - {#if sidebar} -
- -
- {/if} -
-
- {/if} -
- {#if typeof drawerActions?.hide === "function" && drawerActions?.headless} - - {/if} - {#if typeof bindingDrawerActions?.save === "function" && drawerActions?.headless} - - {/if}
- + {/if} +
+ {#if mode === Modes.Text} + {#key hbsCompletions} + + {/key} + {:else if mode === Modes.JavaScript} + {#key jsCompletions} + + {/key} + {/if} + {#if targetMode} +
+
+ + Switch to {targetMode}? + + This will discard anything in your binding +
+ + +
+
+
+ {/if} +
- - +
+ {#if sidePanel === SidePanels.Bindings} + + {:else if sidePanel === SidePanels.Evaluation} + + {:else if sidePanel === SidePanels.Snippets} + bindingHelpers.onSelectSnippet(snippet)} + {snippets} + /> + {/if} +
+
+ diff --git a/packages/builder/src/components/common/bindings/BindingPicker.svelte b/packages/builder/src/components/common/bindings/BindingPicker.svelte deleted file mode 100644 index 42057b382b..0000000000 --- a/packages/builder/src/components/common/bindings/BindingPicker.svelte +++ /dev/null @@ -1,399 +0,0 @@ - - - - - -
- {#if hoverTarget.title} -
{hoverTarget.title}
- {/if} - {#if hoverTarget.description} -
- - {@html hoverTarget.description} -
- {/if} - {#if hoverTarget.example} -
{hoverTarget.example}
- {/if} -
-
-
-
- - - - - - {#if selectedCategory} -
- { - selectedCategory = null - }} - > - Back - -
- {/if} - - {#if !selectedCategory} - - {/if} - - {#if !selectedCategory && !search} -
    - {#each categoryNames as categoryName} -
  • { - selectedCategory = categoryName - }} - > - - {categoryName} - -
  • - {/each} -
- {/if} - - {#if selectedCategory || search} - {#each filteredCategories as category} - {#if category.bindings?.length} -
-
- {category.name} -
-
    - {#each category.bindings as binding} -
  • { - popoverAnchor = e.target - if (!binding.description) { - return - } - hoverTarget = { - title: binding.display?.name || binding.fieldSchema?.name, - description: binding.description, - } - popover.show() - e.stopPropagation() - }} - on:mouseleave={() => { - popover.hide() - popoverAnchor = null - hoverTarget = null - }} - on:focus={() => {}} - on:blur={() => {}} - on:click={() => addBinding(binding)} - > - - {#if binding.display?.name} - {binding.display.name} - {:else if binding.fieldSchema?.name} - {binding.fieldSchema?.name} - {:else} - {binding.readableBinding} - {/if} - - - {#if binding.display?.type || binding.fieldSchema?.type} - - - {binding.display?.type || binding.fieldSchema?.type} - - - {/if} -
  • - {/each} -
-
- {/if} - {/each} - - {#if selectedCategory === "Helpers" || search} - {#if filteredHelpers?.length} -
-
Helpers
-
    - {#each filteredHelpers as helper} -
  • addHelper(helper, mode.name == "javascript")} - on:mouseenter={e => { - popoverAnchor = e.target - if (!helper.displayText && helper.description) { - return - } - hoverTarget = { - title: helper.displayText, - description: helper.description, - example: getHelperExample( - helper, - mode.name == "javascript" - ), - } - popover.show() - e.stopPropagation() - }} - on:mouseleave={() => { - popover.hide() - popoverAnchor = null - hoverTarget = null - }} - on:focus={() => {}} - on:blur={() => {}} - > - {helper.displayText} - - function - -
  • - {/each} -
-
- {/if} - {/if} - {/if} -
- - diff --git a/packages/builder/src/components/common/bindings/BindingSidePanel.svelte b/packages/builder/src/components/common/bindings/BindingSidePanel.svelte new file mode 100644 index 0000000000..6ef2d35a6c --- /dev/null +++ b/packages/builder/src/components/common/bindings/BindingSidePanel.svelte @@ -0,0 +1,446 @@ + + + +
+ {#if hoverTarget.description} +
+ + {@html hoverTarget.description} +
+ {/if} + {#if hoverTarget.code} + +
{@html hoverTarget.code}
+ {/if} +
+
+ + + +
+ + {#if selectedCategory} +
+ (selectedCategory = null)} + /> + {selectedCategory} +
+ {/if} + + {#if !selectedCategory} +
+ {#if searching} +
+ +
+ + {:else} +
Bindings
+ + {/if} +
+ {/if} + {#if !selectedCategory && !search} +
    + {#each categoryNames as categoryName} +
  • { + selectedCategory = categoryName + }} + > + + {categoryName} + +
  • + {/each} +
+ {/if} + + {#if selectedCategory || search} + {#each filteredCategories as category} + {#if category.bindings?.length} +
+ {#if filteredCategories.length > 1} +
+ {category.name} +
+ {/if} +
    + {#each category.bindings as binding} +
  • showBindingPopover(binding, e.target)} + on:mouseleave={hidePopover} + on:click={() => addBinding(binding)} + > + + {#if binding.display?.name} + {binding.display.name} + {:else if binding.fieldSchema?.name} + {binding.fieldSchema?.name} + {:else} + {binding.readableBinding} + {/if} + + {#if binding.display?.type || binding.fieldSchema?.type} + + + {binding.display?.type || binding.fieldSchema?.type} + + + {/if} +
  • + {/each} +
+
+ {/if} + {/each} + + {#if selectedCategory === "Helpers" || search} + {#if filteredHelpers?.length} +
+
    + {#each filteredHelpers as helper} +
  • showHelperPopover(helper, e.target)} + on:mouseleave={hidePopover} + on:click={() => addHelper(helper, mode.name === "javascript")} + > + {helper.displayText} + + function + +
  • + {/each} +
+
+ {/if} + {/if} + {/if} +
+
+ + diff --git a/packages/builder/src/components/common/bindings/ClientBindingPanel.svelte b/packages/builder/src/components/common/bindings/ClientBindingPanel.svelte index 7888f2e486..cb65d2bbe4 100644 --- a/packages/builder/src/components/common/bindings/ClientBindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/ClientBindingPanel.svelte @@ -1,8 +1,9 @@ - - - Add the objects on the left to enrich your text. - - - + + (tempValue = event.detail)} {bindings} {allowJS} diff --git a/packages/builder/src/components/common/bindings/DrawerBindableInput.svelte b/packages/builder/src/components/common/bindings/DrawerBindableInput.svelte index 80996a484d..d11ebcf87a 100644 --- a/packages/builder/src/components/common/bindings/DrawerBindableInput.svelte +++ b/packages/builder/src/components/common/bindings/DrawerBindableInput.svelte @@ -13,21 +13,21 @@ export let panel = ClientBindingPanel export let value = "" export let bindings = [] - export let title = "Bindings" + export let title export let placeholder export let label export let disabled = false - export let fillWidth export let allowJS = true export let allowHelpers = true export let updateOnChange = true - export let drawerLeft export let key export let disableBindings = false + export let forceModal = false + export let context = null const dispatch = createEventDispatcher() + let bindingDrawer - let valid = true let currentVal = value $: readableValue = runtimeToReadableBinding(bindings, value) @@ -88,27 +88,20 @@ - - Add the objects on the left to enrich your text. - - + (tempValue = event.detail)} {bindings} {allowJS} {allowHelpers} + {context} /> diff --git a/packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte b/packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte index 4cac24660f..8ce9dda209 100644 --- a/packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte +++ b/packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte @@ -16,7 +16,6 @@ export let placeholder export let label export let disabled = false - export let fillWidth export let allowJS = true export let allowHelpers = true export let updateOnChange = true @@ -26,7 +25,6 @@ const dispatch = createEventDispatcher() let bindingDrawer - let valid = true let currentVal = value $: readableValue = runtimeToReadableBinding(bindings, value) @@ -173,22 +171,14 @@ - - Add the objects on the left to enrich your text. - - + (tempValue = event.detail)} {bindings} diff --git a/packages/builder/src/components/common/bindings/EvaluationSidePanel.svelte b/packages/builder/src/components/common/bindings/EvaluationSidePanel.svelte new file mode 100644 index 0000000000..2c4e6a0991 --- /dev/null +++ b/packages/builder/src/components/common/bindings/EvaluationSidePanel.svelte @@ -0,0 +1,133 @@ + + +
+
+
+ {#if error} + +
Error
+ {#if evaluating} +
+ +
+ {/if} + + + {:else} +
Preview
+ {#if evaluating} +
+ +
+ {/if} + + {#if !empty} + + {/if} + {/if} +
+
+
+ {#if empty} + Your expression will be evaluated here + {:else} + + {@html highlightedResult} + {/if} +
+
+ + diff --git a/packages/builder/src/components/common/bindings/ModalBindableInput.svelte b/packages/builder/src/components/common/bindings/ModalBindableInput.svelte index 41245ceaec..3261dc6b74 100644 --- a/packages/builder/src/components/common/bindings/ModalBindableInput.svelte +++ b/packages/builder/src/components/common/bindings/ModalBindableInput.svelte @@ -1,115 +1,12 @@ - - -
- onChange(event.detail)} - {placeholder} - {updateOnChange} - /> -
- -
-
- - - - Add the objects on the left to enrich your text. - -
- (tempValue = e.detail)} - {bindings} - {allowJS} - /> -
-
-
- - + diff --git a/packages/builder/src/components/common/bindings/ServerBindingPanel.svelte b/packages/builder/src/components/common/bindings/ServerBindingPanel.svelte index 213e5bbf1d..df0da768e0 100644 --- a/packages/builder/src/components/common/bindings/ServerBindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/ServerBindingPanel.svelte @@ -1,10 +1,11 @@ diff --git a/packages/builder/src/components/common/bindings/SnippetDrawer.svelte b/packages/builder/src/components/common/bindings/SnippetDrawer.svelte new file mode 100644 index 0000000000..d6b6f92b17 --- /dev/null +++ b/packages/builder/src/components/common/bindings/SnippetDrawer.svelte @@ -0,0 +1,160 @@ + + + + + {#if snippet} + {snippet.name} + {:else} +
+ Name + + {#if nameError} + + + + {/if} +
+ {/if} +
+ + {#if snippet} + + {/if} + + + + {#key key} + (code = e.detail)} + > +
+ +
+
+ {/key} +
+
+ + + + diff --git a/packages/builder/src/components/common/bindings/SnippetSidePanel.svelte b/packages/builder/src/components/common/bindings/SnippetSidePanel.svelte new file mode 100644 index 0000000000..c68699fc0f --- /dev/null +++ b/packages/builder/src/components/common/bindings/SnippetSidePanel.svelte @@ -0,0 +1,278 @@ + + + + +
+ +
+ {#if enableSnippets} + {#if searching} +
+ +
+ + {:else} +
Snippets
+ + + {/if} + {:else} +
+ Snippets + + Premium + +
+ {/if} +
+
+ {#if enableSnippets && filteredSnippets?.length} + {#each filteredSnippets as snippet} +
showSnippet(snippet, e.target)} + on:mouseleave={hidePopover} + on:click={() => addSnippet(snippet)} + > + {snippet.name} + editSnippet(e, snippet)} + /> +
+ {/each} + {:else} +
+ + Snippets let you create reusable JS functions and values that can + all be managed in one place + + {#if enableSnippets} + + {:else} + + {/if} +
+ {/if} +
+
+
+ + +
+ {#key hoveredSnippet} + + {/key} +
+
+ + + + diff --git a/packages/builder/src/components/common/bindings/utils.js b/packages/builder/src/components/common/bindings/utils.js index a086cd0394..c60374f0f7 100644 --- a/packages/builder/src/components/common/bindings/utils.js +++ b/packages/builder/src/components/common/bindings/utils.js @@ -38,4 +38,11 @@ export class BindingHelpers { this.insertAtPos({ start, end, value: insertVal }) } } + + // Adds a snippet to the expression + onSelectSnippet(snippet) { + const pos = this.getCaretPosition() + const { start, end } = pos + this.insertAtPos({ start, end, value: `snippets.${snippet.name}` }) + } } diff --git a/packages/builder/src/components/deploy/AppActions.svelte b/packages/builder/src/components/deploy/AppActions.svelte index 9e5de1d3bf..de8b45c98b 100644 --- a/packages/builder/src/components/deploy/AppActions.svelte +++ b/packages/builder/src/components/deploy/AppActions.svelte @@ -19,7 +19,7 @@ import ConfirmDialog from "components/common/ConfirmDialog.svelte" import analytics, { Events, EventSource } from "analytics" import { API } from "api" - import { apps } from "stores/portal" + import { appsStore } from "stores/portal" import { previewStore, builderStore, @@ -45,7 +45,7 @@ let appActionPopoverAnchor let publishing = false - $: filteredApps = $apps.filter(app => app.devId === application) + $: filteredApps = $appsStore.apps.filter(app => app.devId === application) $: selectedApp = filteredApps?.length ? filteredApps[0] : null $: latestDeployments = $deploymentStore .filter(deployment => deployment.status === "SUCCESS") @@ -129,7 +129,7 @@ } try { await API.unpublishApp(selectedApp.prodId) - await apps.load() + await appsStore.load() notifications.send("App unpublished", { type: "success", icon: "GlobeStrike", @@ -141,7 +141,7 @@ const completePublish = async () => { try { - await apps.load() + await appsStore.load() await deploymentStore.load() } catch (err) { notifications.error("Error refreshing app") diff --git a/packages/builder/src/components/deploy/DeleteModal.svelte b/packages/builder/src/components/deploy/DeleteModal.svelte index 855f6a0757..75204b55ce 100644 --- a/packages/builder/src/components/deploy/DeleteModal.svelte +++ b/packages/builder/src/components/deploy/DeleteModal.svelte @@ -2,10 +2,17 @@ import { Input, notifications } from "@budibase/bbui" import { goto } from "@roxi/routify" import ConfirmDialog from "components/common/ConfirmDialog.svelte" - import { apps } from "stores/portal" - import { appStore } from "stores/builder" + import { appsStore } from "stores/portal" import { API } from "api" + export let appId + export let appName + export let onDeleteSuccess = () => { + $goto("/builder") + } + + let deleting = false + export const show = () => { deletionModal.show() } @@ -17,32 +24,52 @@ let deletionModal let deletionConfirmationAppName + const copyName = () => { + deletionConfirmationAppName = appName + } + const deleteApp = async () => { + if (!appId) { + console.error("No app id provided") + return + } + deleting = true try { - await API.deleteApp($appStore.appId) - apps.load() + await API.deleteApp(appId) + appsStore.load() notifications.success("App deleted successfully") - $goto("/builder") + onDeleteSuccess() } catch (err) { notifications.error("Error deleting app") + deleting = false } } + (deletionConfirmationAppName = null)} - disabled={deletionConfirmationAppName !== $appStore.name} + disabled={deletionConfirmationAppName !== appName || deleting} > - Are you sure you want to delete {$appStore.name}? + Are you sure you want to delete + + {appName} + ? +
Please enter the app name below to confirm.

- +
+ + diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/ButtonActionEditor.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/ButtonActionEditor.svelte index d445c98a1a..f009c975cf 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/ButtonActionEditor.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/ButtonActionEditor.svelte @@ -12,6 +12,7 @@ export let bindings export let nested export let componentInstance + export let title = "Actions" let drawer let tmpValue @@ -37,7 +38,7 @@ {actionText}
- + Define what actions to run. diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte index 431368d28f..5b7844ce53 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte @@ -31,7 +31,7 @@ (parameters.rowId = value.detail)} /> diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/FetchRow.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/FetchRow.svelte index 4478f1bb16..61b7494ab2 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/FetchRow.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/FetchRow.svelte @@ -29,7 +29,7 @@ (parameters.rowId = value.detail)} /> diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveFields.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveFields.svelte index 52bd84c453..e03af75207 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveFields.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveFields.svelte @@ -62,7 +62,7 @@ {/if} updateFieldValue(idx, event.detail)} diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/ShowNotification.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/ShowNotification.svelte index 55b00d215d..d95e13cb5f 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/ShowNotification.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/ShowNotification.svelte @@ -40,6 +40,7 @@ diff --git a/packages/builder/src/components/design/settings/controls/PropertyControl.svelte b/packages/builder/src/components/design/settings/controls/PropertyControl.svelte index 0f0276823a..4db9a03d80 100644 --- a/packages/builder/src/components/design/settings/controls/PropertyControl.svelte +++ b/packages/builder/src/components/design/settings/controls/PropertyControl.svelte @@ -105,6 +105,7 @@ onChange={handleChange} bindings={allBindings} name={key} + title={label} {nested} {key} {type} diff --git a/packages/builder/src/components/integration/KeyValueBuilder.svelte b/packages/builder/src/components/integration/KeyValueBuilder.svelte index e71090f613..74636fc50c 100644 --- a/packages/builder/src/components/integration/KeyValueBuilder.svelte +++ b/packages/builder/src/components/integration/KeyValueBuilder.svelte @@ -143,7 +143,6 @@ value={field.value} allowJS={false} {allowHelpers} - fillWidth={true} drawerLeft={bindingDrawerLeft} /> {:else} diff --git a/packages/builder/src/components/portal/licensing/AppLimitModal.svelte b/packages/builder/src/components/portal/licensing/AppLimitModal.svelte index 39f553517e..bdecbcab3d 100644 --- a/packages/builder/src/components/portal/licensing/AppLimitModal.svelte +++ b/packages/builder/src/components/portal/licensing/AppLimitModal.svelte @@ -31,17 +31,11 @@ : null} > - You are currently on our Free plan. Upgrade - to our Pro plan to get unlimited apps and additional features. + You have exceeded the app limit for your current plan. Upgrade to get + unlimited apps and additional features! {#if !$auth.user.accountPortalAccess} Please contact the account holder to upgrade. {/if} - - diff --git a/packages/builder/src/components/start/AppRow.svelte b/packages/builder/src/components/start/AppRow.svelte index 32bddd58a6..6dd4030f3a 100644 --- a/packages/builder/src/components/start/AppRow.svelte +++ b/packages/builder/src/components/start/AppRow.svelte @@ -5,10 +5,14 @@ import { goto } from "@roxi/routify" import { UserAvatars } from "@budibase/frontend-core" import { sdk } from "@budibase/shared-core" + import AppRowContext from "./AppRowContext.svelte" + import FavouriteAppButton from "pages/builder/portal/apps/FavouriteAppButton.svelte" export let app export let lockedAction + let actionsOpen = false + $: editing = app.sessions?.length $: isBuilder = sdk.users.isBuilder($auth.user, app?.devId) $: unclickable = !isBuilder && !app.deployed @@ -42,8 +46,10 @@
@@ -74,21 +80,35 @@ {app.deployed ? "Published" : "Unpublished"}
- {#if isBuilder} +
- - + {#if isBuilder} +
+ +
+
+ { + actionsOpen = true + }} + on:close={() => { + actionsOpen = false + }} + /> +
+ {:else} + + + {/if}
- {:else if app.deployed} - -
- + +
+
- {/if} +
diff --git a/packages/builder/src/components/start/ExportAppModal.svelte b/packages/builder/src/components/start/ExportAppModal.svelte index 734e4448a1..ec0cf42fe0 100644 --- a/packages/builder/src/components/start/ExportAppModal.svelte +++ b/packages/builder/src/components/start/ExportAppModal.svelte @@ -121,6 +121,7 @@ { - const applications = svelteGet(apps) + const applications = svelteGet(appsStore).apps appValidation.name(validation, { apps: applications, currentApp: { @@ -62,7 +62,7 @@ async function updateApp() { try { - await apps.update(app.appId, { + await appsStore.save(app.appId, { name: $values.name?.trim(), url: $values.url?.trim(), icon: { diff --git a/packages/builder/src/global.css b/packages/builder/src/global.css index bc1f55d9d3..adf4a47070 100644 --- a/packages/builder/src/global.css +++ b/packages/builder/src/global.css @@ -22,6 +22,7 @@ body { --grey-7: var(--spectrum-global-color-gray-700); --grey-8: var(--spectrum-global-color-gray-800); --grey-9: var(--spectrum-global-color-gray-900); + --spectrum-global-color-yellow-1000: #d8b500; color: var(--ink); background-color: var(--background-alt); diff --git a/packages/builder/src/helpers/duplicate.js b/packages/builder/src/helpers/duplicate.js index 1547fcd4d1..c2a924f97b 100644 --- a/packages/builder/src/helpers/duplicate.js +++ b/packages/builder/src/helpers/duplicate.js @@ -48,3 +48,53 @@ export const duplicateName = (name, allNames) => { return `${baseName} ${number}` } + +/** + * More flexible alternative to the above function, which handles getting the + * next sequential name from an array of existing items while accounting for + * any type of prefix, and being able to deeply retrieve that name from the + * existing item array. + * + * Examples with a prefix of "foo": + * [] => "foo" + * ["foo"] => "foo2" + * ["foo", "foo6"] => "foo7" + * + * Examples with a prefix of "foo " (space at the end): + * [] => "foo" + * ["foo"] => "foo 2" + * ["foo", "foo 6"] => "foo 7" + * + * @param items the array of existing items + * @param prefix the string prefix of each name, including any spaces desired + * @param getName optional function to extract the name for an item, if not a + * flat array of strings + */ +export const getSequentialName = (items, prefix, getName = x => x) => { + if (!prefix?.length || !getName) { + return null + } + const trimmedPrefix = prefix.trim() + if (!items?.length) { + return trimmedPrefix + } + let max = 0 + items.forEach(item => { + const name = getName(item) + if (typeof name !== "string" || !name.startsWith(trimmedPrefix)) { + return + } + const split = name.split(trimmedPrefix) + if (split.length !== 2) { + return + } + if (split[1].trim() === "") { + split[1] = "1" + } + const num = parseInt(split[1]) + if (num > max) { + max = num + } + }) + return max === 0 ? trimmedPrefix : `${prefix}${max + 1}` +} diff --git a/packages/builder/src/helpers/tests/duplicate.test.js b/packages/builder/src/helpers/tests/duplicate.test.js index 400abed0aa..7e51c5ff2a 100644 --- a/packages/builder/src/helpers/tests/duplicate.test.js +++ b/packages/builder/src/helpers/tests/duplicate.test.js @@ -1,5 +1,5 @@ import { expect, describe, it } from "vitest" -import { duplicateName } from "../duplicate" +import { duplicateName, getSequentialName } from "../duplicate" describe("duplicate", () => { describe("duplicates a name ", () => { @@ -40,3 +40,64 @@ describe("duplicate", () => { }) }) }) + +describe("getSequentialName", () => { + it("handles nullish items", async () => { + const name = getSequentialName(null, "foo", () => {}) + expect(name).toBe("foo") + }) + + it("handles nullish prefix", async () => { + const name = getSequentialName([], null, () => {}) + expect(name).toBe(null) + }) + + it("handles nullish getName function", async () => { + const name = getSequentialName([], "foo", null) + expect(name).toBe(null) + }) + + it("handles just the prefix", async () => { + const name = getSequentialName(["foo"], "foo", x => x) + expect(name).toBe("foo2") + }) + + it("handles continuous ranges", async () => { + const name = getSequentialName(["foo", "foo2", "foo3"], "foo", x => x) + expect(name).toBe("foo4") + }) + + it("handles discontinuous ranges", async () => { + const name = getSequentialName(["foo", "foo3"], "foo", x => x) + expect(name).toBe("foo4") + }) + + it("handles a space inside the prefix", async () => { + const name = getSequentialName(["foo", "foo 2", "foo 3"], "foo ", x => x) + expect(name).toBe("foo 4") + }) + + it("handles a space inside the prefix with just the prefix", async () => { + const name = getSequentialName(["foo"], "foo ", x => x) + expect(name).toBe("foo 2") + }) + + it("handles no matches", async () => { + const name = getSequentialName(["aaa", "bbb"], "foo", x => x) + expect(name).toBe("foo") + }) + + it("handles similar names", async () => { + const name = getSequentialName( + ["fooo1", "2foo", "a3foo4", "5foo5"], + "foo", + x => x + ) + expect(name).toBe("foo") + }) + + it("handles non-string names", async () => { + const name = getSequentialName([null, 4123, [], {}], "foo", x => x) + expect(name).toBe("foo") + }) +}) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 7c1cc583e1..d714bafc70 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -15,7 +15,14 @@ FancySelect, } from "@budibase/bbui" import { builderStore, appStore, roles } from "stores/builder" - import { groups, licensing, apps, users, auth, admin } from "stores/portal" + import { + groups, + licensing, + appsStore, + users, + auth, + admin, + } from "stores/portal" import { fetchData, Constants, @@ -54,7 +61,7 @@ let inviteFailureResponse = "" $: validEmail = emailValidator(email) === true - $: prodAppId = apps.getProdAppID($appStore.appId) + $: prodAppId = appsStore.getProdAppID($appStore.appId) $: promptInvite = showInvite( filteredInvites, filteredUsers, diff --git a/packages/builder/src/pages/builder/app/[application]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/_layout.svelte index 16a1adadee..fd6a97560d 100644 --- a/packages/builder/src/pages/builder/app/[application]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_layout.svelte @@ -8,7 +8,7 @@ userStore, deploymentStore, } from "stores/builder" - import { auth, apps } from "stores/portal" + import { auth, appsStore } from "stores/portal" import { TENANT_FEATURE_FLAGS, isEnabled } from "helpers/featureFlags" import { Icon, @@ -52,7 +52,7 @@ const pkg = await API.fetchAppPackage(application) await initialise(pkg) - await apps.load() + await appsStore.load() await deploymentStore.load() loaded = true @@ -188,7 +188,7 @@ {/if} - + diff --git a/packages/builder/src/pages/builder/app/[application]/automation/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/automation/_layout.svelte index c4ee060149..57180625b1 100644 --- a/packages/builder/src/pages/builder/app/[application]/automation/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/automation/_layout.svelte @@ -40,7 +40,7 @@
-
+
{#if $automationStore.automations?.length} {:else} diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/AppPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/AppPanel.svelte index 5867021386..4617814485 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/AppPanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/AppPanel.svelte @@ -6,6 +6,7 @@
+
@@ -32,7 +33,17 @@ flex-direction: column; justify-content: flex-start; align-items: stretch; - padding: 9px var(--spacing-m); + padding: 9px 10px 12px 10px; + position: relative; + transition: width 360ms ease-out; + } + .drawer-container { + position: absolute; + height: 100%; + width: 100%; + overflow: hidden; + top: 0; + left: 0; } .header { display: flex; diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/AppPreview.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/AppPreview.svelte index bf66c28a09..95e7a66be9 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/AppPreview.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/AppPreview.svelte @@ -10,6 +10,7 @@ navigationStore, selectedScreen, hoverStore, + snippets, } from "stores/builder" import ConfirmDialog from "components/common/ConfirmDialog.svelte" import { @@ -68,6 +69,7 @@ hostname: window.location.hostname, port: window.location.port, }, + snippets: $snippets, } // Refresh the preview when required @@ -196,6 +198,16 @@ } else if (type === "add-parent-component") { const { componentId, parentType } = data await componentStore.addParent(componentId, parentType) + } else if (type === "provide-context") { + let context = data?.context + if (context) { + try { + context = JSON.parse(context) + } catch (error) { + context = null + } + } + previewStore.setSelectedComponentContext(context) } else { console.warn(`Client sent unknown event type: ${type}`) } diff --git a/packages/builder/src/pages/builder/app/[application]/settings/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/settings/_layout.svelte index da4f743f04..67befddcb9 100644 --- a/packages/builder/src/pages/builder/app/[application]/settings/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/settings/_layout.svelte @@ -3,7 +3,7 @@ import { Page, Layout, AbsTooltip, TooltipPosition } from "@budibase/bbui" import { url, isActive } from "@roxi/routify" import DeleteModal from "components/deploy/DeleteModal.svelte" - import { isOnlyUser } from "stores/builder" + import { isOnlyUser, appStore } from "stores/builder" let deleteModal @@ -67,7 +67,11 @@
- + diff --git a/packages/builder/src/pages/builder/portal/apps/_layout.svelte b/packages/builder/src/pages/builder/portal/apps/_layout.svelte index 8810edca9c..00719dc6d5 100644 --- a/packages/builder/src/pages/builder/portal/apps/_layout.svelte +++ b/packages/builder/src/pages/builder/portal/apps/_layout.svelte @@ -2,7 +2,7 @@ import { notifications } from "@budibase/bbui" import { admin, - apps, + appsStore, templates, licensing, groups, @@ -14,7 +14,7 @@ import PortalSideBar from "./_components/PortalSideBar.svelte" // Don't block loading if we've already hydrated state - let loaded = !!$apps?.length + let loaded = !!$appsStore.apps?.length onMount(async () => { try { @@ -34,7 +34,10 @@ } // Go to new app page if no apps exists - if (!$apps.length && sdk.users.hasBuilderPermissions($auth.user)) { + if ( + !$appsStore.apps.length && + sdk.users.hasBuilderPermissions($auth.user) + ) { $redirect("./onboarding") } } catch (error) { @@ -46,7 +49,7 @@ {#if loaded}
- {#if $apps.length > 0} + {#if $appsStore.apps.length > 0} {/if} diff --git a/packages/builder/src/pages/builder/portal/apps/create.svelte b/packages/builder/src/pages/builder/portal/apps/create.svelte index 1f2c579071..1248c41cf8 100644 --- a/packages/builder/src/pages/builder/portal/apps/create.svelte +++ b/packages/builder/src/pages/builder/portal/apps/create.svelte @@ -5,7 +5,7 @@ import CreateAppModal from "components/start/CreateAppModal.svelte" import TemplateDisplay from "components/common/TemplateDisplay.svelte" import AppLimitModal from "components/portal/licensing/AppLimitModal.svelte" - import { apps, templates, licensing } from "stores/portal" + import { appsStore, templates, licensing } from "stores/portal" import { Breadcrumbs, Breadcrumb, Header } from "components/portal/page" let template @@ -35,7 +35,7 @@ } -{#if !$apps.length} +{#if !$appsStore.apps.length} {:else} diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index a1aa242a36..adea7600a6 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -19,13 +19,18 @@ import { automationStore, initialise } from "stores/builder" import { API } from "api" import { onMount } from "svelte" - import { apps, auth, admin, licensing, environment } from "stores/portal" + import { + appsStore, + auth, + admin, + licensing, + environment, + enrichedApps, + } from "stores/portal" import { goto } from "@roxi/routify" import AppRow from "components/start/AppRow.svelte" - import { AppStatus } from "constants" import Logo from "assets/bb-space-man.svg" - let sortBy = "name" let template let creationModal let appLimitModal @@ -33,56 +38,27 @@ let searchTerm = "" let creatingFromTemplate = false let automationErrors - let accessFilterList = null $: welcomeHeader = `Welcome ${$auth?.user?.firstName || "back"}` - $: enrichedApps = enrichApps($apps, $auth.user, sortBy) - $: filteredApps = enrichedApps.filter( - app => - (searchTerm - ? app?.name?.toLowerCase().includes(searchTerm.toLowerCase()) - : true) && - (accessFilterList !== null - ? accessFilterList?.includes( - `${app?.type}_${app?.tenantId}_${app?.appId}` - ) - : true) - ) - $: automationErrors = getAutomationErrors(enrichedApps) + $: filteredApps = filterApps($enrichedApps, searchTerm) + $: automationErrors = getAutomationErrors(filteredApps || []) $: isOwner = $auth.accountPortalAccess && $admin.cloud + const filterApps = (apps, searchTerm) => { + return apps?.filter(app => { + const query = searchTerm?.trim()?.replace(/\s/g, "") + if (query) { + return app?.name?.toLowerCase().includes(query.toLowerCase()) + } else { + return true + } + }) + } + const usersLimitLockAction = $licensing?.errUserLimit ? () => accountLockedModal.show() : null - const enrichApps = (apps, user, sortBy) => { - const enrichedApps = apps.map(app => ({ - ...app, - deployed: app.status === AppStatus.DEPLOYED, - lockedYou: app.lockedBy && app.lockedBy.email === user?.email, - lockedOther: app.lockedBy && app.lockedBy.email !== user?.email, - })) - - if (sortBy === "status") { - return enrichedApps.sort((a, b) => { - if (a.status === b.status) { - return a.name?.toLowerCase() < b.name?.toLowerCase() ? -1 : 1 - } - return a.status === AppStatus.DEPLOYED ? -1 : 1 - }) - } else if (sortBy === "updated") { - return enrichedApps.sort((a, b) => { - const aUpdated = a.updatedAt || "9999" - const bUpdated = b.updatedAt || "9999" - return aUpdated < bUpdated ? 1 : -1 - }) - } else { - return enrichedApps.sort((a, b) => { - return a.name?.toLowerCase() < b.name?.toLowerCase() ? -1 : 1 - }) - } - } - const getAutomationErrors = apps => { const automationErrors = {} for (let app of apps) { @@ -117,7 +93,7 @@ const initiateAppCreation = async () => { if ($licensing?.usageMetrics?.apps >= 100) { appLimitModal.show() - } else if ($apps?.length) { + } else if ($appsStore.apps?.length) { $goto("/builder/portal/apps/create") } else { template = null @@ -136,7 +112,7 @@ const templateKey = template.key.split("/")[1] let appName = templateKey.replace(/-/g, " ") - const appsWithSameName = $apps.filter(app => + const appsWithSameName = $appsStore.apps.filter(app => app.name?.startsWith(appName) ) appName = `${appName} ${appsWithSameName.length + 1}` @@ -217,7 +193,7 @@ : "View error"} on:dismiss={async () => { await automationStore.actions.clearLogErrors({ appId }) - await apps.load() + await appsStore.load() }} message={automationErrorMessage(appId)} /> @@ -233,7 +209,7 @@
- {#if enrichedApps.length} + {#if $appsStore.apps.length}
{#if $auth.user && sdk.users.canCreateApps($auth.user)} @@ -245,7 +221,7 @@ > Create new app - {#if $apps?.length > 0 && !$admin.offlineMode} + {#if $appsStore.apps?.length > 0 && !$admin.offlineMode}