Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move snippets to sidepanel #15595

Open
wants to merge 18 commits into
base: BUDI-9068/type-sidepanel
Choose a base branch
from
2 changes: 1 addition & 1 deletion packages/bbui/src/Drawer/Drawer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import { setContext, createEventDispatcher, onDestroy } from "svelte"
import { generate } from "shortid"

export let title
export let title = ""
export let forceModal = false

const dispatch = createEventDispatcher()
Expand Down
2 changes: 1 addition & 1 deletion packages/bbui/src/Popover/Popover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import type { KeyboardEventHandler } from "svelte/elements"
import { PopoverAlignment } from "../constants"

export let anchor: HTMLElement
export let anchor: HTMLElement | undefined
export let align: PopoverAlignment | `${PopoverAlignment}` =
PopoverAlignment.Right
export let portalTarget: string | undefined = undefined
Expand Down
58 changes: 27 additions & 31 deletions packages/builder/src/components/common/bindings/BindingPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
} from "../CodeEditor"
import BindingSidePanel from "./BindingSidePanel.svelte"
import EvaluationSidePanel from "./EvaluationSidePanel.svelte"
import SnippetSidePanel from "./SnippetSidePanel.svelte"
import { BindingHelpers } from "./utils"
import { capitalise } from "@/helpers"
import { Utils, JsonFormatter } from "@budibase/frontend-core"
import { licensing } from "@/stores/portal"
import { BindingMode, SidePanel } from "@budibase/types"
import { BindingMode } from "@budibase/types"
import type {
EnrichedBinding,
Snippet,
Expand All @@ -44,6 +43,8 @@
import type { Log } from "@budibase/string-templates"
import type { CodeValidator } from "@/types"

type SidePanel = "Bindings" | "Evaluation"

const dispatch = createEventDispatcher()

export let bindings: EnrichedBinding[] = []
Expand All @@ -55,7 +56,7 @@
export let context = null
export let snippets: Snippet[] | null = null
export let autofocusEditor = false
export let placeholder = null
export let placeholder: string | null = null
export let showTabBar = true

let mode: BindingMode
Expand All @@ -71,14 +72,13 @@
let expressionError: string | undefined
let evaluating = false

$: useSnippets = allowSnippets && !$licensing.isFreePlan
const SidePanelIcons: Record<SidePanel, string> = {
Bindings: "FlashOn",
Evaluation: "Play",
}

$: editorModeOptions = getModeOptions(allowHBS, allowJS)
$: sidePanelOptions = getSidePanelOptions(
bindings,
context,
allowSnippets,
mode
)
$: sidePanelOptions = getSidePanelOptions(bindings, context)
$: enrichedBindings = enrichBindings(bindings, context, snippets)
$: usingJS = mode === BindingMode.JavaScript
$: editorMode =
Expand All @@ -93,7 +93,9 @@
$: bindingOptions = bindingsToCompletions(bindings, editorMode)
$: helperOptions = allowHelpers ? getHelperCompletions(editorMode) : []
$: snippetsOptions =
usingJS && useSnippets && snippets?.length ? snippets : []
usingJS && allowSnippets && !$licensing.isFreePlan && snippets?.length
? snippets
: []

$: completions = !usingJS
? [hbAutocomplete([...bindingOptions, ...helperOptions])]
Expand Down Expand Up @@ -137,21 +139,13 @@
return options
}

const getSidePanelOptions = (
bindings: EnrichedBinding[],
context: any,
useSnippets: boolean,
mode: BindingMode | null
) => {
let options = []
const getSidePanelOptions = (bindings: EnrichedBinding[], context: any) => {
let options: SidePanel[] = []
if (bindings?.length) {
options.push(SidePanel.Bindings)
options.push("Bindings")
}
if (context && Object.keys(context).length > 0) {
options.push(SidePanel.Evaluation)
}
if (useSnippets && mode === BindingMode.JavaScript) {
options.push(SidePanel.Snippets)
options.push("Evaluation")
}
return options
}
Expand Down Expand Up @@ -342,14 +336,15 @@
{/each}
</div>
<div class="side-tabs">
{#each sidePanelOptions as panel}
{#each sidePanelOptions as panelOption}
<ActionButton
size="M"
quiet
selected={sidePanel === panel}
on:click={() => changeSidePanel(panel)}
selected={sidePanel === panelOption}
on:click={() => changeSidePanel(panelOption)}
tooltip={panelOption}
>
<Icon name={panel} size="S" />
<Icon name={SidePanelIcons[panelOption]} size="S" />
</ActionButton>
{/each}
</div>
Expand Down Expand Up @@ -414,25 +409,26 @@
</div>
</div>
<div class="side" class:visible={!!sidePanel}>
{#if sidePanel === SidePanel.Bindings}
{#if sidePanel === "Bindings"}
<BindingSidePanel
bindings={enrichedBindings}
{allowHelpers}
{allowSnippets}
{context}
addHelper={onSelectHelper}
addBinding={onSelectBinding}
{addSnippet}
{mode}
{snippets}
/>
{:else if sidePanel === SidePanel.Evaluation}
{:else if sidePanel === "Evaluation"}
<EvaluationSidePanel
{expressionResult}
{expressionError}
{expressionLogs}
{evaluating}
expression={editorValue ? editorValue : ""}
/>
{:else if sidePanel === SidePanel.Snippets}
<SnippetSidePanel {addSnippet} {snippets} />
{/if}
</div>
</div>
Expand Down
Loading
Loading