1
0
Fork 0
mirror of synced 2024-09-29 08:41:16 +13:00

Update form block to be ejectable

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

View file

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

View file

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