Merge pull request #1156 from Budibase/external-data-source-fixes
External data source fixes
This commit is contained in:
commit
175d34841b
|
@ -3,13 +3,14 @@
|
||||||
import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte"
|
import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte"
|
||||||
|
|
||||||
export let integration
|
export let integration
|
||||||
|
export let schema
|
||||||
|
|
||||||
let unsaved = false
|
let unsaved = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
{#each Object.keys(integration) as configKey}
|
{#each Object.keys(schema) as configKey}
|
||||||
{#if typeof integration[configKey] === 'object'}
|
{#if typeof schema[configKey].type === 'object'}
|
||||||
<Label small>{configKey}</Label>
|
<Label small>{configKey}</Label>
|
||||||
<Spacer small />
|
<Spacer small />
|
||||||
<KeyValueBuilder bind:object={integration[configKey]} on:change />
|
<KeyValueBuilder bind:object={integration[configKey]} on:change />
|
||||||
|
@ -18,7 +19,7 @@
|
||||||
<Label small>{configKey}</Label>
|
<Label small>{configKey}</Label>
|
||||||
<Input
|
<Input
|
||||||
outline
|
outline
|
||||||
type={integration[configKey].type}
|
type={schema[configKey].type}
|
||||||
on:change
|
on:change
|
||||||
bind:value={integration[configKey]} />
|
bind:value={integration[configKey]} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ModalContent title="Webhook Endpoints" confirmText="Done">
|
<ModalContent title="Webhook Endpoints" confirmText="OK" showCancelButton={false}>
|
||||||
<p>See below the list of deployed webhook URLs.</p>
|
<p>See below the list of deployed webhook URLs.</p>
|
||||||
{#each webhookUrls as webhookUrl}
|
{#each webhookUrls as webhookUrl}
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
if (response.status !== 200) throw new Error(json.message)
|
if (response.status !== 200) throw new Error(json.message)
|
||||||
|
|
||||||
data = json || []
|
data = json.rows || []
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
notifier.info(
|
notifier.info(
|
||||||
|
@ -101,9 +101,9 @@
|
||||||
|
|
||||||
notifier.success("Query executed successfully.")
|
notifier.success("Query executed successfully.")
|
||||||
|
|
||||||
// Assume all the fields are strings and create a basic schema
|
// Assume all the fields are strings and create a basic schema from the
|
||||||
// from the first record returned by the query
|
// unique fields returned by the server
|
||||||
fields = Object.keys(json[0]).map(field => ({
|
fields = json.schemaFields.map(field => ({
|
||||||
name: field,
|
name: field,
|
||||||
type: "STRING",
|
type: "STRING",
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -74,6 +74,7 @@
|
||||||
|
|
||||||
<Spacer extraLarge />
|
<Spacer extraLarge />
|
||||||
<IntegrationConfigForm
|
<IntegrationConfigForm
|
||||||
|
schema={integration.datasource}
|
||||||
integration={datasource.config}
|
integration={datasource.config}
|
||||||
on:change={setUnsaved} />
|
on:change={setUnsaved} />
|
||||||
<Spacer extraLarge />
|
<Spacer extraLarge />
|
||||||
|
|
|
@ -115,9 +115,17 @@ exports.preview = async function(ctx) {
|
||||||
|
|
||||||
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
||||||
|
|
||||||
ctx.body = formatResponse(
|
const rows = formatResponse(
|
||||||
await new Integration(datasource.config)[queryVerb](enrichedQuery)
|
await new Integration(datasource.config)[queryVerb](enrichedQuery)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// get all the potential fields in the schema
|
||||||
|
const keys = rows.flatMap(Object.keys)
|
||||||
|
|
||||||
|
ctx.body = {
|
||||||
|
rows,
|
||||||
|
schemaFields: [...new Set(keys)],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.execute = async function(ctx) {
|
exports.execute = async function(ctx) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ const SCHEMA = {
|
||||||
friendlyName: "Airtable",
|
friendlyName: "Airtable",
|
||||||
datasource: {
|
datasource: {
|
||||||
apiKey: {
|
apiKey: {
|
||||||
type: FIELD_TYPES.STRING,
|
type: FIELD_TYPES.PASSWORD,
|
||||||
default: "enter api key",
|
default: "enter api key",
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue