Improve grid and table rendering of any type of datasource
This commit is contained in:
parent
4ac83afb62
commit
7e162960f0
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
|
||||
// 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)
|
||||
}
|
||||
headers = Object.keys(schema).filter(shouldDisplayField)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue