Fix fetching of relationship data in lists
This commit is contained in:
parent
e9fc20696b
commit
3dcd9d32e2
|
@ -55,7 +55,7 @@ export default `<html>
|
||||||
|
|
||||||
window["##BUDIBASE_FRONTEND_DEFINITION##"] = data.frontendDefinition;
|
window["##BUDIBASE_FRONTEND_DEFINITION##"] = data.frontendDefinition;
|
||||||
if (window.loadBudibase) {
|
if (window.loadBudibase) {
|
||||||
loadBudibase({ window, localStorage })
|
loadBudibase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let styles
|
let styles
|
||||||
|
|
|
@ -6,20 +6,24 @@ import { enrichRows } from "./rows"
|
||||||
/**
|
/**
|
||||||
* Fetches all rows for a particular Budibase data source.
|
* Fetches all rows for a particular Budibase data source.
|
||||||
*/
|
*/
|
||||||
export const fetchDatasource = async datasource => {
|
export const fetchDatasource = async (datasource, context) => {
|
||||||
if (!datasource || !datasource.type) {
|
if (!datasource || !datasource.type) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch all rows in data source
|
// Fetch all rows in data source
|
||||||
const { type, tableId } = datasource
|
const { type, tableId, fieldName } = datasource
|
||||||
let rows = []
|
let rows = []
|
||||||
if (type === "table") {
|
if (type === "table") {
|
||||||
rows = await fetchTableData(tableId)
|
rows = await fetchTableData(tableId)
|
||||||
} else if (type === "view") {
|
} else if (type === "view") {
|
||||||
rows = await fetchViewData(datasource)
|
rows = await fetchViewData(datasource)
|
||||||
} else if (type === "link") {
|
} else if (type === "link") {
|
||||||
rows = await fetchRelationshipData(tableId)
|
rows = await fetchRelationshipData({
|
||||||
|
tableId: context?.row?.tableId,
|
||||||
|
fieldName,
|
||||||
|
rowId: context?.row?._id,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enrich rows
|
// Enrich rows
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { enrichRows } from "./rows"
|
||||||
* Fetches related rows for a certain field of a certain row.
|
* Fetches related rows for a certain field of a certain row.
|
||||||
*/
|
*/
|
||||||
export const fetchRelationshipData = async ({ tableId, rowId, fieldName }) => {
|
export const fetchRelationshipData = async ({ tableId, rowId, fieldName }) => {
|
||||||
if (!tableId || !rowId) {
|
if (!tableId || !rowId || !fieldName) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const response = await api.get({ url: `/api/${tableId}/${rowId}/enrich` })
|
const response = await api.get({ url: `/api/${tableId}/${rowId}/enrich` })
|
||||||
|
|
|
@ -8,11 +8,7 @@
|
||||||
export let styles
|
export let styles
|
||||||
let routes
|
let routes
|
||||||
|
|
||||||
onMount(() => {
|
onMount(async () => {
|
||||||
initialiseRouter()
|
|
||||||
})
|
|
||||||
|
|
||||||
const initialiseRouter = async () => {
|
|
||||||
await routeStore.actions.fetchRoutes()
|
await routeStore.actions.fetchRoutes()
|
||||||
await screenStore.actions.fetchScreens()
|
await screenStore.actions.fetchScreens()
|
||||||
routes = {}
|
routes = {}
|
||||||
|
@ -22,7 +18,7 @@
|
||||||
|
|
||||||
// Add catch-all route so that we serve the Screen component always
|
// Add catch-all route so that we serve the Screen component always
|
||||||
routes["*"] = Screen
|
routes["*"] = Screen
|
||||||
}
|
})
|
||||||
|
|
||||||
function onRouteLoading({ detail }) {
|
function onRouteLoading({ detail }) {
|
||||||
routeStore.actions.setActiveRoute(detail.route)
|
routeStore.actions.setActiveRoute(detail.route)
|
||||||
|
|
|
@ -28,5 +28,6 @@ export default (input, context) => {
|
||||||
if (!looksLikeMustache.test(input)) {
|
if (!looksLikeMustache.test(input)) {
|
||||||
return input
|
return input
|
||||||
}
|
}
|
||||||
|
console.log(input)
|
||||||
return mustache.render(input, context)
|
return mustache.render(input, context)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import DataProvider from "./DataProvider.svelte"
|
import DataProvider from "./DataProvider.svelte"
|
||||||
|
|
||||||
const { API, styleable } = getContext("app")
|
const { API, styleable } = getContext("app")
|
||||||
|
const dataContext = getContext("data")
|
||||||
|
|
||||||
export let datasource = []
|
export let datasource = []
|
||||||
export let styles
|
export let styles
|
||||||
|
@ -12,7 +13,7 @@
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (!isEmpty(datasource)) {
|
if (!isEmpty(datasource)) {
|
||||||
rows = await API.fetchDatasource(datasource)
|
rows = await API.fetchDatasource(datasource, $dataContext)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import { isEmpty } from "lodash/fp"
|
import { isEmpty } from "lodash/fp"
|
||||||
|
|
||||||
const { API } = getContext("app")
|
const { API } = getContext("app")
|
||||||
|
const dataContext = getContext("data")
|
||||||
|
|
||||||
// Common props
|
// Common props
|
||||||
export let title
|
export let title
|
||||||
|
@ -41,7 +42,7 @@
|
||||||
|
|
||||||
// Fetch, filter and sort data
|
// Fetch, filter and sort data
|
||||||
const schema = (await API.fetchTableDefinition(datasource.tableId)).schema
|
const schema = (await API.fetchTableDefinition(datasource.tableId)).schema
|
||||||
const result = await API.fetchDatasource(datasource)
|
const result = await API.fetchDatasource(datasource, $dataContext)
|
||||||
const reducer = row => (valid, column) => valid && row[column] != null
|
const reducer = row => (valid, column) => valid && row[column] != null
|
||||||
const hasAllColumns = row => allCols.reduce(reducer(row), true)
|
const hasAllColumns = row => allCols.reduce(reducer(row), true)
|
||||||
const data = result
|
const data = result
|
||||||
|
|
Loading…
Reference in New Issue