Improve editor refresh on delete

This commit is contained in:
Mel O'Hagan 2022-10-04 10:18:16 +01:00
parent b3d549a170
commit 91db8f10ab
1 changed files with 21 additions and 13 deletions

View File

@ -24,6 +24,8 @@
export let editable = true export let editable = true
export let height = 500 export let height = 500
let flowEditors = []
$: urlDisplay = $: urlDisplay =
schema.urlDisplay && schema.urlDisplay &&
`${datasource.config.url}${ `${datasource.config.url}${
@ -33,6 +35,12 @@
function updateQuery({ detail }) { function updateQuery({ detail }) {
query.fields[schema.type] = detail.value query.fields[schema.type] = detail.value
} }
function updateEditors(deleteIndex) {
for (let i = deleteIndex; i < query.fields.steps?.length - 1; i++) {
flowEditors[i].update(query.fields.steps[i + 1].value.value)
}
}
</script> </script>
{#if schema} {#if schema}
@ -93,8 +101,9 @@
Stage {index + 1} Stage {index + 1}
<ActionButton <ActionButton
on:click={() => { on:click={() => {
updateEditors(index)
query.fields.steps.splice(index, 1) query.fields.steps.splice(index, 1)
query.fields.steps = query.fields.steps query.fields.steps = [...query.fields.steps]
}} }}
icon="DeleteOutline" icon="DeleteOutline"
/> />
@ -108,18 +117,17 @@
query.fields.steps[index].key = detail query.fields.steps[index].key = detail
}} }}
/> />
{#key query.fields.steps.length} <Editor
<Editor bind:this={flowEditors[index]}
editorHeight={height / 2} editorHeight={height / 2}
mode="json" mode="json"
value={typeof step.value === "string" value={typeof step.value === "string"
? step.value ? step.value
: step.value.value} : step.value.value}
on:change={({ detail }) => { on:change={({ detail }) => {
query.fields.steps[index].value = detail query.fields.steps[index].value = detail
}} }}
/> />
{/key}
</div> </div>
</div> </div>
</Layout> </Layout>