Skip to content

Commit ca0630c

Browse files
authored
Merge pull request #15545 from Budibase/execute-script-tweaks
Pull out new code editor field and drawer bindable slot into single component
2 parents 84cee75 + 75a0ded commit ca0630c

File tree

5 files changed

+79
-52
lines changed

5 files changed

+79
-52
lines changed

packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte

+6-44
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@
6262
} from "@budibase/types"
6363
import PropField from "./PropField.svelte"
6464
import { utils } from "@budibase/shared-core"
65-
import { encodeJSBinding } from "@budibase/string-templates"
66-
import CodeEditorField from "@/components/common/bindings/CodeEditorField.svelte"
65+
import DrawerBindableCodeEditorField from "@/components/common/bindings/DrawerBindableCodeEditorField.svelte"
6766
6867
export let automation
6968
export let block
@@ -908,32 +907,14 @@
908907
/>
909908
{:else if value.customType === "code" && stepId === ActionStepID.EXECUTE_SCRIPT_V2}
910909
<div class="scriptv2-wrapper">
911-
<DrawerBindableSlot
912-
title={"Edit Code"}
913-
panel={AutomationBindingPanel}
914-
type={"longform"}
910+
<DrawerBindableCodeEditorField
911+
{bindings}
915912
{schema}
913+
panel={AutomationBindingPanel}
916914
on:change={e => onChange({ [key]: e.detail })}
917-
value={inputData[key]}
918-
{bindings}
919-
allowJS={true}
920-
allowHBS={false}
921-
updateOnChange={false}
922915
context={$memoContext}
923-
>
924-
<div class="field-wrap code-editor">
925-
<CodeEditorField
926-
value={inputData[key]}
927-
{bindings}
928-
context={$memoContext}
929-
allowHBS={false}
930-
allowJS
931-
placeholder={"Add bindings by typing $"}
932-
on:blur={e =>
933-
onChange({ [key]: encodeJSBinding(e.detail) })}
934-
/>
935-
</div>
936-
</DrawerBindableSlot>
916+
value={inputData[key]}
917+
/>
937918
</div>
938919
{:else if value.customType === "code" && stepId === ActionStepID.EXECUTE_SCRIPT}
939920
<!-- DEPRECATED -->
@@ -1086,23 +1067,4 @@
10861067
flex: 3;
10871068
margin-top: calc((var(--spacing-xl) * -1) + 1px);
10881069
}
1089-
1090-
.field-wrap :global(.cm-editor),
1091-
.field-wrap :global(.cm-scroller) {
1092-
border-radius: 4px;
1093-
}
1094-
.field-wrap {
1095-
box-sizing: border-box;
1096-
border: 1px solid var(--spectrum-global-color-gray-400);
1097-
border-radius: 4px;
1098-
}
1099-
.field-wrap.code-editor {
1100-
height: 180px;
1101-
}
1102-
.scriptv2-wrapper :global(.icon.slot-icon) {
1103-
top: 1px;
1104-
border-bottom-left-radius: var(--spectrum-alias-border-radius-regular);
1105-
border-right: 0px;
1106-
border-bottom: 1px solid var(--spectrum-alias-border-color);
1107-
}
11081070
</style>

packages/builder/src/components/common/bindings/BindingPanel.svelte

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
let mode: BindingMode | null
6262
let sidePanel: SidePanel | null
6363
let initialValueJS = value?.startsWith?.("{{ js ")
64+
let jsValue = initialValueJS ? value : null
65+
let hbsValue = initialValueJS ? null : value
6466
let getCaretPosition: CaretPositionFn | undefined
6567
let insertAtPos: InsertAtPositionFn | undefined
6668
let targetMode: BindingMode | null = null
@@ -69,10 +71,6 @@
6971
let expressionError: string | undefined
7072
let evaluating = false
7173
72-
// Ensure these values are not stale
73-
$: jsValue = initialValueJS ? value : null
74-
$: hbsValue = initialValueJS ? null : value
75-
7674
$: useSnippets = allowSnippets && !$licensing.isFreePlan
7775
$: editorModeOptions = getModeOptions(allowHBS, allowJS)
7876
$: sidePanelOptions = getSidePanelOptions(

packages/builder/src/components/common/bindings/CodeEditorField.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
export let context = null
3737
export let autofocusEditor = false
3838
export let placeholder = null
39+
export let height = 180
3940
4041
let getCaretPosition: CaretPositionFn | undefined
4142
let insertAtPos: InsertAtPositionFn | undefined
@@ -131,7 +132,7 @@
131132
}
132133
</script>
133134

134-
<div class="code-panel">
135+
<div class="code-panel" style="height:{height}px;">
135136
<div class="editor">
136137
{#key jsCompletions}
137138
<CodeEditor
@@ -154,7 +155,6 @@
154155

155156
<style>
156157
.code-panel {
157-
height: 100%;
158158
display: flex;
159159
}
160160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<script>
2+
import { createEventDispatcher } from "svelte"
3+
import {
4+
ClientBindingPanel,
5+
DrawerBindableSlot,
6+
} from "@/components/common/bindings"
7+
import CodeEditorField from "@/components/common/bindings/CodeEditorField.svelte"
8+
9+
export let value = ""
10+
export let panel = ClientBindingPanel
11+
export let schema = null
12+
export let bindings = []
13+
export let context = {}
14+
export let height = 180
15+
16+
const dispatch = createEventDispatcher()
17+
</script>
18+
19+
<div class="wrapper">
20+
<DrawerBindableSlot
21+
{panel}
22+
{schema}
23+
{value}
24+
{bindings}
25+
{context}
26+
title="Edit Code"
27+
type="longform"
28+
allowJS={true}
29+
allowHBS={false}
30+
updateOnChange={false}
31+
on:change={e => {
32+
value = e.detail
33+
dispatch("change", value)
34+
}}
35+
>
36+
<div class="code-editor-wrapper">
37+
<CodeEditorField
38+
{value}
39+
{bindings}
40+
{context}
41+
{height}
42+
allowHBS={false}
43+
allowJS
44+
placeholder={"Add bindings by typing $"}
45+
on:change={e => (value = e.detail)}
46+
on:blur={() => dispatch("change", value)}
47+
/>
48+
</div>
49+
</DrawerBindableSlot>
50+
</div>
51+
52+
<style>
53+
.wrapper :global(.icon.slot-icon) {
54+
top: 1px;
55+
border-radius: 0 4px 0 4px;
56+
border-right: 0;
57+
border-bottom: 1px solid var(--spectrum-alias-border-color);
58+
}
59+
.wrapper :global(.cm-editor),
60+
.wrapper :global(.cm-scroller) {
61+
border-radius: 4px;
62+
}
63+
.code-editor-wrapper {
64+
box-sizing: border-box;
65+
border: 1px solid var(--spectrum-global-color-gray-400);
66+
border-radius: 4px;
67+
}
68+
</style>

packages/builder/src/components/common/bindings/DrawerBindableSlot.svelte

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
export let updateOnChange = true
2323
export let type
2424
export let schema
25-
2625
export let allowHBS = true
2726
export let context = {}
2827
@@ -174,7 +173,7 @@
174173
{:else}
175174
<slot />
176175
{/if}
177-
{#if !disabled && type !== "formula" && !disabled && !attachmentTypes.includes(type)}
176+
{#if !disabled && type !== "formula" && !attachmentTypes.includes(type)}
178177
<div
179178
class={`icon ${getIconClass(value, type)}`}
180179
on:click={() => {

0 commit comments

Comments
 (0)