This commit is contained in:
Gerard Burns 2024-04-11 11:42:31 +01:00
parent 293a969f5f
commit 2af464791c
4 changed files with 20 additions and 56 deletions

View File

@ -1,11 +1,10 @@
<script> <script>
import ExplanationModal from './ExplanationModal/index.svelte' import ExplanationModal from './ExplanationModal/index.svelte'
import { messages } from "./columnInfo"; import { messages as messageConstants, getColumnInfoMessagesAndSupport } from "./columnInfo";
import { Column, Support, NotRequired, StringNumber } from "./lines" import { Column, Support, NotRequired, StringNumber } from "./lines"
import subjects from './subjects'; import subjects from './subjects';
export let support = {} export let columnInfo
export let columnIcon export let columnIcon
export let columnType export let columnType
export let columnName export let columnName
@ -15,6 +14,15 @@
export let schema export let schema
let support
let messages = []
$: {
const columnInfoMessagesAndSupport = getColumnInfoMessagesAndSupport(schema, columnInfo)
support = columnInfoMessagesAndSupport.support
messages = columnInfoMessagesAndSupport.messages
}
let root = null; let root = null;
let explanationModalSubject = subjects.none let explanationModalSubject = subjects.none
@ -38,15 +46,15 @@
{setExplanationSubject} {setExplanationSubject}
/> />
<Support <Support
support={support.support} {support}
{setExplanationSubject} {setExplanationSubject}
/> />
{#if support?.messages?.includes(messages.stringAsNumber)} {#if messages.includes(messageConstants.stringAsNumber)}
<StringNumber <StringNumber
{setExplanationSubject} {setExplanationSubject}
/> />
{/if} {/if}
{#if support?.messages?.includes(messages.notRequired)} {#if messages.includes(messageConstants.notRequired)}
<NotRequired <NotRequired
{setExplanationSubject} {setExplanationSubject}
/> />

View File

@ -1,2 +1 @@
export { default as FieldContext } from "./FieldContext.svelte" export { default as FieldContext } from "./FieldContext.svelte"
export * from "./columnInfo"

View File

@ -3,7 +3,7 @@
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding" import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
import { selectedScreen } from "stores/builder" import { selectedScreen } from "stores/builder"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import { FieldContext, getColumnInfoMessagesAndSupport } from './FieldContext' import { FieldContext } from './FieldContext'
import { debounce } from "lodash" import { debounce } from "lodash"
import { goto, params } from "@roxi/routify" import { goto, params } from "@roxi/routify"
import { Constants } from "@budibase/frontend-core" import { Constants } from "@budibase/frontend-core"
@ -19,23 +19,9 @@
let previousOption = null let previousOption = null
let contextTooltipVisible = false let contextTooltipVisible = false
const getFieldSupport = (schema, columnInfo) => {
if (columnInfo == null) {
return {}
}
const fieldSupport = {}
Object.entries(schema || {}).forEach(([key, value]) => {
fieldSupport[key] = getColumnInfoMessagesAndSupport(value)
})
return fieldSupport
}
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance) $: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: schema = getSchemaForDatasource($selectedScreen, datasource).schema $: schema = getSchemaForDatasource($selectedScreen, datasource).schema
$: fieldSupport = getFieldSupport(schema, columnInfo);
$: options = Object.keys(schema || {}) $: options = Object.keys(schema || {})
$: boundValue = getValidValue(value, options) $: boundValue = getValidValue(value, options)
@ -127,18 +113,18 @@
explanationModal explanationModal
tableHref={`/builder/app/${$params.application}/data/table/${datasource?.tableId}`} tableHref={`/builder/app/${$params.application}/data/table/${datasource?.tableId}`}
schema={schema[currentOption]} schema={schema[currentOption]}
support={fieldSupport[currentOption]}
columnIcon={getOptionIcon(currentOption)} columnIcon={getOptionIcon(currentOption)}
columnName={currentOption} columnName={currentOption}
columnType={getOptionIconTooltip(currentOption)} columnType={getOptionIconTooltip(currentOption)}
{columnInfo}
/> />
<FieldContext <FieldContext
slot="previous" slot="previous"
schema={schema[previousOption]} schema={schema[previousOption]}
support={fieldSupport[previousOption]}
columnIcon={getOptionIcon(previousOption)} columnIcon={getOptionIcon(previousOption)}
columnName={previousOption} columnName={previousOption}
columnType={getOptionIconTooltip(previousOption)} columnType={getOptionIconTooltip(previousOption)}
{columnInfo}
/> />
</ContextTooltip> </ContextTooltip>
{/if} {/if}

View File

@ -5,7 +5,7 @@
componentStore, componentStore,
} from "stores/builder" } from "stores/builder"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import { FieldContext, getColumnInfoMessagesAndSupport } from './FieldContext' import { FieldContext } from './FieldContext'
import { FIELDS } from 'constants/backend' import { FIELDS } from 'constants/backend'
import { goto, params } from "@roxi/routify" import { goto, params } from "@roxi/routify"
import { debounce } from "lodash" import { debounce } from "lodash"
@ -25,29 +25,12 @@
componentInstance?._component componentInstance?._component
) )
const getFieldSupport = (schema, columnInfo) => {
if (columnInfo == null) {
return {}
}
const fieldSupport = {}
Object.entries(schema || {}).forEach(([key, value]) => {
// super TODO: nicer to do this at the component level jit and store each value seperately so i don't have this long ass name???
fieldSupport[key] = getColumnInfoMessagesAndSupport(value, columnInfo)
})
return fieldSupport
}
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance) $: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: schema = getSchemaForDatasource($selectedScreen, datasource).schema $: schema = getSchemaForDatasource($selectedScreen, datasource).schema
$: options = Object.keys(schema || {}) $: options = Object.keys(schema || {})
$: fieldSupport = getFieldSupport(schema, columnInfo);
$: boundValue = getValidOptions(value, options) $: boundValue = getValidOptions(value, options)
$: console.log(fieldSupport)
const getValidOptions = (selectedOptions, allOptions) => { const getValidOptions = (selectedOptions, allOptions) => {
// Fix the hardcoded default string value // Fix the hardcoded default string value
@ -92,18 +75,6 @@
return "" return ""
} }
const isOptionEnabled = optionKey => {
return true;
// Remain enabled if already selected, so it can be deselected
if (value?.includes(optionKey)) return true
const support = fieldSupport[optionKey]?.support;
if (support == null) return true
if (support === unsupported) return false
return true
}
const updateTooltip = debounce((e, option) => { const updateTooltip = debounce((e, option) => {
if (option == null) { if (option == null) {
contextTooltipVisible = false; contextTooltipVisible = false;
@ -145,18 +116,18 @@
explanationModal explanationModal
tableHref={`/builder/app/${$params.application}/data/table/${datasource?.tableId}`} tableHref={`/builder/app/${$params.application}/data/table/${datasource?.tableId}`}
schema={schema[currentOption]} schema={schema[currentOption]}
support={fieldSupport[currentOption]}
columnIcon={getOptionIcon(currentOption)} columnIcon={getOptionIcon(currentOption)}
columnName={currentOption} columnName={currentOption}
columnType={getOptionIconTooltip(currentOption)} columnType={getOptionIconTooltip(currentOption)}
{columnInfo}
/> />
<FieldContext <FieldContext
slot="previous" slot="previous"
schema={schema[previousOption]} schema={schema[previousOption]}
support={fieldSupport[previousOption]}
columnIcon={getOptionIcon(previousOption)} columnIcon={getOptionIcon(previousOption)}
columnName={previousOption} columnName={previousOption}
columnType={getOptionIconTooltip(previousOption)} columnType={getOptionIconTooltip(previousOption)}
{columnInfo}
/> />
</ContextTooltip> </ContextTooltip>
{/if} {/if}