Update form block to be ejectable

This commit is contained in:
Andrew Kingston 2022-08-25 09:24:27 +01:00
parent 8d76959f88
commit 10a251f1f6
2 changed files with 118 additions and 91 deletions

View File

@ -4402,6 +4402,7 @@
"type": "text", "type": "text",
"label": "Row ID", "label": "Row ID",
"key": "rowId", "key": "rowId",
"nested": true,
"dependsOn": { "dependsOn": {
"setting": "actionType", "setting": "actionType",
"value": "Create", "value": "Create",

View File

@ -83,7 +83,7 @@
operator: "equal", operator: "equal",
type: "string", type: "string",
value: rowId, value: rowId,
valueType: "binding", valueType: "Binding",
}, },
] ]
// If we're using an "update" form, use the real data provider. If we're // If we're using an "update" form, use the real data provider. If we're
@ -93,6 +93,10 @@
actionType !== "Create" actionType !== "Create"
? `{{ literal ${safe(providerId)} }}` ? `{{ literal ${safe(providerId)} }}`
: { rows: [{}] } : { rows: [{}] }
$: renderDeleteButton = showDeleteButton && actionType === "Update"
$: renderSaveButton = showSaveButton && actionType !== "View"
$: renderButtons = renderDeleteButton || renderSaveButton
$: renderHeader = renderButtons || title
const fetchSchema = async () => { const fetchSchema = async () => {
schema = (await fetchDatasourceSchema(dataSource)) || {} schema = (await fetchDatasourceSchema(dataSource)) || {}
@ -108,7 +112,6 @@
</script> </script>
<Block> <Block>
<div use:styleable={$component.styles}>
{#if fields?.length} {#if fields?.length}
<BlockComponent <BlockComponent
type="dataprovider" type="dataprovider"
@ -141,11 +144,47 @@
context="form" context="form"
bind:id={formId} bind:id={formId}
> >
<Layout noPadding gap="M"> <BlockComponent
<div class="title" class:with-text={!!title}> type="container"
<BlockComponent type="heading" props={{ text: title || "" }} /> props={{
<div class="buttons"> direction: "column",
{#if showDeleteButton && actionType === "Update"} hAlign: "stretch",
vAlign: "top",
gap: "M",
}}
>
{#if renderHeader}
<BlockComponent
type="container"
props={{
direction: "row",
hAlign: title ? "stretch" : "right",
vAlign: "center",
gap: "M",
wrap: true,
}}
order={0}
>
{#if title}
<BlockComponent
type="heading"
props={{ text: title }}
order={0}
/>
{/if}
{#if renderButtons}
<BlockComponent
type="container"
props={{
direction: "row",
hAlign: "stretch",
vAlign: "center",
gap: "M",
wrap: true,
}}
order={1}
>
{#if renderDeleteButton}
<BlockComponent <BlockComponent
type="button" type="button"
props={{ props={{
@ -154,9 +193,10 @@
quiet: true, quiet: true,
type: "secondary", type: "secondary",
}} }}
order={0}
/> />
{/if} {/if}
{#if showSaveButton && actionType !== "View"} {#if renderSaveButton}
<BlockComponent <BlockComponent
type="button" type="button"
props={{ props={{
@ -164,12 +204,19 @@
onClick: onSave, onClick: onSave,
type: "cta", type: "cta",
}} }}
order={1}
/> />
{/if} {/if}
</div> </BlockComponent>
</div> {/if}
<BlockComponent type="fieldgroup" props={{ labelPosition }}> </BlockComponent>
{#each fields as field} {/if}
<BlockComponent
type="fieldgroup"
props={{ labelPosition }}
order={1}
>
{#each fields as field, idx}
{#if getComponentForField(field)} {#if getComponentForField(field)}
<BlockComponent <BlockComponent
type={getComponentForField(field)} type={getComponentForField(field)}
@ -179,11 +226,12 @@
placeholder: field, placeholder: field,
disabled, disabled,
}} }}
order={idx}
/> />
{/if} {/if}
{/each} {/each}
</BlockComponent> </BlockComponent>
</Layout> </BlockComponent>
</BlockComponent> </BlockComponent>
</BlockComponent> </BlockComponent>
</BlockComponent> </BlockComponent>
@ -192,26 +240,4 @@
text="Choose your table and add some fields to your form to get started" text="Choose your table and add some fields to your form to get started"
/> />
{/if} {/if}
</div>
</Block> </Block>
<style>
.title {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
gap: var(--spacing-m);
order: 2;
}
.title.with-text {
order: 0;
}
.buttons {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
gap: var(--spacing-m);
}
</style>