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

View File

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