Skip to content

Commit b9f3c5b

Browse files
committed
Fix: Prevent overwrite of already-present properties
Handle the case as described in #125 Closes #125
1 parent 3a41540 commit b9f3c5b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib/components/workflow/common/NewEntryProperty.svelte

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
const entryType = typeof entry
4343
const isArray = Array.isArray(entry)
4444
if (entryType === 'object' && !isArray) {
45+
// Check that the property name is not already used
46+
if (Object.hasOwn(entry, propertyName)) {
47+
const error = document.getElementById('submitEntryError')
48+
error.textContent = `Property name "${propertyName}" is already used`
49+
const input = document.getElementById('submitEntryName')
50+
input.classList.add('is-invalid')
51+
return
52+
}
4553
entry[propertyName] = propertyValue
4654
} else if (isArray) {
4755
entry.push(propertyValue)
@@ -76,7 +84,7 @@
7684
<form id={uuid} on:submit|preventDefault={handleSubmitEntry}>
7785
<div class="input-group mb-3">
7886
{#if !isListItem}
79-
<input type="text" class="form-control" placeholder="Arg name" bind:value={propertyName} required>
87+
<input id="submitEntryName" type="text" class="form-control" placeholder="Arg name" bind:value={propertyName} required>
8088
{/if}
8189
{#if propertyType === 'string' }
8290
<input type="text" class="form-control w-50 font-monospace" placeholder="Argument default value" bind:value={propertyValue}>
@@ -95,6 +103,8 @@
95103
<option value="object">Object</option>
96104
<option value="array">Array</option>
97105
</select>
106+
<div id="submitEntryError" class="invalid-feedback">
107+
</div>
98108
</div>
99109
</form>
100110
</div>

0 commit comments

Comments
 (0)