From 98a7085bbca4bf31fce9451dd4ca38ab583c70c3 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 8 Jan 2021 12:06:37 +0000 Subject: [PATCH] Allow dynamic query execution from front end components --- .../src/builderStore/store/frontend.js | 1 + .../buttons/CreateQueryButton.svelte | 49 -------- .../src/components/common/BottomDrawer.svelte | 29 +++++ .../components/integration/QueryEditor.svelte | 4 + .../integration/QueryParameterBuilder.svelte | 52 +++++++++ .../components/integration/QueryViewer.svelte | 15 ++- .../src/components/integration/index.svelte | 53 +-------- .../DataBindingDrawer/index.svelte | 35 ++++++ .../EventsEditor/EventEditorModal.svelte | 105 +++++++++--------- .../EventsEditor/EventPropertyControl.svelte | 21 +++- .../EventsEditor/actions/ExecuteQuery.svelte | 36 +++++- .../GenericBindingPopover.svelte | 6 +- .../userInterface/PropertyControl.svelte | 1 + .../userInterface/TableViewSelect.svelte | 14 +++ .../[selectedDatasource]/[query]/index.svelte | 3 +- .../[selectedDatasource]/index.svelte | 1 - .../design/[assetType]/_layout.svelte | 14 +++ packages/client/src/api/queries.js | 8 +- packages/client/src/utils/buttonActions.js | 17 +-- packages/server/src/api/controllers/query.js | 20 ++-- packages/server/src/db/client.js | 2 +- packages/server/src/integrations/postgres.js | 56 +++++++++- 22 files changed, 344 insertions(+), 198 deletions(-) delete mode 100644 packages/builder/src/components/backend/DataTable/buttons/CreateQueryButton.svelte create mode 100644 packages/builder/src/components/common/BottomDrawer.svelte create mode 100644 packages/builder/src/components/integration/QueryParameterBuilder.svelte create mode 100644 packages/builder/src/components/userInterface/DataBindingDrawer/index.svelte diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index acb5929b3c..1e451ff63e 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -40,6 +40,7 @@ const INITIAL_FRONTEND_STATE = { libraries: null, appId: "", routes: {}, + bottomDrawerVisible: false, } export const getFrontendStore = () => { diff --git a/packages/builder/src/components/backend/DataTable/buttons/CreateQueryButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/CreateQueryButton.svelte deleted file mode 100644 index 98c03873ab..0000000000 --- a/packages/builder/src/components/backend/DataTable/buttons/CreateQueryButton.svelte +++ /dev/null @@ -1,49 +0,0 @@ - - -
- -
- - - - - diff --git a/packages/builder/src/components/common/BottomDrawer.svelte b/packages/builder/src/components/common/BottomDrawer.svelte new file mode 100644 index 0000000000..d2a4bcbaab --- /dev/null +++ b/packages/builder/src/components/common/BottomDrawer.svelte @@ -0,0 +1,29 @@ + + + +
+ {#if title} + {title} + {/if} + +
+
+ + diff --git a/packages/builder/src/components/integration/QueryEditor.svelte b/packages/builder/src/components/integration/QueryEditor.svelte index 257a2dc29c..5def206c90 100644 --- a/packages/builder/src/components/integration/QueryEditor.svelte +++ b/packages/builder/src/components/integration/QueryEditor.svelte @@ -12,6 +12,10 @@ // $: codemirror && codemirror.setValue(value) + console.log("Running init") + + $: console.log("Running reactive") + onMount(async () => { codemirror = cm.fromTextArea(editor, { lineNumbers: true, diff --git a/packages/builder/src/components/integration/QueryParameterBuilder.svelte b/packages/builder/src/components/integration/QueryParameterBuilder.svelte new file mode 100644 index 0000000000..d78018768d --- /dev/null +++ b/packages/builder/src/components/integration/QueryParameterBuilder.svelte @@ -0,0 +1,52 @@ + + +Parameters +
+ + + +
+ {#each parameters as parameter, idx} + + + + deleteQueryParameter(idx)} /> + {/each} +
+ + + diff --git a/packages/builder/src/components/integration/QueryViewer.svelte b/packages/builder/src/components/integration/QueryViewer.svelte index c8a34eb423..afba48c9f6 100644 --- a/packages/builder/src/components/integration/QueryViewer.svelte +++ b/packages/builder/src/components/integration/QueryViewer.svelte @@ -85,8 +85,18 @@ async function previewQuery() { try { + // parse all the parameters in the UI + // send them + const response = await api.post(`/api/queries/preview`, { - parameters: query.parameters, + // TODO: revisit + parameters: query.parameters.reduce( + (acc, next) => ({ + ...acc, + [next.name]: next.default, + }), + {} + ), datasourceId: datasource._id, query: query.queryString, }) @@ -96,7 +106,8 @@ data = json || [] - // TODO: refactor + // 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 => ({ name: field, type: "STRING", diff --git a/packages/builder/src/components/integration/index.svelte b/packages/builder/src/components/integration/index.svelte index c133f4ff24..acea9cdd3f 100644 --- a/packages/builder/src/components/integration/index.svelte +++ b/packages/builder/src/components/integration/index.svelte @@ -1,65 +1,16 @@ -Parameters - {#if query.queryType === QueryTypes.SQL} -
-
- - - - - {#each parameters as parameter, idx} - - - deleteQueryParameter(idx)} /> - {/each} - -
-
- + {/if} - - diff --git a/packages/builder/src/components/userInterface/DataBindingDrawer/index.svelte b/packages/builder/src/components/userInterface/DataBindingDrawer/index.svelte new file mode 100644 index 0000000000..736117c30e --- /dev/null +++ b/packages/builder/src/components/userInterface/DataBindingDrawer/index.svelte @@ -0,0 +1,35 @@ + + +{#if query} + +
+ + +
+
+{/if} + + diff --git a/packages/builder/src/components/userInterface/EventsEditor/EventEditorModal.svelte b/packages/builder/src/components/userInterface/EventsEditor/EventEditorModal.svelte index 27e91cd29e..fda964a7ba 100644 --- a/packages/builder/src/components/userInterface/EventsEditor/EventEditorModal.svelte +++ b/packages/builder/src/components/userInterface/EventsEditor/EventEditorModal.svelte @@ -1,5 +1,11 @@ - -
-
- -
- -
- Add Action -
-
- -
- {#each actionTypes as actionType} -
- {actionType.name} -
- {/each} +
+
+ +
+
- + Add Action +
- -
- {#if actions && actions.length > 0} - {#each actions as action, index} -
-
- {index + 1}. {action[eventTypeKey]} -
- -
-
- {#if action === selectedAction} -
- -
- deleteAction(index)}> - Delete - -
-
- {/if} + +
+ {#each actionTypes as actionType} +
+ {actionType.name}
{/each} - {/if} -
+
+ +
- - +
+ {#if actions && actions.length > 0} + {#each actions as action, index} +
+
+ {index + 1}. {action[eventTypeKey]} +
+ +
+
+ {#if action === selectedAction} +
+ +
+ deleteAction(index)}> + Delete + +
+
+ {/if} +
+ {/each} + {/if} + +
+ +Learn more about Actions