1
0
Fork 0
mirror of synced 2024-09-25 13:51:40 +12:00

Merge pull request #14629 from Budibase/fixes/automation-bug-fixing

Some bug fixes
This commit is contained in:
Peter Clement 2024-09-24 14:00:51 +01:00 committed by GitHub
commit b005150622
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 31 deletions

View file

@ -16,9 +16,11 @@
export let enableNaming = true export let enableNaming = true
let validRegex = /^[A-Za-z0-9_\s]+$/ let validRegex = /^[A-Za-z0-9_\s]+$/
let typing = false let typing = false
let editing = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: stepNames = $selectedAutomation?.definition.stepNames $: stepNames = $selectedAutomation?.definition.stepNames
$: allSteps = $selectedAutomation?.definition.steps || []
$: automationName = stepNames?.[block.id] || block?.name || "" $: automationName = stepNames?.[block.id] || block?.name || ""
$: automationNameError = getAutomationNameError(automationName) $: automationNameError = getAutomationNameError(automationName)
$: status = updateStatus(testResult) $: status = updateStatus(testResult)
@ -56,10 +58,18 @@
} }
} }
const getAutomationNameError = name => { const getAutomationNameError = name => {
if (stepNames) { const duplicateError =
"This name already exists, please enter a unique name"
if (stepNames && editing) {
for (const [key, value] of Object.entries(stepNames)) { for (const [key, value] of Object.entries(stepNames)) {
if (name === value && key !== block.id) { if (name !== block.name && name === value && key !== block.id) {
return "This name already exists, please enter a unique name" return duplicateError
}
}
for (const step of allSteps) {
if (step.id !== block.id && name === step.name) {
return duplicateError
} }
} }
} }
@ -67,15 +77,11 @@
if (name !== block.name && name?.length > 0) { if (name !== block.name && name?.length > 0) {
let invalidRoleName = !validRegex.test(name) let invalidRoleName = !validRegex.test(name)
if (invalidRoleName) { if (invalidRoleName) {
return "Please enter a role name consisting of only alphanumeric symbols and underscores" return "Please enter a name consisting of only alphanumeric symbols and underscores"
} }
return null
} }
}
const startTyping = async () => { return null
typing = true
} }
const saveName = async () => { const saveName = async () => {
@ -89,13 +95,28 @@
await automationStore.actions.saveAutomationName(block.id, automationName) await automationStore.actions.saveAutomationName(block.id, automationName)
} }
} }
const startEditing = () => {
editing = true
typing = true
}
const stopEditing = async () => {
editing = false
typing = false
if (automationNameError) {
automationName = stepNames[block.id] || block?.name
} else {
await saveName()
}
}
</script> </script>
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<div <div
class:typing={typing && !automationNameError} class:typing={typing && !automationNameError && editing}
class:typing-error={automationNameError} class:typing-error={automationNameError && editing}
class="blockSection" class="blockSection"
on:click={() => dispatch("toggle")} on:click={() => dispatch("toggle")}
> >
@ -132,7 +153,7 @@
<input <input
class="input-text" class="input-text"
disabled={!enableNaming} disabled={!enableNaming}
placeholder="Enter some text" placeholder="Enter step name"
name="name" name="name"
autocomplete="off" autocomplete="off"
value={automationName} value={automationName}
@ -141,26 +162,14 @@
}} }}
on:click={e => { on:click={e => {
e.stopPropagation() e.stopPropagation()
startTyping() startEditing()
}} }}
on:keydown={async e => { on:keydown={async e => {
if (e.key === "Enter") { if (e.key === "Enter") {
typing = false await stopEditing()
if (automationNameError) {
automationName = stepNames[block.id] || block?.name
} else {
await saveName()
}
}
}}
on:blur={async () => {
typing = false
if (automationNameError) {
automationName = stepNames[block.id] || block?.name
} else {
await saveName()
} }
}} }}
on:blur={stopEditing}
/> />
{:else} {:else}
<div class="input-text"> <div class="input-text">
@ -222,7 +231,7 @@
/> />
{/if} {/if}
</div> </div>
{#if automationNameError} {#if automationNameError && editing}
<div class="error-container"> <div class="error-container">
<AbsTooltip type="negative" text={automationNameError}> <AbsTooltip type="negative" text={automationNameError}>
<div class="error-icon"> <div class="error-icon">

View file

@ -643,8 +643,8 @@
runtimeName = `loop.${name}` runtimeName = `loop.${name}`
} else if (block.name.startsWith("JS")) { } else if (block.name.startsWith("JS")) {
runtimeName = hasUserDefinedName runtimeName = hasUserDefinedName
? `stepsByName[${bindingName}].${name}` ? `stepsByName["${bindingName}"].${name}`
: `steps[${idx - loopBlockCount}].${name}` : `steps["${idx - loopBlockCount}"].${name}`
} else { } else {
runtimeName = hasUserDefinedName runtimeName = hasUserDefinedName
? `stepsByName.${bindingName}.${name}` ? `stepsByName.${bindingName}.${name}`
@ -752,13 +752,21 @@
: allSteps[idx].icon : allSteps[idx].icon
if (wasLoopBlock) { if (wasLoopBlock) {
loopBlockCount++
schema = cloneDeep(allSteps[idx - 1]?.schema?.outputs?.properties) schema = cloneDeep(allSteps[idx - 1]?.schema?.outputs?.properties)
} }
Object.entries(schema).forEach(([name, value]) => { Object.entries(schema).forEach(([name, value]) => {
addBinding(name, value, icon, idx, isLoopBlock, bindingName) addBinding(name, value, icon, idx, isLoopBlock, bindingName)
}) })
} }
if (
allSteps[blockIdx - 1]?.stepId !== ActionStepID.LOOP &&
allSteps
.slice(0, blockIdx)
.some(step => step.stepId === ActionStepID.LOOP)
) {
bindings = bindings.filter(x => !x.readableBinding.includes("loop"))
}
return bindings return bindings
} }