Improve grid and table rendering of any type of datasource
This commit is contained in:
parent
8a10ea899c
commit
59174c4c1a
|
@ -46,28 +46,20 @@
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (datasource != null) {
|
if (datasource != null) {
|
||||||
data = await fetchData(datasource, $store)
|
data = await fetchData(datasource, $store)
|
||||||
let schemaKeys = []
|
|
||||||
let schema = {}
|
let schema = {}
|
||||||
|
|
||||||
// Get schema for datasource
|
// Get schema for datasource
|
||||||
if (datasource.type === "view") {
|
// Views with "Calculate" applied provide their own schema.
|
||||||
// For views, use the first object as the schema and pretend it's all strings
|
// For everything else, use the tableId property to pull to table schema
|
||||||
if (data && data.length) {
|
if (datasource.schema) {
|
||||||
schemaKeys = Object.keys(data[0])
|
schema = datasource.schema
|
||||||
}
|
|
||||||
schema = {}
|
|
||||||
schemaKeys.forEach(key => {
|
|
||||||
schema[key] = "string"
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
// Fetch the real schema for the table or relationship
|
|
||||||
const jsonTable = await _bb.api.get(`/api/tables/${datasource.tableId}`)
|
const jsonTable = await _bb.api.get(`/api/tables/${datasource.tableId}`)
|
||||||
table = await jsonTable.json()
|
table = await jsonTable.json()
|
||||||
schema = table.schema
|
schema = table.schema
|
||||||
schemaKeys = Object.keys(schema)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
columnDefs = schemaKeys.map((key, i) => {
|
columnDefs = Object.keys(schema).map((key, i) => {
|
||||||
return {
|
return {
|
||||||
headerCheckboxSelection: i === 0 && canEdit,
|
headerCheckboxSelection: i === 0 && canEdit,
|
||||||
checkboxSelection: i === 0 && canEdit,
|
checkboxSelection: i === 0 && canEdit,
|
||||||
|
|
|
@ -40,15 +40,18 @@
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (!isEmpty(datasource)) {
|
if (!isEmpty(datasource)) {
|
||||||
|
console.log(datasource)
|
||||||
data = await fetchData(datasource, $store)
|
data = await fetchData(datasource, $store)
|
||||||
if (data && data.length) {
|
|
||||||
if (datasource.type === "view") {
|
// Get schema for datasource
|
||||||
schema = data[0]
|
// Views with "Calculate" applied provide their own schema.
|
||||||
headers = Object.keys(schema).filter(shouldDisplayField)
|
// For everything else, use the tableId property to pull to table schema
|
||||||
} else {
|
if (datasource.schema) {
|
||||||
schema = await fetchTable(datasource.tableId)
|
schema = datasource.schema
|
||||||
headers = Object.keys(schema)
|
headers = Object.keys(schema).filter(shouldDisplayField)
|
||||||
}
|
} else {
|
||||||
|
schema = await fetchTable(datasource.tableId)
|
||||||
|
headers = Object.keys(schema).filter(shouldDisplayField)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue