pr feedback
This commit is contained in:
parent
eb932770b3
commit
43b7dc5d7b
|
@ -10,7 +10,7 @@
|
||||||
export let readonly: boolean = false
|
export let readonly: boolean = false
|
||||||
export let labelPosition: string = "above"
|
export let labelPosition: string = "above"
|
||||||
export let error: string | undefined = undefined
|
export let error: string | undefined = undefined
|
||||||
export let placeholder: string = "Choose an option"
|
export let placeholder: string | boolean = "Choose an option"
|
||||||
export let options: any[] = []
|
export let options: any[] = []
|
||||||
export let getOptionLabel = (option: any) => extractProperty(option, "label")
|
export let getOptionLabel = (option: any) => extractProperty(option, "label")
|
||||||
export let getOptionValue = (option: any) => extractProperty(option, "value")
|
export let getOptionValue = (option: any) => extractProperty(option, "value")
|
||||||
|
|
|
@ -1159,10 +1159,16 @@ export const buildFormSchema = (component, asset) => {
|
||||||
* Returns an array of the keys of any state variables which are set anywhere
|
* Returns an array of the keys of any state variables which are set anywhere
|
||||||
* in the app.
|
* in the app.
|
||||||
*/
|
*/
|
||||||
export const getAllStateVariables = () => {
|
export const getAllStateVariables = (screen = null) => {
|
||||||
// Find all button action settings in all components
|
// Find all button action settings in all components
|
||||||
|
let assets = []
|
||||||
|
if (screen) {
|
||||||
|
assets.push(screen)
|
||||||
|
} else {
|
||||||
|
assets = getAllAssets()
|
||||||
|
}
|
||||||
let eventSettings = []
|
let eventSettings = []
|
||||||
getAllAssets().forEach(asset => {
|
assets.forEach(asset => {
|
||||||
findAllMatchingComponents(asset.props, component => {
|
findAllMatchingComponents(asset.props, component => {
|
||||||
const settings = componentStore.getComponentSettings(component._component)
|
const settings = componentStore.getComponentSettings(component._component)
|
||||||
const nestedTypes = [
|
const nestedTypes = [
|
||||||
|
@ -1213,12 +1219,17 @@ export const getAllStateVariables = () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add on load settings from screens
|
if (screen) {
|
||||||
get(screenStore).screens.forEach(screen => {
|
|
||||||
if (screen.onLoad) {
|
if (screen.onLoad) {
|
||||||
eventSettings.push(screen.onLoad)
|
eventSettings.push(screen.onLoad)
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
|
get(screenStore).screens.forEach(screen => {
|
||||||
|
if (screen.onLoad) {
|
||||||
|
eventSettings.push(screen.onLoad)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Extract all state keys from any "update state" actions in each setting
|
// Extract all state keys from any "update state" actions in each setting
|
||||||
let bindingSet = new Set()
|
let bindingSet = new Set()
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { Select, Link } from "@budibase/bbui"
|
import { Select, Link } from "@budibase/bbui"
|
||||||
import type { Component } from "@budibase/types"
|
import type { Component } from "@budibase/types"
|
||||||
import { getAllStateVariables } from "@/dataBinding"
|
import { getAllStateVariables, getBindableProperties } from "@/dataBinding"
|
||||||
import {
|
import {
|
||||||
componentStore,
|
componentStore,
|
||||||
selectedScreen,
|
selectedScreen,
|
||||||
|
@ -16,31 +16,40 @@
|
||||||
} from "@budibase/string-templates"
|
} from "@budibase/string-templates"
|
||||||
import DrawerBindableInput from "@/components/common/bindings/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "@/components/common/bindings/DrawerBindableInput.svelte"
|
||||||
|
|
||||||
type ComponentUsingState = {
|
interface ComponentUsingState {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
settings: string[]
|
settings: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyOptions = getAllStateVariables()
|
$: keyOptions = getAllStateVariables($selectedScreen)
|
||||||
|
$: bindings = getBindableProperties(
|
||||||
|
$selectedScreen,
|
||||||
|
$componentStore.selectedComponentId
|
||||||
|
)
|
||||||
|
|
||||||
let selectedKey: string | undefined = undefined
|
let selectedKey: string | undefined = undefined
|
||||||
let componentsUsingState: ComponentUsingState[] = []
|
let componentsUsingState: ComponentUsingState[] = []
|
||||||
let componentsUpdatingState: ComponentUsingState[] = []
|
let componentsUpdatingState: ComponentUsingState[] = []
|
||||||
let editorValue: string = ""
|
let editorValue: string = ""
|
||||||
|
let previousScreenId: string | undefined = undefined
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
previewStore.requestComponentContext()
|
|
||||||
})
|
|
||||||
|
|
||||||
$: $selectedScreen, selectedKey && searchComponents(selectedKey)
|
|
||||||
$: {
|
$: {
|
||||||
|
const screenChanged =
|
||||||
|
$selectedScreen && $selectedScreen._id !== previousScreenId
|
||||||
const previewContext = $previewStore.selectedComponentContext || {}
|
const previewContext = $previewStore.selectedComponentContext || {}
|
||||||
if (selectedKey && previewContext.state) {
|
|
||||||
// It's unlikely value will ever be populated immediately as preview never has state values on load
|
if (screenChanged) {
|
||||||
editorValue = previewContext.state[selectedKey] ?? null
|
selectedKey = keyOptions[0]
|
||||||
} else {
|
componentsUsingState = []
|
||||||
|
componentsUpdatingState = []
|
||||||
editorValue = ""
|
editorValue = ""
|
||||||
|
previousScreenId = $selectedScreen._id
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedKey) {
|
||||||
|
searchComponents(selectedKey)
|
||||||
|
editorValue = previewContext.state?.[selectedKey] ?? ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,18 +206,19 @@
|
||||||
|
|
||||||
const handleStateInspectorChange = (e: CustomEvent) => {
|
const handleStateInspectorChange = (e: CustomEvent) => {
|
||||||
if (!selectedKey || !$previewStore.selectedComponentContext) {
|
if (!selectedKey || !$previewStore.selectedComponentContext) {
|
||||||
throw new Error("No state key selected")
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateUpdate = { [selectedKey]: e.detail }
|
const stateUpdate = {
|
||||||
|
[selectedKey]: e.detail,
|
||||||
|
}
|
||||||
previewStore.updateState(stateUpdate)
|
previewStore.updateState(stateUpdate)
|
||||||
previewStore.setSelectedComponentContext({
|
editorValue = e.detail
|
||||||
...$previewStore.selectedComponentContext,
|
|
||||||
state: stateUpdate,
|
|
||||||
})
|
|
||||||
previewStore.requestComponentContext()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
previewStore.requestComponentContext()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="state-panel">
|
<div class="state-panel">
|
||||||
|
@ -216,21 +226,23 @@
|
||||||
<Select
|
<Select
|
||||||
label="State variables"
|
label="State variables"
|
||||||
bind:value={selectedKey}
|
bind:value={selectedKey}
|
||||||
placeholder="Type here..."
|
placeholder={keyOptions.length > 0 ? false : "No state variables found"}
|
||||||
options={keyOptions}
|
options={keyOptions}
|
||||||
on:change={handleStateKeySelect}
|
on:change={handleStateKeySelect}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="section">
|
{#if selectedKey && keyOptions.length > 0}
|
||||||
<DrawerBindableInput
|
<div class="section">
|
||||||
value={editorValue}
|
<DrawerBindableInput
|
||||||
title={`Set value for "${selectedKey}"`}
|
value={editorValue}
|
||||||
placeholder="Enter a value"
|
title={`Set value for "${selectedKey}"`}
|
||||||
label="Set temporary value for design preview"
|
placeholder="Enter a value"
|
||||||
on:change={handleStateInspectorChange}
|
label="Set temporary value for design preview"
|
||||||
/>
|
on:change={e => handleStateInspectorChange(e)}
|
||||||
</div>
|
{bindings}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{#if componentsUsingState.length > 0}
|
{#if componentsUsingState.length > 0}
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<span class="text">Updates:</span>
|
<span class="text">Updates:</span>
|
||||||
|
@ -276,7 +288,6 @@
|
||||||
<style>
|
<style>
|
||||||
.state-panel {
|
.state-panel {
|
||||||
background-color: var(--spectrum-alias-background-color-primary);
|
background-color: var(--spectrum-alias-background-color-primary);
|
||||||
padding: var(--spacing-m);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: var(--spacing-m);
|
gap: var(--spacing-m);
|
||||||
|
@ -290,14 +301,6 @@
|
||||||
color: var(--spectrum-global-color-gray-700);
|
color: var(--spectrum-global-color-gray-700);
|
||||||
font-size: var(--spectrum-global-dimension-font-size-50);
|
font-size: var(--spectrum-global-dimension-font-size-50);
|
||||||
}
|
}
|
||||||
.error {
|
|
||||||
color: var(
|
|
||||||
--spectrum-semantic-negative-color-default,
|
|
||||||
var(--spectrum-global-color-red-500)
|
|
||||||
);
|
|
||||||
font-size: var(--spectrum-global-dimension-font-size-75);
|
|
||||||
margin-top: var(--spectrum-global-dimension-size-75);
|
|
||||||
}
|
|
||||||
|
|
||||||
.updates-colour {
|
.updates-colour {
|
||||||
color: #8488fd;
|
color: #8488fd;
|
||||||
|
|
Loading…
Reference in New Issue