Fix: studio now handles arrays better (might fix #2102)

This commit is contained in:
Pieter Vander Vennet 2024-09-24 13:13:08 +02:00
parent e09af8fcb9
commit 0c9e41a6ce
3 changed files with 14 additions and 10 deletions

View file

@ -39,16 +39,20 @@
} }
function fusePath(subpartPath: string[]): (string | number)[] { function fusePath(subpartPath: string[]): (string | number)[] {
const newPath = [...path] const newPath = [...path] // has indices, e.g. ["A", 1, "B", "C", 2]
const toAdd = [...subpartPath] const toAdd = [...subpartPath] // doesn't have indices, e.g. ["A", "B", "C", "D"]
for (const part of path) {
if (toAdd[0] === part) { let indexInToAdd = 0
toAdd.splice(0, 1) for (let i = 0; i < newPath.length; i++) {
} else { if(newPath[i] === toAdd[indexInToAdd]){
break indexInToAdd ++
} }
} }
newPath.push(...toAdd)
// indexToAdd should now point to the last common index, '2' in the example
const resting = toAdd.slice(indexInToAdd)
newPath.push(...resting)
return newPath return newPath
} }

View file

@ -204,7 +204,7 @@ export abstract class EditJsonState<T> {
for (let i = 0; i < path.length - 1; i++) { for (let i = 0; i < path.length - 1; i++) {
const breadcrumb = path[i] const breadcrumb = path[i]
if (entry[breadcrumb] === undefined) { if (entry[breadcrumb] === undefined || entry[breadcrumb] === null) {
if (isUndefined) { if (isUndefined) {
// we have a dead end _and_ we do not need to set a value - we do an early return // we have a dead end _and_ we do not need to set a value - we do an early return
return return

View file

@ -105,7 +105,7 @@
</div> </div>
{/each} {/each}
{:else} {:else}
<Accordion> <Accordion> <!-- The CollapsedTagRenderingPreview contains the accordeon items -->
{#each $currentValue as value, i} {#each $currentValue as value, i}
<CollapsedTagRenderingPreview <CollapsedTagRenderingPreview
{state} {state}