allow type editing on custom query datasource schemas
This commit is contained in:
parent
5695827f86
commit
90934c547f
|
@ -32,31 +32,22 @@
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
export let query
|
export let query
|
||||||
export let fields = []
|
|
||||||
|
|
||||||
|
let fields = query.schema ? schemaToFields(query.schema) : []
|
||||||
let parameters
|
let parameters
|
||||||
let data = []
|
let data = []
|
||||||
let roleId
|
let roleId
|
||||||
const transformerDocs =
|
const transformerDocs =
|
||||||
"https://docs.budibase.com/building-apps/data/transformers"
|
"https://docs.budibase.com/building-apps/data/transformers"
|
||||||
const typeOptions = [
|
const typeOptions = [
|
||||||
{ label: "Text", value: "STRING" },
|
{ label: "Text", value: "string" },
|
||||||
{ label: "Number", value: "NUMBER" },
|
{ label: "Number", value: "number" },
|
||||||
{ label: "Boolean", value: "BOOLEAN" },
|
{ label: "Boolean", value: "boolean" },
|
||||||
{ label: "Datetime", value: "DATETIME" },
|
{ label: "Datetime", value: "datetime" },
|
||||||
]
|
]
|
||||||
|
|
||||||
$: datasource = $datasources.list.find(ds => ds._id === query.datasourceId)
|
$: datasource = $datasources.list.find(ds => ds._id === query.datasourceId)
|
||||||
$: query.schema = fields.reduce(
|
$: query.schema = fieldsToSchema(fields)
|
||||||
(acc, next) => ({
|
|
||||||
...acc,
|
|
||||||
[next.name]: {
|
|
||||||
name: next.name,
|
|
||||||
type: "string",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
{}
|
|
||||||
)
|
|
||||||
$: datasourceType = datasource?.source
|
$: datasourceType = datasource?.source
|
||||||
$: integrationInfo = $integrations[datasourceType]
|
$: integrationInfo = $integrations[datasourceType]
|
||||||
$: queryConfig = integrationInfo?.query
|
$: queryConfig = integrationInfo?.query
|
||||||
|
@ -135,7 +126,7 @@
|
||||||
// unique fields returned by the server
|
// unique fields returned by the server
|
||||||
fields = json.schemaFields.map(field => ({
|
fields = json.schemaFields.map(field => ({
|
||||||
name: field,
|
name: field,
|
||||||
type: "STRING",
|
type: "string",
|
||||||
}))
|
}))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notifications.error(`Query Error: ${err.message}`)
|
notifications.error(`Query Error: ${err.message}`)
|
||||||
|
@ -155,6 +146,26 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function schemaToFields(schema) {
|
||||||
|
return Object.keys(schema).map(key => ({
|
||||||
|
name: key,
|
||||||
|
type: query.schema[key].type,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
function fieldsToSchema(fieldsToConvert) {
|
||||||
|
return fieldsToConvert.reduce(
|
||||||
|
(acc, next) => ({
|
||||||
|
...acc,
|
||||||
|
[next.name]: {
|
||||||
|
name: next.name,
|
||||||
|
type: next.type,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (!query || !query._id) {
|
if (!query || !query._id) {
|
||||||
roleId = Roles.BASIC
|
roleId = Roles.BASIC
|
||||||
|
|
Loading…
Reference in New Issue