Convert form block
This commit is contained in:
parent
c4eb29fcdb
commit
f74e2c6693
|
@ -1,12 +1,14 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import InnerFormBlock from "./InnerFormBlock.svelte"
|
import InnerFormBlock from "./InnerFormBlock.svelte"
|
||||||
import { Utils } from "@budibase/frontend-core"
|
import { Utils } from "@budibase/frontend-core"
|
||||||
import FormBlockWrapper from "./FormBlockWrapper.svelte"
|
import FormBlockWrapper from "./FormBlockWrapper.svelte"
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
|
import { Component, Context, SDK } from "../../../../index"
|
||||||
|
import { TableSchema, UIDatasource } from "@budibase/types"
|
||||||
|
|
||||||
export let actionType
|
export let actionType
|
||||||
export let dataSource
|
export let dataSource: UIDatasource
|
||||||
export let size
|
export let size
|
||||||
export let disabled
|
export let disabled
|
||||||
export let fields
|
export let fields
|
||||||
|
@ -27,11 +29,11 @@
|
||||||
export let saveButtonLabel
|
export let saveButtonLabel
|
||||||
export let deleteButtonLabel
|
export let deleteButtonLabel
|
||||||
|
|
||||||
const { fetchDatasourceSchema, generateGoldenSample } = getContext("sdk")
|
const { fetchDatasourceSchema, generateGoldenSample } = getContext<SDK>("sdk")
|
||||||
const component = getContext("component")
|
const component = getContext<Component>("component")
|
||||||
const context = getContext("context")
|
const context = getContext<Context>("context")
|
||||||
|
|
||||||
let schema
|
let schema: TableSchema
|
||||||
|
|
||||||
$: fetchSchema(dataSource)
|
$: fetchSchema(dataSource)
|
||||||
$: id = $component.id
|
$: id = $component.id
|
||||||
|
@ -61,11 +63,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const convertOldFieldFormat = fields => {
|
const convertOldFieldFormat = (fields: any[]) => {
|
||||||
if (!fields) {
|
if (!fields) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
return fields.map(field => {
|
return fields.map((field: any) => {
|
||||||
if (typeof field === "string") {
|
if (typeof field === "string") {
|
||||||
// existed but was a string
|
// existed but was a string
|
||||||
return {
|
return {
|
||||||
|
@ -82,11 +84,14 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDefaultFields = (fields, schema) => {
|
const getDefaultFields = (
|
||||||
|
fields: { name: string; active: boolean }[],
|
||||||
|
schema: TableSchema
|
||||||
|
) => {
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let defaultFields = []
|
let defaultFields: { name: string; active: boolean }[] = []
|
||||||
|
|
||||||
if (!fields || fields.length === 0) {
|
if (!fields || fields.length === 0) {
|
||||||
Object.values(schema)
|
Object.values(schema)
|
||||||
|
@ -101,15 +106,14 @@
|
||||||
return [...fields, ...defaultFields].filter(field => field.active)
|
return [...fields, ...defaultFields].filter(field => field.active)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchSchema = async () => {
|
const fetchSchema = async (datasource: UIDatasource) => {
|
||||||
schema = (await fetchDatasourceSchema(dataSource)) || {}
|
schema = (await fetchDatasourceSchema(datasource)) || {}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormBlockWrapper {actionType} {dataSource} {rowId} {noRowsMessage}>
|
<FormBlockWrapper {actionType} {dataSource} {rowId} {noRowsMessage}>
|
||||||
<InnerFormBlock
|
<InnerFormBlock
|
||||||
{dataSource}
|
{dataSource}
|
||||||
{actionUrl}
|
|
||||||
{actionType}
|
{actionType}
|
||||||
{size}
|
{size}
|
||||||
{disabled}
|
{disabled}
|
||||||
|
@ -117,7 +121,6 @@
|
||||||
{title}
|
{title}
|
||||||
{description}
|
{description}
|
||||||
{schema}
|
{schema}
|
||||||
{notificationOverride}
|
|
||||||
buttons={buttonsOrDefault}
|
buttons={buttonsOrDefault}
|
||||||
buttonPosition={buttons ? buttonPosition : "top"}
|
buttonPosition={buttons ? buttonPosition : "top"}
|
||||||
{buttonsCollapsed}
|
{buttonsCollapsed}
|
||||||
|
|
|
@ -7,9 +7,13 @@ export interface SDK {
|
||||||
styleable: any
|
styleable: any
|
||||||
Provider: any
|
Provider: any
|
||||||
ActionTypes: typeof ActionTypes
|
ActionTypes: typeof ActionTypes
|
||||||
|
fetchDatasourceSchema: any
|
||||||
|
generateGoldenSample: any
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Component = Readable<{
|
export type Component = Readable<{
|
||||||
id: string
|
id: string
|
||||||
styles: any
|
styles: any
|
||||||
}>
|
}>
|
||||||
|
|
||||||
|
export type Context = Readable<any>
|
||||||
|
|
Loading…
Reference in New Issue