From 89c2ae0692321b258fe034f61161d58cf10ce7ce Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 22 Feb 2021 17:41:02 +0000 Subject: [PATCH 1/3] read all columns for schema rather than just the first --- .../TableIntegrationMenu/IntegrationConfigForm.svelte | 7 ++++--- .../src/components/integration/QueryViewer.svelte | 8 ++++---- .../data/datasource/[selectedDatasource]/index.svelte | 6 ++++++ packages/server/src/api/controllers/query.js | 10 +++++++++- packages/server/src/integrations/airtable.js | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte index 793f3cc186..2db5490678 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte @@ -3,13 +3,14 @@ import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte" export let integration + export let schema let unsaved = false
- {#each Object.keys(integration) as configKey} - {#if typeof integration[configKey] === 'object'} + {#each Object.keys(schema) as configKey} + {#if typeof schema[configKey].type === 'object'} @@ -18,7 +19,7 @@ diff --git a/packages/builder/src/components/integration/QueryViewer.svelte b/packages/builder/src/components/integration/QueryViewer.svelte index 596b4a3a1a..c80a0020ea 100644 --- a/packages/builder/src/components/integration/QueryViewer.svelte +++ b/packages/builder/src/components/integration/QueryViewer.svelte @@ -92,7 +92,7 @@ if (response.status !== 200) throw new Error(json.message) - data = json || [] + data = json.rows || [] if (data.length === 0) { notifier.info( @@ -103,9 +103,9 @@ notifier.success("Query executed successfully.") - // Assume all the fields are strings and create a basic schema - // from the first record returned by the query - fields = Object.keys(json[0]).map(field => ({ + // Assume all the fields are strings and create a basic schema from the + // unique fields returned by the server + fields = json.schemaFields.map(field => ({ name: field, type: "STRING", })) diff --git a/packages/builder/src/pages/[application]/data/datasource/[selectedDatasource]/index.svelte b/packages/builder/src/pages/[application]/data/datasource/[selectedDatasource]/index.svelte index 6415f3f9de..4fb13131eb 100644 --- a/packages/builder/src/pages/[application]/data/datasource/[selectedDatasource]/index.svelte +++ b/packages/builder/src/pages/[application]/data/datasource/[selectedDatasource]/index.svelte @@ -13,6 +13,11 @@ ) $: integration = datasource && $backendUiStore.integrations[datasource.source] + $: console.log({ + datasource, + integration, + }) + async function saveDatasource() { // Create datasource await backendUiStore.actions.datasources.save(datasource) @@ -74,6 +79,7 @@ diff --git a/packages/server/src/api/controllers/query.js b/packages/server/src/api/controllers/query.js index 04ff019a38..55c2ad14b0 100644 --- a/packages/server/src/api/controllers/query.js +++ b/packages/server/src/api/controllers/query.js @@ -115,9 +115,17 @@ exports.preview = async function(ctx) { const enrichedQuery = await enrichQueryFields(fields, parameters) - ctx.body = formatResponse( + const rows = formatResponse( 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) { diff --git a/packages/server/src/integrations/airtable.js b/packages/server/src/integrations/airtable.js index 004deff16e..2c83712289 100644 --- a/packages/server/src/integrations/airtable.js +++ b/packages/server/src/integrations/airtable.js @@ -8,7 +8,7 @@ const SCHEMA = { friendlyName: "Airtable", datasource: { apiKey: { - type: FIELD_TYPES.STRING, + type: FIELD_TYPES.PASSWORD, default: "enter api key", required: true, }, From b082909dd53002662a7ab55e387de69f74611aeb Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 22 Feb 2021 17:51:15 +0000 Subject: [PATCH 2/3] remove log --- .../data/datasource/[selectedDatasource]/index.svelte | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/builder/src/pages/[application]/data/datasource/[selectedDatasource]/index.svelte b/packages/builder/src/pages/[application]/data/datasource/[selectedDatasource]/index.svelte index 4fb13131eb..657ca256b4 100644 --- a/packages/builder/src/pages/[application]/data/datasource/[selectedDatasource]/index.svelte +++ b/packages/builder/src/pages/[application]/data/datasource/[selectedDatasource]/index.svelte @@ -13,11 +13,6 @@ ) $: integration = datasource && $backendUiStore.integrations[datasource.source] - $: console.log({ - datasource, - integration, - }) - async function saveDatasource() { // Create datasource await backendUiStore.actions.datasources.save(datasource) From d4e792426970797373147fee35f5eb58a7bf9dbe Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 22 Feb 2021 18:40:33 +0000 Subject: [PATCH 3/3] removing redundant cancel button --- .../src/components/deploy/CreateWebhookDeploymentModal.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/deploy/CreateWebhookDeploymentModal.svelte b/packages/builder/src/components/deploy/CreateWebhookDeploymentModal.svelte index 4259f2ef9c..1599297d00 100644 --- a/packages/builder/src/components/deploy/CreateWebhookDeploymentModal.svelte +++ b/packages/builder/src/components/deploy/CreateWebhookDeploymentModal.svelte @@ -23,7 +23,7 @@ }) - +

See below the list of deployed webhook URLs.

{#each webhookUrls as webhookUrl}