1
0
Fork 0
mirror of synced 2024-10-01 01:28:51 +13:00

Improve grid and table rendering of any type of datasource

This commit is contained in:
Andrew Kingston 2020-10-14 09:23:20 +01:00
parent 8a10ea899c
commit 59174c4c1a
2 changed files with 16 additions and 21 deletions

View file

@ -46,28 +46,20 @@
onMount(async () => {
if (datasource != null) {
data = await fetchData(datasource, $store)
let schemaKeys = []
let schema = {}
// Get schema for datasource
if (datasource.type === "view") {
// For views, use the first object as the schema and pretend it's all strings
if (data && data.length) {
schemaKeys = Object.keys(data[0])
}
schema = {}
schemaKeys.forEach(key => {
schema[key] = "string"
})
// Views with "Calculate" applied provide their own schema.
// For everything else, use the tableId property to pull to table schema
if (datasource.schema) {
schema = datasource.schema
} else {
// Fetch the real schema for the table or relationship
const jsonTable = await _bb.api.get(`/api/tables/${datasource.tableId}`)
table = await jsonTable.json()
schema = table.schema
schemaKeys = Object.keys(schema)
}
columnDefs = schemaKeys.map((key, i) => {
columnDefs = Object.keys(schema).map((key, i) => {
return {
headerCheckboxSelection: i === 0 && canEdit,
checkboxSelection: i === 0 && canEdit,

View file

@ -40,15 +40,18 @@
onMount(async () => {
if (!isEmpty(datasource)) {
console.log(datasource)
data = await fetchData(datasource, $store)
if (data && data.length) {
if (datasource.type === "view") {
schema = data[0]
headers = Object.keys(schema).filter(shouldDisplayField)
} else {
schema = await fetchTable(datasource.tableId)
headers = Object.keys(schema)
}
// Get schema for datasource
// Views with "Calculate" applied provide their own schema.
// For everything else, use the tableId property to pull to table schema
if (datasource.schema) {
schema = datasource.schema
headers = Object.keys(schema).filter(shouldDisplayField)
} else {
schema = await fetchTable(datasource.tableId)
headers = Object.keys(schema).filter(shouldDisplayField)
}
}
})