queries working with repeater

This commit is contained in:
Martin McKeaveney 2021-01-18 14:41:59 +00:00
parent 7ed062bf1e
commit b5c4bde662
10 changed files with 52 additions and 7 deletions

View File

@ -23,13 +23,20 @@ import { cloneDeep, difference } from "lodash/fp"
* @param {fetchBindablePropertiesParameter} param
* @returns {Array.<BindableProperty>}
*/
export default function({ componentInstanceId, screen, components, tables }) {
export default function({
componentInstanceId,
screen,
components,
tables,
queries,
}) {
const result = walk({
// cloning so we are free to mutate props (e.g. by adding _contexts)
instance: cloneDeep(screen.props),
targetId: componentInstanceId,
components,
tables,
queries,
})
return [
@ -37,6 +44,9 @@ export default function({ componentInstanceId, screen, components, tables }) {
.filter(isInstanceInSharedContext(result))
.map(componentInstanceToBindable),
...(result.target?._contexts.map(contextToBindables(tables)).flat() ?? []),
...(result.target?._contexts
.map(context => queriesToBindables(queries, context))
.flat() ?? []),
]
}
@ -61,9 +71,36 @@ const componentInstanceToBindable = i => {
}
}
const queriesToBindables = (queries, context) => {
let queryId = context.table._id
const query = queries.find(query => query._id === queryId)
let schema = query?.schema
// Avoid crashing whenever no data source has been selected
if (!schema) {
return []
}
const queryBindings = Object.entries(schema).map(([key, value]) => ({
type: "context",
fieldSchema: value,
instance: context.instance,
// how the binding expression persists, and is used in the app at runtime
runtimeBinding: `${context.instance._id}.${key}`,
// how the binding expressions looks to the user of the builder
readableBinding: `${context.instance._instanceName}.${query.name}.${key}`,
// table / view info
table: context.table,
}))
return queryBindings
}
const contextToBindables = tables => context => {
const tableId = context.table?.tableId ?? context.table
const table = tables.find(table => table._id === tableId)
let tableId = context.table?.tableId ?? context.table
const table = tables.find(table => table._id === tableId || context.table._id)
let schema =
context.table?.type === "view"
? table?.views?.[context.table.name]?.schema
@ -152,8 +189,8 @@ const walk = ({ instance, targetId, components, tables, result }) => {
const currentContexts = [...result.currentContexts]
for (let child of instance._children || []) {
// attaching _contexts of components, for eas comparison later
// these have been deep cloned above, so shouln't modify the
// attaching _contexts of components, for easy comparison later
// these have been deep cloned above, so shouldn't modify the
// original component instances
child._contexts = currentContexts
walk({ instance: child, targetId, components, tables, result })

View File

@ -11,6 +11,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries,
})
const tableFields = tableId => {

View File

@ -12,6 +12,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries,
})
$: idFields = bindableProperties.filter(

View File

@ -15,6 +15,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries
}).map(property => ({
...property,
category: property.type === "instance" ? "Component" : "Table",

View File

@ -44,6 +44,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries,
})
const addField = () => {
@ -114,8 +115,7 @@
<Spacer small />
<TextButton text small blue on:click={addField}>
Add
{fieldLabel}
Add {fieldLabel}
<div style="height: 20px; width: 20px;">
<AddIcon />
</div>

View File

@ -20,6 +20,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries,
})
$: {

View File

@ -15,6 +15,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries,
})
let idFields

View File

@ -35,6 +35,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries,
})
}

View File

@ -31,6 +31,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries,
})
const detailScreens = $allScreens.filter(screen =>

View File

@ -45,6 +45,7 @@
components: $store.components,
screen: $currentAsset,
tables: $backendUiStore.tables,
queries: $backendUiStore.queries
})
$: queryBindableProperties = bindableProperties.map(property => ({