Add button to fieldgroups to automatically update from schema

This commit is contained in:
Andrew Kingston 2021-02-02 17:26:14 +00:00
parent 3d5876f8bd
commit ed2ada720e
1 changed files with 19 additions and 1 deletions

View File

@ -1,7 +1,10 @@
<script> <script>
import { get } from "lodash" import { get } from "lodash"
import { isEmpty } from "lodash/fp" import { isEmpty } from "lodash/fp"
import { Button } from "@budibase/bbui"
import { currentAsset } from "builderStore"
import { findClosestMatchingComponent } from "builderStore/storeUtils"
import { makeSchemaFormComponents } from "builderStore/store/screenTemplates/utils/commonComponents"
import PropertyControl from "./PropertyControls/PropertyControl.svelte" import PropertyControl from "./PropertyControls/PropertyControl.svelte"
import Input from "./PropertyControls/Input.svelte" import Input from "./PropertyControls/Input.svelte"
import LayoutSelect from "./PropertyControls/LayoutSelect.svelte" import LayoutSelect from "./PropertyControls/LayoutSelect.svelte"
@ -94,6 +97,17 @@
const onInstanceNameChange = name => { const onInstanceNameChange = name => {
onChange("_instanceName", name) onChange("_instanceName", name)
} }
const resetFormFields = () => {
const form = findClosestMatchingComponent(
$currentAsset.props,
componentInstance._id,
component => component._component.endsWith("/form")
)
const tableId = form?.datasource?.tableId
const fields = makeSchemaFormComponents(tableId).map(field => field.json())
onChange("_children", fields)
}
</script> </script>
<div class="settings-view-container"> <div class="settings-view-container">
@ -138,6 +152,10 @@
This component doesn't have any additional settings. This component doesn't have any additional settings.
</div> </div>
{/if} {/if}
{#if componentDefinition?.component?.endsWith('/fieldgroup')}
<Button secondary wide on:click={resetFormFields}>Reset Fields</Button>
{/if}
</div> </div>
<style> <style>