Fix charts not correctly using data context

This commit is contained in:
Andrew Kingston 2020-11-25 18:43:58 +00:00
parent b8bc583fd9
commit c962ea9ad9
9 changed files with 19 additions and 14 deletions

View File

@ -9,7 +9,7 @@
export let definition = {} export let definition = {}
// Get local data binding context // Get local data binding context
const dataStore = getContext("data") const dataContext = getContext("data")
// Create component context // Create component context
const componentStore = writable({}) const componentStore = writable({})
@ -19,7 +19,7 @@
$: constructor = getComponentConstructor(definition._component) $: constructor = getComponentConstructor(definition._component)
$: children = definition._children $: children = definition._children
$: id = definition._id $: id = definition._id
$: enrichedProps = enrichProps(definition, $dataStore, $bindingStore) $: enrichedProps = enrichProps(definition, $dataContext, $bindingStore)
// Update component context // Update component context
// ID is duplicated inside style so that the "styleable" helper can set // ID is duplicated inside style so that the "styleable" helper can set

View File

@ -5,9 +5,9 @@
export let row export let row
// Clone and create new data context for this component tree // Clone and create new data context for this component tree
const data = getContext("data") const dataContext = getContext("data")
const component = getContext("component") const component = getContext("component")
const newData = createDataStore($data) const newData = createDataStore($dataContext)
setContext("data", newData) setContext("data", newData)
$: newData.actions.addContext(row, $component.id) $: newData.actions.addContext(row, $component.id)
</script> </script>

View File

@ -7,7 +7,7 @@
const { styleable, API } = getContext("sdk") const { styleable, API } = getContext("sdk")
const component = getContext("component") const component = getContext("component")
const data = getContext("data") const dataContext = getContext("data")
export let wide = false export let wide = false
@ -16,7 +16,7 @@
let fields = [] let fields = []
// Fetch info about the closest data context // Fetch info about the closest data context
$: getFormData($data[$data.closestComponentId]) $: getFormData($dataContext[$dataContext.closestComponentId])
const getFormData = async context => { const getFormData = async context => {
if (context) { if (context) {
@ -25,7 +25,7 @@
fields = Object.keys(schema) fields = Object.keys(schema)
// Use the draft version for editing // Use the draft version for editing
row = $data[`${$data.closestComponentId}_draft`] row = $dataContext[`${$dataContext.closestComponentId}_draft`]
} }
} }
</script> </script>

View File

@ -4,7 +4,7 @@
const { API, styleable, DataProvider } = getContext("sdk") const { API, styleable, DataProvider } = getContext("sdk")
const component = getContext("component") const component = getContext("component")
const data = getContext("data") const dataContext = getContext("data")
export let datasource = [] export let datasource = []
@ -12,7 +12,7 @@
onMount(async () => { onMount(async () => {
if (!isEmpty(datasource)) { if (!isEmpty(datasource)) {
rows = await API.fetchDatasource(datasource, $data) rows = await API.fetchDatasource(datasource, $dataContext)
} }
}) })
</script> </script>

View File

@ -5,6 +5,7 @@
import { isEmpty } from "lodash/fp" import { isEmpty } from "lodash/fp"
const { API } = getContext("sdk") const { API } = getContext("sdk")
const dataContext = getContext("data")
export let title export let title
export let datasource export let datasource
@ -34,7 +35,7 @@
// Fetch, filter and sort data // Fetch, filter and sort data
const schema = (await API.fetchTableDefinition(datasource.tableId)).schema const schema = (await API.fetchTableDefinition(datasource.tableId)).schema
const result = await API.fetchDatasource(datasource) const result = await API.fetchDatasource(datasource, $dataContext)
const reducer = row => (valid, column) => valid && row[column] != null const reducer = row => (valid, column) => valid && row[column] != null
const hasAllColumns = row => allCols.reduce(reducer(row), true) const hasAllColumns = row => allCols.reduce(reducer(row), true)
const data = result const data = result

View File

@ -5,6 +5,7 @@
import { isEmpty } from "lodash/fp" import { isEmpty } from "lodash/fp"
const { API } = getContext("sdk") const { API } = getContext("sdk")
const dataContext = getContext("data")
export let title export let title
export let datasource export let datasource
@ -32,7 +33,7 @@
// Fetch, filter and sort data // Fetch, filter and sort data
const schema = (await API.fetchTableDefinition(datasource.tableId)).schema const schema = (await API.fetchTableDefinition(datasource.tableId)).schema
const result = await API.fetchDatasource(datasource) const result = await API.fetchDatasource(datasource, $dataContext)
const reducer = row => (valid, column) => valid && row[column] != null const reducer = row => (valid, column) => valid && row[column] != null
const hasAllColumns = row => allCols.reduce(reducer(row), true) const hasAllColumns = row => allCols.reduce(reducer(row), true)
const data = result const data = result

View File

@ -5,6 +5,7 @@
import { isEmpty } from "lodash/fp" import { isEmpty } from "lodash/fp"
const { API } = getContext("sdk") const { API } = getContext("sdk")
const dataContext = getContext("data")
// Common props // Common props
export let title export let title
@ -40,7 +41,7 @@
// Fetch, filter and sort data // Fetch, filter and sort data
const schema = (await API.fetchTableDefinition(datasource.tableId)).schema const schema = (await API.fetchTableDefinition(datasource.tableId)).schema
const result = await API.fetchDatasource(datasource) const result = await API.fetchDatasource(datasource, $dataContext)
const reducer = row => (valid, column) => valid && row[column] != null const reducer = row => (valid, column) => valid && row[column] != null
const hasAllColumns = row => allCols.reduce(reducer(row), true) const hasAllColumns = row => allCols.reduce(reducer(row), true)
const data = result const data = result

View File

@ -5,6 +5,7 @@
import { isEmpty } from "lodash/fp" import { isEmpty } from "lodash/fp"
const { API } = getContext("sdk") const { API } = getContext("sdk")
const dataContext = getContext("data")
export let title export let title
export let datasource export let datasource
@ -30,7 +31,7 @@
// Fetch, filter and sort data // Fetch, filter and sort data
const schema = (await API.fetchTableDefinition(datasource.tableId)).schema const schema = (await API.fetchTableDefinition(datasource.tableId)).schema
const result = await API.fetchDatasource(datasource) const result = await API.fetchDatasource(datasource, $dataContext)
const data = result const data = result
.filter(row => row[labelColumn] != null && row[valueColumn] != null) .filter(row => row[labelColumn] != null && row[valueColumn] != null)
.slice(0, 20) .slice(0, 20)

View File

@ -16,6 +16,7 @@
const setters = new Map([["number", number]]) const setters = new Map([["number", number]])
const SDK = getContext("sdk") const SDK = getContext("sdk")
const component = getContext("component") const component = getContext("component")
const dataContext = getContext("data")
const { API, styleable } = SDK const { API, styleable } = SDK
export let datasource = {} export let datasource = {}
@ -58,7 +59,7 @@
onMount(async () => { onMount(async () => {
if (!isEmpty(datasource)) { if (!isEmpty(datasource)) {
data = await API.fetchDatasource(datasource) data = await API.fetchDatasource(datasource, $dataContext)
let schema let schema
// Get schema for datasource // Get schema for datasource