Add new top level column editor and ensure all types can be stringified in PDF tables
This commit is contained in:
parent
ced5210977
commit
4dfe10a5ad
|
@ -22,6 +22,7 @@ import ValidationEditor from "./controls/ValidationEditor/ValidationEditor.svelt
|
|||
import DrawerBindableInput from "@/components/common/bindings/DrawerBindableInput.svelte"
|
||||
import ColumnEditor from "./controls/ColumnEditor/ColumnEditor.svelte"
|
||||
import BasicColumnEditor from "./controls/ColumnEditor/BasicColumnEditor.svelte"
|
||||
import TopLevelColumnEditor from "./controls/ColumnEditor/TopLevelColumnEditor.svelte"
|
||||
import GridColumnEditor from "./controls/GridColumnConfiguration/GridColumnConfiguration.svelte"
|
||||
import BarButtonList from "./controls/BarButtonList.svelte"
|
||||
import FieldConfiguration from "./controls/FieldConfiguration/FieldConfiguration.svelte"
|
||||
|
@ -62,7 +63,10 @@ const componentMap = {
|
|||
stepConfiguration: FormStepConfiguration,
|
||||
formStepControls: FormStepControls,
|
||||
columns: ColumnEditor,
|
||||
// "Basic" actually includes nested JSON and relationship fields
|
||||
"columns/basic": BasicColumnEditor,
|
||||
// "Top level" is only the top level schema fields
|
||||
"columns/toplevel": TopLevelColumnEditor,
|
||||
"columns/grid": GridColumnEditor,
|
||||
tableConditions: TableConditionEditor,
|
||||
"field/sortable": SortableFieldSelect,
|
||||
|
|
|
@ -10,10 +10,17 @@
|
|||
} from "@/dataBinding"
|
||||
import { selectedScreen, tables } from "@/stores/builder"
|
||||
|
||||
export let componentInstance
|
||||
const getSearchableFields = (schema, tableList) => {
|
||||
return search.getFields(tableList, Object.values(schema || {}), {
|
||||
allowLinks: true,
|
||||
})
|
||||
}
|
||||
|
||||
export let componentInstance = undefined
|
||||
export let value = []
|
||||
export let allowCellEditing = true
|
||||
export let allowReorder = true
|
||||
export let getSchemaFields = getSearchableFields
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
|
@ -28,13 +35,7 @@
|
|||
: enrichedSchemaFields?.map(field => field.name)
|
||||
$: sanitisedValue = getValidColumns(value, options)
|
||||
$: updateBoundValue(sanitisedValue)
|
||||
$: enrichedSchemaFields = search.getFields(
|
||||
$tables.list,
|
||||
Object.values(schema || {}),
|
||||
{
|
||||
allowLinks: true,
|
||||
}
|
||||
)
|
||||
$: enrichedSchemaFields = getSchemaFields(schema, $tables.list)
|
||||
|
||||
$: {
|
||||
value = (value || []).filter(
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<script lang="ts">
|
||||
import ColumnEditor from "./ColumnEditor.svelte"
|
||||
import type { TableSchema } from "@budibase/types"
|
||||
|
||||
const getTopLevelSchemaFields = (schema: TableSchema) => {
|
||||
return Object.values(schema).filter(fieldSchema => !fieldSchema.nestedJSON)
|
||||
}
|
||||
</script>
|
||||
|
||||
<ColumnEditor
|
||||
{...$$props}
|
||||
on:change
|
||||
allowCellEditing={false}
|
||||
getSchemaFields={getTopLevelSchemaFields}
|
||||
/>
|
|
@ -8138,7 +8138,7 @@
|
|||
"dependsOn": "sortColumn"
|
||||
},
|
||||
{
|
||||
"type": "columns/basic",
|
||||
"type": "columns/toplevel",
|
||||
"label": "Columns",
|
||||
"key": "columns",
|
||||
"resetOn": "datasource"
|
||||
|
|
|
@ -93,8 +93,7 @@
|
|||
sanitized = pruned
|
||||
}
|
||||
|
||||
// Add nested JSON fields
|
||||
return SchemaUtils.addNestedJSONSchemaFields(sanitized)
|
||||
return sanitized
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import {
|
||||
BBReferenceFieldMetadata,
|
||||
BBReferenceFieldSubType,
|
||||
BBReferenceSingleFieldMetadata,
|
||||
DateFieldMetadata,
|
||||
FieldSchema,
|
||||
FieldType,
|
||||
Row,
|
||||
|
@ -48,14 +45,40 @@ const stringifyValue = (value: any): string => {
|
|||
|
||||
const stringifyField = (value: any, schema: FieldSchema): string => {
|
||||
switch (schema.type) {
|
||||
// TODO
|
||||
case FieldType.ATTACHMENT_SINGLE:
|
||||
case FieldType.ATTACHMENTS:
|
||||
// Auto should not exist as it should always be typed by its underlying
|
||||
// real type, like date or user
|
||||
case FieldType.AUTO:
|
||||
case FieldType.LINK:
|
||||
case FieldType.SIGNATURE_SINGLE:
|
||||
return ""
|
||||
|
||||
// Just state whether signatures exist or not
|
||||
case FieldType.SIGNATURE_SINGLE:
|
||||
return value ? "Yes" : "No"
|
||||
|
||||
// Extract attachment names
|
||||
case FieldType.ATTACHMENT_SINGLE:
|
||||
case FieldType.ATTACHMENTS: {
|
||||
if (!value) {
|
||||
return ""
|
||||
}
|
||||
const arrayValue = Array.isArray(value) ? value : [value]
|
||||
return arrayValue
|
||||
.map(x => x.name)
|
||||
.filter(x => !!x)
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
// Extract primary displays from relationships
|
||||
case FieldType.LINK: {
|
||||
if (!value) {
|
||||
return ""
|
||||
}
|
||||
const arrayValue = Array.isArray(value) ? value : [value]
|
||||
return arrayValue
|
||||
.map(x => x.primaryDisplay)
|
||||
.filter(x => !!x)
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
// Stringify JSON blobs
|
||||
case FieldType.JSON:
|
||||
return value ? JSON.stringify(value) : ""
|
||||
|
|
|
@ -207,6 +207,8 @@ export interface BaseFieldSchema extends UIFieldMetadata {
|
|||
autocolumn?: boolean
|
||||
autoReason?: AutoReason.FOREIGN_KEY
|
||||
subtype?: never
|
||||
// added when enriching nested JSON fields into schema
|
||||
nestedJSON?: boolean
|
||||
}
|
||||
|
||||
interface OtherFieldMetadata extends BaseFieldSchema {
|
||||
|
|
Loading…
Reference in New Issue