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:
parent
9a72c418c9
commit
f355933bf3
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue