1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Allow selecting columns in design

This commit is contained in:
Adria Navarro 2024-09-09 12:41:59 +02:00
parent 4f4c0f2b07
commit 785ac58d84
4 changed files with 34 additions and 22 deletions

View file

@ -1,4 +1,5 @@
<script> <script>
import { enrichSchemaWithRelColumns } from "@budibase/frontend-core"
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding" import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
import { selectedScreen, componentStore } from "stores/builder" import { selectedScreen, componentStore } from "stores/builder"
import DraggableList from "../DraggableList/DraggableList.svelte" import DraggableList from "../DraggableList/DraggableList.svelte"
@ -27,7 +28,8 @@
delete schema._rev delete schema._rev
} }
return schema const result = enrichSchemaWithRelColumns(schema)
return result
} }
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance) $: datasource = getDatasourceForProvider($selectedScreen, componentInstance)

View file

@ -1,6 +1,6 @@
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 { enrichSchemaWithRelColumns, memo } from "../../../utils"
export const createStores = () => { export const createStores = () => {
const definition = memo(null) const definition = memo(null)
@ -54,27 +54,9 @@ export const deriveStores = context => {
return null return null
} }
const schemaWithRelatedColumns = Object.keys($schema || {}).reduce( const schemaWithRelatedColumns = enrichSchemaWithRelColumns($schema)
(acc, c) => {
const field = $schema[c]
acc[c] = field
if (field.columns) { const enrichedSchema = {}
for (const relColumn of Object.keys(field.columns)) {
const name = `${field.name}.${relColumn}`
acc[name] = {
...field.columns[relColumn],
name,
related: { field: c, subField: relColumn },
}
}
}
return acc
},
{}
)
let enrichedSchema = {}
Object.keys(schemaWithRelatedColumns).forEach(field => { Object.keys(schemaWithRelatedColumns).forEach(field => {
enrichedSchema[field] = { enrichedSchema[field] = {
...schemaWithRelatedColumns[field], ...schemaWithRelatedColumns[field],

View file

@ -10,3 +10,4 @@ export { createWebsocket } from "./websocket"
export * from "./download" export * from "./download"
export * from "./theme" export * from "./theme"
export * from "./settings" export * from "./settings"
export * from "./schema"

View file

@ -0,0 +1,27 @@
export function enrichSchemaWithRelColumns(schema) {
if (!schema) {
return
}
const result = Object.keys(schema).reduce((acc, c) => {
const field = schema[c]
acc[c] = field
if (field.columns) {
for (const relColumn of Object.keys(field.columns)) {
const relField = field.columns[relColumn]
if (!relField.visible) {
continue
}
const name = `${field.name}.${relColumn}`
acc[name] = {
...relField,
name,
related: { field: c, subField: relColumn },
}
}
}
return acc
}, {})
return result
}