From 1b0fa94dff188752644ed1fd05629764c6d47b84 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 20 Nov 2020 09:50:10 +0000 Subject: [PATCH] Add support for full depth data binding --- packages/client/src/api/datasources.js | 6 +-- .../client/src/components/ClientApp.svelte | 7 +-- .../client/src/components/Component.svelte | 31 +++++++------ .../client/src/components/DataProvider.svelte | 24 +++++++++++ packages/client/src/components/Router.svelte | 7 +-- packages/client/src/sdk.js | 2 + packages/client/src/store/auth.js | 1 - packages/client/src/store/dataContext.js | 43 +++++++++++++++++++ packages/client/src/store/index.js | 1 + .../client/src/utils/enrichDataBinding.js | 4 +- packages/client/src/utils/index.js | 1 + .../standard-components/src/Button.svelte | 4 +- packages/standard-components/src/Card.svelte | 4 +- .../src/CardHorizontal.svelte | 4 +- .../standard-components/src/Container.svelte | 4 +- .../standard-components/src/DataForm.svelte | 4 +- .../src/DataFormWide.svelte | 4 +- .../src/DataProvider.svelte | 19 -------- .../standard-components/src/DatePicker.svelte | 4 +- packages/standard-components/src/Embed.svelte | 4 +- packages/standard-components/src/Form.svelte | 23 +++++++--- .../standard-components/src/Heading.svelte | 4 +- packages/standard-components/src/Icon.svelte | 4 +- packages/standard-components/src/Image.svelte | 4 +- packages/standard-components/src/Input.svelte | 4 +- packages/standard-components/src/Link.svelte | 4 +- .../src/LinkedRowSelector.svelte | 2 +- packages/standard-components/src/List.svelte | 9 ++-- packages/standard-components/src/Login.svelte | 4 +- .../standard-components/src/Navigation.svelte | 4 +- .../standard-components/src/NewRow.svelte | 4 +- .../standard-components/src/RichText.svelte | 2 +- .../standard-components/src/RowDetail.svelte | 3 +- .../src/StackedList.svelte | 4 +- packages/standard-components/src/Text.svelte | 4 +- .../src/attachments/Dropzone.svelte | 2 +- .../src/charts/ApexChart.svelte | 4 +- .../src/charts/BarChart.svelte | 3 +- .../src/charts/CandleStickChart.svelte | 3 +- .../src/charts/LineChart.svelte | 3 +- .../src/charts/PieChart.svelte | 3 +- .../src/grid/Component.svelte | 4 +- .../src/grid/CreateRow/Modal.svelte | 2 +- .../src/stores/dataProvider.js | 26 ----------- 44 files changed, 169 insertions(+), 138 deletions(-) create mode 100644 packages/client/src/components/DataProvider.svelte create mode 100644 packages/client/src/store/dataContext.js delete mode 100644 packages/standard-components/src/DataProvider.svelte delete mode 100644 packages/standard-components/src/stores/dataProvider.js diff --git a/packages/client/src/api/datasources.js b/packages/client/src/api/datasources.js index 66890b230b..f97618b4a9 100644 --- a/packages/client/src/api/datasources.js +++ b/packages/client/src/api/datasources.js @@ -6,7 +6,7 @@ import { enrichRows } from "./rows" /** * Fetches all rows for a particular Budibase data source. */ -export const fetchDatasource = async (datasource, context) => { +export const fetchDatasource = async (datasource, dataContext) => { if (!datasource || !datasource.type) { return [] } @@ -20,9 +20,9 @@ export const fetchDatasource = async (datasource, context) => { rows = await fetchViewData(datasource) } else if (type === "link") { rows = await fetchRelationshipData({ - tableId: context?.row?.tableId, + rowId: dataContext?.data?._id, + tableId: dataContext?.data?.tableId, fieldName, - rowId: context?.row?._id, }) } diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index 77454edfa5..a0be2120b5 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -2,10 +2,11 @@ import { setContext, onMount } from "svelte" import Component from "./Component.svelte" import SDK from "../sdk" - import { routeStore, screenStore } from "../store" + import { routeStore, screenStore, createDataContextStore } from "../store" - // Provide SDK for components - setContext("app", SDK) + // Provide contexts + setContext("sdk", SDK) + setContext("data", createDataContextStore()) let loaded = false diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index 56e79e9449..273d217df3 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -1,21 +1,10 @@ {#if constructor} - + {#if children && children.length} {#each children as child} diff --git a/packages/client/src/components/DataProvider.svelte b/packages/client/src/components/DataProvider.svelte new file mode 100644 index 0000000000..30c1b4aec6 --- /dev/null +++ b/packages/client/src/components/DataProvider.svelte @@ -0,0 +1,24 @@ + + +{#if loaded} + +{/if} diff --git a/packages/client/src/components/Router.svelte b/packages/client/src/components/Router.svelte index f61bff7c10..693ec2dd28 100644 --- a/packages/client/src/components/Router.svelte +++ b/packages/client/src/components/Router.svelte @@ -1,11 +1,12 @@