This commit is contained in:
Martin McKeaveney 2021-01-13 18:29:51 +00:00
parent 01ff661f17
commit 267e85c2bf
6 changed files with 29 additions and 41 deletions

View File

@ -11,22 +11,22 @@
let loading = false let loading = false
let error = false let error = false
async function fetchData() { // async function fetchData() {
try { // try {
loading = true // loading = true
const response = await api.fetchDataForQuery( // const response = await api.fetchDataForQuery(
$params.selectedDatasource, // $params.selectedDatasource,
query._id // query._id
) // )
data = response.rows || [] // data = response.rows || []
error = false // error = false
} catch (err) { // } catch (err) {
error = `${query}: Query error. (${err.message}). This could be a problem with your datasource configuration.` // error = `${query}: Query error. (${err.message}). This could be a problem with your datasource configuration.`
notifier.danger(error) // notifier.danger(error)
} finally { // } finally {
loading = false // loading = false
} // }
} // }
// Fetch rows for specified query // Fetch rows for specified query
// $: query && fetchData() // $: query && fetchData()

View File

@ -30,15 +30,3 @@ export async function fetchDataForView(view) {
} }
return json return json
} }
export async function fetchDataForQuery(datasourceId, queryId) {
const FETCH_QUERY_URL = `/api/queries/${queryId}`
const response = await api.get(FETCH_QUERY_URL)
const json = await response.json()
if (response.status !== 200) {
throw new Error(json.message)
}
return json
}

View File

@ -9,8 +9,7 @@
$: datasource = $backendUiStore.datasources.find( $: datasource = $backendUiStore.datasources.find(
ds => ds._id === parameters.datasourceId ds => ds._id === parameters.datasourceId
) )
// TODO: binding needs a significant refactor and needs to // TODO: binding needs to be centralised
// be centralised
$: bindableProperties = fetchBindableProperties({ $: bindableProperties = fetchBindableProperties({
componentInstanceId: $store.selectedComponentId, componentInstanceId: $store.selectedComponentId,
components: $store.components, components: $store.components,
@ -51,7 +50,6 @@
<Spacer medium /> <Spacer medium />
<!-- TODO: Need to render defaults, but allow interpolation of frontend values -->
{#if query} {#if query}
<ParameterBuilder <ParameterBuilder
bind:customParams={parameters.queryParams} bind:customParams={parameters.queryParams}

View File

@ -17,7 +17,7 @@ const SCHEMA = {
query: { query: {
create: { create: {
"Airtable Record": { "Airtable Record": {
type: "fields", type: QUERY_TYPES.FIELDS,
customisable: true, customisable: true,
fields: { fields: {
table: { table: {

View File

@ -1,24 +1,25 @@
const PouchDB = require("pouchdb") const PouchDB = require("pouchdb")
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
const SCHEMA = { const SCHEMA = {
datasource: { datasource: {
url: { url: {
type: "string", type: FIELD_TYPES.STRING,
required: true, required: true,
default: "localhost", default: "localhost",
}, },
database: { database: {
type: "string", type: FIELD_TYPES.STRING,
required: true, required: true,
}, },
view: { view: {
type: "string", type: FIELD_TYPES.STRING,
required: true, required: true,
}, },
}, },
query: { query: {
json: { json: {
type: "json", type: QUERY_TYPES.JSON,
required: true, required: true,
}, },
}, },

View File

@ -1,30 +1,31 @@
const { MongoClient } = require("mongodb") const { MongoClient } = require("mongodb")
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
const SCHEMA = { const SCHEMA = {
datasource: { datasource: {
connectionString: { connectionString: {
type: "string", type: FIELD_TYPES.STRING,
required: true, required: true,
default: "localhost", default: "localhost",
}, },
db: { db: {
type: "string", type: FIELD_TYPES.STRING,
required: true, required: true,
}, },
collection: { collection: {
type: "string", type: FIELD_TYPES.STRING,
required: true, required: true,
}, },
}, },
query: { query: {
create: { create: {
JSON: { JSON: {
type: "json", type: QUERY_TYPES.JSON,
}, },
}, },
read: { read: {
JSON: { JSON: {
type: "json", type: QUERY_TYPES.JSON,
}, },
}, },
}, },