tweaking around user default values
This commit is contained in:
parent
1074850538
commit
417631c7dc
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ActionButton, Popover, Divider, Icon, Select } from "@budibase/bbui"
|
import { Divider, Select, Heading } from "@budibase/bbui"
|
||||||
import { getAllStateVariables } from "@/dataBinding"
|
import { getAllStateVariables } from "@/dataBinding"
|
||||||
import {
|
import {
|
||||||
componentStore,
|
componentStore,
|
||||||
|
@ -14,6 +14,7 @@
|
||||||
} from "@budibase/string-templates"
|
} from "@budibase/string-templates"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import CodeMirrorEditor from "@/components/common/CodeMirrorEditor.svelte"
|
import CodeMirrorEditor from "@/components/common/CodeMirrorEditor.svelte"
|
||||||
|
|
||||||
type ComponentUsingState = {
|
type ComponentUsingState = {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
let componentsUsingState: ComponentUsingState[] = []
|
let componentsUsingState: ComponentUsingState[] = []
|
||||||
let componentsUpdatingState: ComponentUsingState[] = []
|
let componentsUpdatingState: ComponentUsingState[] = []
|
||||||
let editorValue: string = ""
|
let editorValue: string = ""
|
||||||
|
let editorError: string | null = null
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (selectedKey) {
|
if (selectedKey) {
|
||||||
|
@ -35,16 +37,19 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
let previewContext = $previewStore.selectedComponentContext || {}
|
const previewContext = $previewStore.selectedComponentContext || {}
|
||||||
|
|
||||||
if (selectedKey && previewContext.state) {
|
if (selectedKey && previewContext.state) {
|
||||||
// It's unlikely value will ever be populated immediately as state is never populated automatically in preview
|
// It's unlikely value will ever be populated immediately as state is never populated automatically in preview
|
||||||
const value = previewContext.state[selectedKey] ?? null
|
const value = previewContext.state[selectedKey] ?? null
|
||||||
editorValue = JSON.stringify(value, null, 2)
|
editorValue = JSON.stringify(value, null, 2)
|
||||||
|
editorError = null
|
||||||
} else {
|
} else {
|
||||||
editorValue = ""
|
editorValue = ""
|
||||||
|
editorError = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findComponentsUpdatingState(
|
function findComponentsUpdatingState(
|
||||||
component: any,
|
component: any,
|
||||||
stateKey: string
|
stateKey: string
|
||||||
|
@ -79,7 +84,6 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundComponents
|
return foundComponents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,25 +172,30 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = JSON.parse(e.detail)
|
try {
|
||||||
const stateUpdate = { [selectedKey]: value }
|
const value = JSON.parse(e.detail)
|
||||||
|
const stateUpdate = { [selectedKey]: value }
|
||||||
|
editorError = null
|
||||||
|
|
||||||
previewStore.updateState(stateUpdate)
|
previewStore.updateState(stateUpdate)
|
||||||
|
previewStore.updateState(stateUpdate)
|
||||||
|
|
||||||
previewStore.setSelectedComponentContext({
|
previewStore.updateState(stateUpdate)
|
||||||
...$previewStore.selectedComponentContext,
|
|
||||||
state: stateUpdate,
|
|
||||||
})
|
|
||||||
|
|
||||||
previewStore.requestComponentContext()
|
previewStore.setSelectedComponentContext({
|
||||||
|
...$previewStore.selectedComponentContext,
|
||||||
|
state: stateUpdate,
|
||||||
|
})
|
||||||
|
previewStore.requestComponentContext()
|
||||||
|
} catch (err) {
|
||||||
|
editorError = "Invalid JSON value"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="state-panel">
|
<div class="state-panel">
|
||||||
<div>State</div>
|
<Heading size="S">State</Heading>
|
||||||
<div>
|
<div>Showing state variables for this screen</div>
|
||||||
Showing state variables for {$selectedScreen?.routing?.route.split("/")[1]}:
|
|
||||||
</div>
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<Select
|
<Select
|
||||||
value={selectedKey}
|
value={selectedKey}
|
||||||
|
@ -204,6 +213,9 @@
|
||||||
label="State Inspector"
|
label="State Inspector"
|
||||||
on:change={handleStateInspectorChange}
|
on:change={handleStateInspectorChange}
|
||||||
/>
|
/>
|
||||||
|
{#if editorError}
|
||||||
|
<div class="error">{editorError}</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
|
@ -211,29 +223,26 @@
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<span class="text">Updates:</span>
|
<span class="text">Updates:</span>
|
||||||
{#each componentsUsingState as component, i}
|
{#each componentsUsingState as component, i}
|
||||||
|
{#if i > 0}{", "}{/if}
|
||||||
<button
|
<button
|
||||||
class="component-link"
|
class="component-link"
|
||||||
on:click={() => onClickComponentLink(component)}
|
on:click={() => onClickComponentLink(component)}
|
||||||
>
|
>
|
||||||
{component.name}{i < componentsUsingState.length - 1 ? ", " : ""}
|
{component.name}
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if componentsUpdatingState.length > 0}
|
{#if componentsUpdatingState.length > 0}
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<span class="text">Updated by:</span>
|
<span class="text">Controlled by:</span>
|
||||||
{#each componentsUpdatingState as component, i}
|
{#each componentsUpdatingState as component, i}
|
||||||
|
{#if i > 0}{", "}{/if}
|
||||||
<button
|
<button
|
||||||
class="component-link"
|
class="component-link"
|
||||||
on:click={() =>
|
on:click={() => onClickComponentLink(component)}
|
||||||
onClickComponentLink({
|
|
||||||
id: component.id,
|
|
||||||
name: component.name,
|
|
||||||
settings: component.settings,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
{component.name}{i < componentsUpdatingState.length - 1 ? ", " : ""}
|
{component.name}
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
@ -255,6 +264,14 @@
|
||||||
color: var(--spectrum-global-color-gray-700);
|
color: var(--spectrum-global-color-gray-700);
|
||||||
font-size: var(--spectrum-global-dimension-font-size-75);
|
font-size: var(--spectrum-global-dimension-font-size-75);
|
||||||
}
|
}
|
||||||
|
.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);
|
||||||
|
}
|
||||||
.component-link {
|
.component-link {
|
||||||
display: inline;
|
display: inline;
|
||||||
border: none;
|
border: none;
|
||||||
|
@ -268,10 +285,4 @@
|
||||||
.component-link:hover {
|
.component-link:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.split-title {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue