Add related columns

This commit is contained in:
Adria Navarro 2024-09-06 12:23:32 +02:00
parent 7072244f31
commit 77587c8686
3 changed files with 52 additions and 7 deletions

View File

@ -1,3 +1,5 @@
import { FieldType } from "@budibase/types"
const modernize = columns => { const modernize = columns => {
if (!columns) { if (!columns) {
return [] return []
@ -8,6 +10,7 @@ const modernize = columns => {
label: column.displayName, label: column.displayName,
field: column.name, field: column.name,
active: true, active: true,
related: column.related,
})) }))
} }
@ -50,12 +53,35 @@ const removeInvalidAddMissing = (
const getDefault = (schema = {}) => { const getDefault = (schema = {}) => {
const defaultValues = Object.values(schema) const defaultValues = Object.values(schema)
.filter(column => !column.nestedJSON) .filter(column => !column.nestedJSON)
.map(column => ({ .flatMap(column => {
label: column.name, const order = column.visible
field: column.name, ? column.order ?? -1
active: column.visible ?? true, : Number.MAX_SAFE_INTEGER
order: column.visible ? column.order ?? -1 : Number.MAX_SAFE_INTEGER, const columns = [
})) {
label: column.name,
field: column.name,
active: column.visible ?? true,
order,
},
]
if (column.columns) {
for (const relColumn of Object.keys(column.columns).filter(
relColumn => column.columns[relColumn].visible !== false
)) {
columns.push({
label: `${relColumn} (${column.name})`,
field: `${column.name}.${relColumn}`,
active: column.visible ?? true,
order,
related: true,
})
}
}
return columns
})
defaultValues.sort((a, b) => a.order - b.order) defaultValues.sort((a, b) => a.order - b.order)
@ -69,6 +95,7 @@ const toGridFormat = draggableListColumns => {
active: entry.active, active: entry.active,
width: entry.width, width: entry.width,
conditions: entry.conditions, conditions: entry.conditions,
related: entry.related,
})) }))
} }
@ -82,9 +109,12 @@ const toDraggableListFormat = (gridFormatColumns, createComponent, schema) => {
active: column.active, active: column.active,
field: column.field, field: column.field,
label: column.label, label: column.label,
columnType: schema[column.field].type, columnType: column.related
? FieldType.FORMULA
: schema[column.field]?.type,
width: column.width, width: column.width,
conditions: column.conditions, conditions: column.conditions,
related: column.related,
}, },
{} {}
) )

View File

@ -98,6 +98,7 @@
order: idx, order: idx,
conditions: column.conditions, conditions: column.conditions,
visible: !!column.active, visible: !!column.active,
related: column.related,
} }
if (column.width) { if (column.width) {
overrides[column.field].width = column.width overrides[column.field].width = column.width

View File

@ -1,6 +1,7 @@
import { derived, get } from "svelte/store" import { derived, get } from "svelte/store"
import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch" import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch"
import { memo } from "../../../utils" import { memo } from "../../../utils"
import { FieldType } from "@budibase/types"
export const createStores = () => { export const createStores = () => {
const definition = memo(null) const definition = memo(null)
@ -73,6 +74,19 @@ export const deriveStores = context => {
} }
} }
}) })
if ($schemaOverrides) {
Object.keys($schemaOverrides).forEach(field => {
if (!$schemaOverrides[field].related) {
return
}
enrichedSchema[field] = {
...$schemaOverrides[field],
name: field,
type: FieldType.FORMULA,
related: true,
}
})
}
return enrichedSchema return enrichedSchema
} }
) )