Skip to content

Commit eec1051

Browse files
authored
Merge pull request #15461 from Budibase/execute-script-v2-frontend
Execute Script V2 - UX
2 parents d554796 + e19c27c commit eec1051

File tree

29 files changed

+772
-181
lines changed

29 files changed

+772
-181
lines changed

packages/builder/src/components/automation/AutomationBuilder/FlowChart/BranchNode.svelte

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
import AutomationBindingPanel from "@/components/common/bindings/ServerBindingPanel.svelte"
1919
import FlowItemHeader from "./FlowItemHeader.svelte"
2020
import FlowItemActions from "./FlowItemActions.svelte"
21-
import { automationStore, selectedAutomation } from "@/stores/builder"
22-
import { QueryUtils, Utils } from "@budibase/frontend-core"
21+
import {
22+
automationStore,
23+
selectedAutomation,
24+
evaluationContext,
25+
} from "@/stores/builder"
26+
import { QueryUtils, Utils, memo } from "@budibase/frontend-core"
2327
import { cloneDeep } from "lodash/fp"
2428
import { createEventDispatcher, getContext } from "svelte"
2529
import DragZone from "./DragZone.svelte"
@@ -34,11 +38,14 @@
3438
export let automation
3539
3640
const view = getContext("draggableView")
41+
const memoContext = memo({})
3742
3843
let drawer
3944
let open = true
4045
let confirmDeleteModal
4146
47+
$: memoContext.set($evaluationContext)
48+
4249
$: branch = step.inputs?.branches?.[branchIdx]
4350
$: editableConditionUI = branch.conditionUI || {}
4451
@@ -100,6 +107,7 @@
100107
allowOnEmpty={false}
101108
builderType={"condition"}
102109
docsURL={null}
110+
evaluationContext={$memoContext}
103111
/>
104112
</DrawerContent>
105113
</Drawer>

packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
})
3333
3434
$: groupedAutomations = groupAutomations(filteredAutomations)
35-
3635
$: showNoResults = searchString && !filteredAutomations.length
3736
3837
const groupAutomations = automations => {
@@ -41,7 +40,6 @@
4140
for (let auto of automations) {
4241
let category = null
4342
let dataTrigger = false
44-
4543
// Group by datasource if possible
4644
if (dsTriggers.includes(auto.definition?.trigger?.stepId)) {
4745
if (auto.definition.trigger.inputs?.tableId) {
@@ -97,7 +95,10 @@
9795
{triggerGroup?.name}
9896
</div>
9997
{#each triggerGroup.entries as automation}
100-
<AutomationNavItem {automation} icon={triggerGroup.icon} />
98+
<AutomationNavItem
99+
{automation}
100+
icon={automation?.definition?.trigger?.icon}
101+
/>
101102
{/each}
102103
</div>
103104
{/each}

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

+28-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
} from "@budibase/bbui"
2323
2424
import CreateWebhookModal from "@/components/automation/Shared/CreateWebhookModal.svelte"
25-
import { automationStore, tables } from "@/stores/builder"
25+
import { automationStore, tables, evaluationContext } from "@/stores/builder"
2626
import { environment } from "@/stores/portal"
2727
import WebhookDisplay from "../Shared/WebhookDisplay.svelte"
2828
import {
@@ -70,6 +70,7 @@
7070
} from "@budibase/types"
7171
import PropField from "./PropField.svelte"
7272
import { utils } from "@budibase/shared-core"
73+
import DrawerBindableCodeEditorField from "@/components/common/bindings/DrawerBindableCodeEditorField.svelte"
7374
import { API } from "@/api"
7475
import InfoDisplay from "@/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/InfoDisplay.svelte"
7576
@@ -84,6 +85,7 @@
8485
8586
// Stop unnecessary rendering
8687
const memoBlock = memo(block)
88+
const memoContext = memo({})
8789
8890
const rowTriggers = [
8991
TriggerStepID.ROW_UPDATED,
@@ -109,6 +111,7 @@
109111
let selectedRow
110112
111113
$: memoBlock.set(block)
114+
$: memoContext.set($evaluationContext)
112115
113116
$: filters = lookForFilters(schemaProperties)
114117
$: filterCount =
@@ -250,7 +253,6 @@
250253
onChange({ ["revision"]: e.detail })
251254
},
252255
updateOnChange: false,
253-
forceModal: true,
254256
},
255257
},
256258
]
@@ -278,7 +280,6 @@
278280
onChange({ [rowIdentifier]: e.detail })
279281
},
280282
updateOnChange: false,
281-
forceModal: true,
282283
},
283284
},
284285
]
@@ -569,6 +570,10 @@
569570
...update,
570571
})
571572
573+
if (!updatedAutomation) {
574+
return
575+
}
576+
572577
// Exclude default or invalid data from the test data
573578
let updatedFields = {}
574579
for (const key of Object.keys(block?.inputs?.fields || {})) {
@@ -640,7 +645,7 @@
640645
...newTestData,
641646
body: {
642647
...update,
643-
...automation.testData?.body,
648+
...(automation?.testData?.body || {}),
644649
},
645650
}
646651
}
@@ -770,6 +775,7 @@
770775
{...config.props}
771776
{bindings}
772777
on:change={config.props.onChange}
778+
context={$memoContext}
773779
bind:searchTerm={rowSearchTerm}
774780
/>
775781
</PropField>
@@ -779,6 +785,7 @@
779785
{...config.props}
780786
{bindings}
781787
on:change={config.props.onChange}
788+
context={$memoContext}
782789
/>
783790
{/if}
784791
{/each}
@@ -903,6 +910,7 @@
903910
: "Add signature"}
904911
keyPlaceholder={"URL"}
905912
valuePlaceholder={"Filename"}
913+
context={$memoContext}
906914
/>
907915
{:else if isTestModal}
908916
<ModalBindableInput
@@ -927,6 +935,7 @@
927935
? queryLimit
928936
: ""}
929937
drawerLeft="260px"
938+
context={$memoContext}
930939
/>
931940
{/if}
932941
</div>
@@ -956,6 +965,7 @@
956965
panel={AutomationBindingPanel}
957966
showFilterEmptyDropdown={!rowTriggers.includes(stepId)}
958967
on:change={e => (tempFilters = e.detail)}
968+
evaluationContext={$memoContext}
959969
/>
960970
</DrawerContent>
961971
</Drawer>
@@ -998,7 +1008,19 @@
9981008
on:change={e => onChange({ [key]: e.detail })}
9991009
value={inputData[key]}
10001010
/>
1001-
{:else if value.customType === "code"}
1011+
{:else if value.customType === "code" && stepId === ActionStepID.EXECUTE_SCRIPT_V2}
1012+
<div class="scriptv2-wrapper">
1013+
<DrawerBindableCodeEditorField
1014+
{bindings}
1015+
{schema}
1016+
panel={AutomationBindingPanel}
1017+
on:change={e => onChange({ [key]: e.detail })}
1018+
context={$memoContext}
1019+
value={inputData[key]}
1020+
/>
1021+
</div>
1022+
{:else if value.customType === "code" && stepId === ActionStepID.EXECUTE_SCRIPT}
1023+
<!-- DEPRECATED -->
10021024
<CodeEditorModal
10031025
on:hide={() => {
10041026
// Push any pending changes when the window closes
@@ -1080,6 +1102,7 @@
10801102
? queryLimit
10811103
: ""}
10821104
drawerLeft="260px"
1105+
context={$memoContext}
10831106
/>
10841107
</div>
10851108
{/if}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
export let meta
2626
export let bindings
2727
export let isTestModal
28+
export let context = {}
2829
2930
const typeToField = Object.values(FIELDS).reduce((acc, field) => {
3031
acc[field.type] = field
@@ -58,7 +59,7 @@
5859
5960
$: parsedBindings = bindings.map(binding => {
6061
let clone = Object.assign({}, binding)
61-
clone.icon = "ShareAndroid"
62+
clone.icon = clone.icon ?? "ShareAndroid"
6263
return clone
6364
})
6465
@@ -258,6 +259,7 @@
258259
fields: editableFields,
259260
}}
260261
{onChange}
262+
{context}
261263
/>
262264
{:else}
263265
<DrawerBindableSlot
@@ -276,6 +278,7 @@
276278
allowJS={true}
277279
updateOnChange={false}
278280
drawerLeft="260px"
281+
{context}
279282
>
280283
<RowSelectorTypes
281284
{isTestModal}
@@ -286,6 +289,7 @@
286289
meta={{
287290
fields: editableFields,
288291
}}
292+
{context}
289293
onChange={change => onChange(change)}
290294
/>
291295
</DrawerBindableSlot>

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
export let meta
2626
export let bindings
2727
export let isTestModal
28+
export let context
2829
2930
$: fieldData = value[field]
3031
3132
$: parsedBindings = bindings.map(binding => {
3233
let clone = Object.assign({}, binding)
33-
clone.icon = "ShareAndroid"
34+
clone.icon = clone.icon ?? "ShareAndroid"
3435
return clone
3536
})
3637
@@ -232,6 +233,7 @@
232233
actionButtonDisabled={(schema.type === FieldType.ATTACHMENT_SINGLE ||
233234
schema.type === FieldType.SIGNATURE_SINGLE) &&
234235
fieldData}
236+
{context}
235237
/>
236238
</div>
237239
{:else}

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

+56-22
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
<script>
22
import { Input, Select, Button } from "@budibase/bbui"
33
import { createEventDispatcher } from "svelte"
4-
5-
const dispatch = createEventDispatcher()
4+
import { memo } from "@budibase/frontend-core"
5+
import { generate } from "shortid"
66
77
export let value = {}
88
9-
$: fieldsArray = value
10-
? Object.entries(value).map(([name, type]) => ({
11-
name,
12-
type,
13-
}))
14-
: []
15-
169
const typeOptions = [
1710
{
1811
label: "Text",
@@ -36,16 +29,42 @@
3629
},
3730
]
3831
32+
const dispatch = createEventDispatcher()
33+
const memoValue = memo({ data: {} })
34+
35+
$: memoValue.set({ data: value })
36+
37+
$: fieldsArray = $memoValue.data
38+
? Object.entries($memoValue.data).map(([name, type]) => ({
39+
name,
40+
type,
41+
id: generate(),
42+
}))
43+
: []
44+
3945
function addField() {
40-
const newValue = { ...value }
46+
const newValue = { ...$memoValue.data }
4147
newValue[""] = "string"
42-
dispatch("change", newValue)
48+
fieldsArray = [...fieldsArray, { name: "", type: "string", id: generate() }]
4349
}
4450
45-
function removeField(name) {
46-
const newValues = { ...value }
47-
delete newValues[name]
48-
dispatch("change", newValues)
51+
function removeField(idx) {
52+
const entries = [...fieldsArray]
53+
54+
// Remove empty field
55+
if (!entries[idx]?.name) {
56+
fieldsArray.splice(idx, 1)
57+
fieldsArray = [...fieldsArray]
58+
return
59+
}
60+
61+
entries.splice(idx, 1)
62+
63+
const update = entries.reduce((newVals, current) => {
64+
newVals[current.name.trim()] = current.type
65+
return newVals
66+
}, {})
67+
dispatch("change", update)
4968
}
5069
5170
const fieldNameChanged = originalName => e => {
@@ -57,19 +76,24 @@
5776
} else {
5877
entries = entries.filter(f => f.name !== originalName)
5978
}
60-
value = entries.reduce((newVals, current) => {
61-
newVals[current.name.trim()] = current.type
62-
return newVals
63-
}, {})
64-
dispatch("change", value)
79+
80+
const update = entries
81+
.filter(entry => entry.name)
82+
.reduce((newVals, current) => {
83+
newVals[current.name.trim()] = current.type
84+
return newVals
85+
}, {})
86+
if (Object.keys(update).length) {
87+
dispatch("change", update)
88+
}
6589
}
6690
</script>
6791
6892
<!-- svelte-ignore a11y-click-events-have-key-events -->
6993
<!-- svelte-ignore a11y-no-static-element-interactions -->
7094
<div class="root">
7195
<div class="spacer" />
72-
{#each fieldsArray as field}
96+
{#each fieldsArray as field, idx (field.id)}
7397
<div class="field">
7498
<Input
7599
value={field.name}
@@ -88,7 +112,9 @@
88112
/>
89113
<i
90114
class="remove-field ri-delete-bin-line"
91-
on:click={() => removeField(field.name)}
115+
on:click={() => {
116+
removeField(idx)
117+
}}
92118
/>
93119
</div>
94120
{/each}
@@ -115,4 +141,12 @@
115141
align-items: center;
116142
gap: var(--spacing-m);
117143
}
144+
145+
.remove-field {
146+
cursor: pointer;
147+
}
148+
149+
.remove-field:hover {
150+
color: var(--spectrum-global-color-gray-900);
151+
}
118152
</style>

0 commit comments

Comments
 (0)