This commit is contained in:
Andrew Kingston 2023-12-08 13:45:51 +00:00
parent eac79f754d
commit ed403fd79d
9 changed files with 51 additions and 7 deletions

View File

@ -88,7 +88,7 @@ const INITIAL_FRONTEND_STATE = {
selectedLayoutId: null, selectedLayoutId: null,
// Client state // Client state
selectedComponentInstance: null, selectedComponentContext: null,
// Onboarding // Onboarding
onboarding: false, onboarding: false,
@ -504,6 +504,12 @@ export const getFrontendStore = () => {
return state return state
}) })
}, },
setSelectedComponentContext: context => {
store.update(state => {
state.selectedComponentContext = context
return state
})
},
}, },
layouts: { layouts: {
select: layoutId => { select: layoutId => {

View File

@ -45,6 +45,7 @@
export let valid export let valid
export let allowJS = false export let allowJS = false
export let allowHelpers = true export let allowHelpers = true
export let context = null
const drawerActions = getContext("drawer-actions") const drawerActions = getContext("drawer-actions")
const bindingDrawerActions = getContext("binding-drawer-actions") const bindingDrawerActions = getContext("binding-drawer-actions")
@ -250,6 +251,7 @@
<BindingPicker <BindingPicker
{bindings} {bindings}
{allowHelpers} {allowHelpers}
{context}
addHelper={onSelectHelper} addHelper={onSelectHelper}
addBinding={onSelectBinding} addBinding={onSelectBinding}
mode={editorMode} mode={editorMode}
@ -330,6 +332,7 @@
<BindingPicker <BindingPicker
{bindings} {bindings}
{allowHelpers} {allowHelpers}
{context}
addHelper={onSelectHelper} addHelper={onSelectHelper}
addBinding={onSelectBinding} addBinding={onSelectBinding}
mode={editorMode} mode={editorMode}

View File

@ -1,6 +1,6 @@
<script> <script>
import groupBy from "lodash/fp/groupBy" import groupBy from "lodash/fp/groupBy"
import { convertToJS } from "@budibase/string-templates" import { convertToJS, processStringSync } from "@budibase/string-templates"
import { Input, Layout, ActionButton, Icon, Popover } from "@budibase/bbui" import { Input, Layout, ActionButton, Icon, Popover } from "@budibase/bbui"
import { handlebarsCompletions } from "constants/completions" import { handlebarsCompletions } from "constants/completions"
@ -9,6 +9,7 @@
export let bindings export let bindings
export let mode export let mode
export let allowHelpers export let allowHelpers
export let context = null
let search = "" let search = ""
let popover let popover
@ -95,6 +96,9 @@
{#if hoverTarget.example} {#if hoverTarget.example}
<pre class="helper__example">{hoverTarget.example}</pre> <pre class="helper__example">{hoverTarget.example}</pre>
{/if} {/if}
{#if hoverTarget.val}
<pre>{hoverTarget.val}</pre>
{/if}
</div> </div>
</Layout> </Layout>
</Popover> </Popover>
@ -165,13 +169,14 @@
<li <li
class="binding" class="binding"
on:mouseenter={e => { on:mouseenter={e => {
const hbs = `{{ ${binding.runtimeBinding} }}`
const val = processStringSync(hbs, context)
console.log(binding.runtimeBinding, val)
popoverAnchor = e.target popoverAnchor = e.target
if (!binding.description) {
return
}
hoverTarget = { hoverTarget = {
title: binding.display?.name || binding.fieldSchema?.name, title: binding.display?.name || binding.fieldSchema?.name,
description: binding.description, description: binding.description,
val,
} }
popover.show() popover.show()
e.stopPropagation() e.stopPropagation()

View File

@ -6,7 +6,7 @@
export let value = "" export let value = ""
export let allowJS = false export let allowJS = false
export let allowHelpers = true export let allowHelpers = true
export let context = null
$: enrichedBindings = enrichBindings(bindings) $: enrichedBindings = enrichBindings(bindings)
// Ensure bindings have the correct categories // Ensure bindings have the correct categories
@ -24,6 +24,7 @@
<BindingPanel <BindingPanel
bind:valid bind:valid
bindings={enrichedBindings} bindings={enrichedBindings}
{context}
{value} {value}
{allowJS} {allowJS}
{allowHelpers} {allowHelpers}

View File

@ -4,7 +4,6 @@
readableToRuntimeBinding, readableToRuntimeBinding,
runtimeToReadableBinding, runtimeToReadableBinding,
} from "builderStore/dataBinding" } from "builderStore/dataBinding"
import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte" import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte"
import { createEventDispatcher, setContext } from "svelte" import { createEventDispatcher, setContext } from "svelte"
import { isJSBinding } from "@budibase/string-templates" import { isJSBinding } from "@budibase/string-templates"
@ -22,8 +21,10 @@
export let updateOnChange = true export let updateOnChange = true
export let drawerLeft export let drawerLeft
export let disableBindings = false export let disableBindings = false
export let context = null
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let bindingDrawer let bindingDrawer
let valid = true let valid = true
let currentVal = value let currentVal = value
@ -95,6 +96,7 @@
bind:valid bind:valid
value={readableValue} value={readableValue}
on:change={event => (tempValue = event.detail)} on:change={event => (tempValue = event.detail)}
{context}
{bindings} {bindings}
{allowJS} {allowJS}
{allowHelpers} {allowHelpers}

View File

@ -24,6 +24,7 @@
export let propertyFocus = false export let propertyFocus = false
export let info = null export let info = null
export let disableBindings = false export let disableBindings = false
export let context = null
$: nullishValue = value == null || value === "" $: nullishValue = value == null || value === ""
$: allBindings = getAllBindings(bindings, componentBindings, nested) $: allBindings = getAllBindings(bindings, componentBindings, nested)
@ -97,6 +98,7 @@
onChange={handleChange} onChange={handleChange}
bindings={allBindings} bindings={allBindings}
name={key} name={key}
{context}
{nested} {nested}
{key} {key}
{type} {type}

View File

@ -8,6 +8,7 @@
import { getComponentForSetting } from "components/design/settings/componentSettings" import { getComponentForSetting } from "components/design/settings/componentSettings"
import InfoDisplay from "./InfoDisplay.svelte" import InfoDisplay from "./InfoDisplay.svelte"
import analytics, { Events } from "analytics" import analytics, { Events } from "analytics"
import { onMount } from "svelte"
export let componentDefinition export let componentDefinition
export let componentInstance export let componentInstance
@ -26,6 +27,7 @@
tag, tag,
includeHidden includeHidden
) )
$: context = $store.selectedComponentContext
const getSections = (instance, definition, isScreen, tag, includeHidden) => { const getSections = (instance, definition, isScreen, tag, includeHidden) => {
const settings = definition?.settings ?? [] const settings = definition?.settings ?? []
@ -145,6 +147,12 @@
} }
return shouldDisplay(instance, setting) return shouldDisplay(instance, setting)
} }
onMount(() => {
store.actions.preview.sendEvent("request-context")
})
$: console.log(context)
</script> </script>
{#each sections as section, idx (section.name)} {#each sections as section, idx (section.name)}
@ -191,6 +199,7 @@
min: setting.min ?? null, min: setting.min ?? null,
max: setting.max ?? null, max: setting.max ?? null,
}} }}
{context}
{bindings} {bindings}
{componentBindings} {componentBindings}
{componentInstance} {componentInstance}

View File

@ -181,6 +181,16 @@
} else if (type === "add-parent-component") { } else if (type === "add-parent-component") {
const { componentId, parentType } = data const { componentId, parentType } = data
await store.actions.components.addParent(componentId, parentType) await store.actions.components.addParent(componentId, parentType)
} else if (type === "provide-context") {
let context = data?.context
if (context) {
try {
context = JSON.parse(context)
} catch (error) {
context = null
}
}
store.actions.preview.setSelectedComponentContext(context)
} else { } else {
console.warn(`Client sent unknown event type: ${type}`) console.warn(`Client sent unknown event type: ${type}`)
} }

View File

@ -75,6 +75,12 @@ const loadBudibase = async () => {
} else { } else {
dndStore.actions.reset() dndStore.actions.reset()
} }
} else if (type === "request-context") {
const { selectedComponentInstance } = get(componentStore)
const context = selectedComponentInstance?.getDataContext()
eventStore.actions.dispatchEvent("provide-context", {
context: JSON.stringify(context),
})
} }
} }