1
0
Fork 0
mirror of synced 2024-10-03 10:36:59 +13:00

Add grid support for old views with groupBy specified, and any other datasource that has a custom means of determining a datasource schema

This commit is contained in:
Andrew Kingston 2023-10-24 08:26:57 +01:00
parent 9a72c418c9
commit f355933bf3
2 changed files with 23 additions and 7 deletions

View file

@ -1,5 +1,5 @@
import { derived, get } from "svelte/store"
import { getDatasourceDefinition } from "../../../fetch"
import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch"
import { memo } from "../../../utils"
export const createStores = () => {
@ -11,10 +11,14 @@ export const createStores = () => {
}
export const deriveStores = context => {
const { definition, schemaOverrides, columnWhitelist, datasource } = context
const { API, definition, schemaOverrides, columnWhitelist, datasource } = context
const schema = derived(definition, $definition => {
let schema = $definition?.schema
let schema = getDatasourceSchema({
API,
datasource: get(datasource),
definition: $definition
})
if (!schema) {
return null
}

View file

@ -32,12 +32,24 @@ export const fetchData = ({ API, datasource, options }) => {
return new Fetch({ API, datasource, ...options })
}
// Fetches the definition of any type of datasource
export const getDatasourceDefinition = async ({ API, datasource }) => {
// Creates an empty fetch instance with no datasource configured, so no data
// will initially be loaded
const createEmptyFetchInstance = ({ API, datasource }) => {
const handler = DataFetchMap[datasource?.type]
if (!handler) {
return null
}
const instance = new handler({ API })
return await instance.getDefinition(datasource)
return new handler({ API })
}
// Fetches the definition of any type of datasource
export const getDatasourceDefinition = async ({ API, datasource }) => {
const instance = createEmptyFetchInstance({ API, datasource })
return await instance?.getDefinition(datasource)
}
// Fetches the schema of any type of datasource
export const getDatasourceSchema = ({ API, datasource, definition }) => {
const instance = createEmptyFetchInstance({ API, datasource })
return instance?.getSchema(datasource, definition)
}