Remove legacy concept of currentAsset

This commit is contained in:
Andrew Kingston 2024-02-05 11:59:54 +00:00
parent 05e1dee992
commit e7ac33bf43
30 changed files with 98 additions and 93 deletions

View File

@ -1,7 +1,7 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset, componentStore } from "stores/builder"
import { getActionProviders } from "../../../../../../dataBinding"
import { selectedScreen, componentStore } from "stores/builder"
import { getActionProviders } from "dataBinding"
import { onMount } from "svelte"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
@ -10,7 +10,7 @@
export let nested
$: actionProviders = getActionProviders(
$currentAsset,
$selectedScreen,
$componentStore.selectedComponentId,
"ChangeFormStep",
{ includeSelf: nested }

View File

@ -1,13 +1,13 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset, componentStore } from "stores/builder"
import { selectedScreen, componentStore } from "stores/builder"
import { getActionProviders } from "../../../../../../dataBinding"
export let parameters
export let nested
$: actionProviders = getActionProviders(
$currentAsset,
$selectedScreen,
$componentStore.selectedComponentId,
"ClearForm",
{ includeSelf: nested }

View File

@ -1,6 +1,11 @@
<script>
import { Select, Label, Body, Checkbox, Input } from "@budibase/bbui"
import { currentAsset, componentStore, tables, viewsV2 } from "stores/builder"
import {
selectedScreen,
componentStore,
tables,
viewsV2,
} from "stores/builder"
import { getSchemaForDatasourcePlus } from "../../../../../../dataBinding"
import SaveFields from "./SaveFields.svelte"
import { getDatasourceLikeProviders } from "components/design/settings/controls/ButtonActionEditor/actions/utils"
@ -10,7 +15,7 @@
export let nested
$: providerOptions = getDatasourceLikeProviders({
asset: $currentAsset,
asset: $selectedScreen,
componentId: $componentStore.selectedComponentId,
nested,
})

View File

@ -1,7 +1,7 @@
<script>
import { Label, Select, Body, Multiselect } from "@budibase/bbui"
import { findAllMatchingComponents, findComponent } from "helpers/components"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
import { onMount } from "svelte"
import {
getDatasourceForProvider,
@ -21,14 +21,15 @@
},
]
$: tables = findAllMatchingComponents($currentAsset?.props, component =>
$: tables = findAllMatchingComponents($selectedScreen?.props, component =>
component._component.endsWith("table")
).map(table => ({
label: table._instanceName,
value: table._id,
}))
$: tableBlocks = findAllMatchingComponents($currentAsset?.props, component =>
component._component.endsWith("tableblock")
$: tableBlocks = findAllMatchingComponents(
$selectedScreen?.props,
component => component._component.endsWith("tableblock")
).map(block => ({
label: block._instanceName,
value: `${block._id}-table`,
@ -41,9 +42,9 @@
if (tableId?.includes("-")) {
tableId = tableId.split("-")[0]
}
const selectedTable = findComponent($currentAsset?.props, tableId)
const datasource = getDatasourceForProvider($currentAsset, selectedTable)
const { schema } = getSchemaForDatasource($currentAsset, datasource)
const selectedTable = findComponent($selectedScreen?.props, tableId)
const datasource = getDatasourceForProvider($selectedScreen, selectedTable)
const { schema } = getSchemaForDatasource($selectedScreen, datasource)
return Object.keys(schema || {})
}

View File

@ -1,13 +1,13 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset, componentStore } from "stores/builder"
import { selectedScreen, componentStore } from "stores/builder"
import { getActionProviders } from "../../../../../../dataBinding"
export let parameters
export let nested
$: actionProviders = getActionProviders(
$currentAsset,
$selectedScreen,
$componentStore.selectedComponentId,
"RefreshDatasource",
{ includeSelf: nested }

View File

@ -1,11 +1,11 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
import { findAllMatchingComponents } from "helpers/components"
export let parameters
$: components = findAllMatchingComponents($currentAsset?.props, component =>
$: components = findAllMatchingComponents($selectedScreen?.props, component =>
component._component.endsWith("s3upload")
)
</script>

View File

@ -1,6 +1,11 @@
<script>
import { Select, Label, Body, Checkbox, Input } from "@budibase/bbui"
import { currentAsset, componentStore, tables, viewsV2 } from "stores/builder"
import {
selectedScreen,
componentStore,
tables,
viewsV2,
} from "stores/builder"
import { getSchemaForDatasourcePlus } from "../../../../../../dataBinding"
import SaveFields from "./SaveFields.svelte"
import { getDatasourceLikeProviders } from "components/design/settings/controls/ButtonActionEditor/actions/utils"
@ -10,7 +15,7 @@
export let nested
$: providerOptions = getDatasourceLikeProviders({
asset: $currentAsset,
asset: $selectedScreen,
componentId: $componentStore.selectedComponentId,
nested,
})

View File

@ -1,5 +1,5 @@
<script>
import { currentAsset, componentStore } from "stores/builder"
import { selectedScreen, componentStore } from "stores/builder"
import { Label, Combobox, Select } from "@budibase/bbui"
import {
getActionProviders,
@ -11,13 +11,13 @@
export let nested
$: formComponent = getFormComponent(
$currentAsset.props,
$selectedScreen.props,
parameters.componentId
)
$: formSchema = buildFormSchema(formComponent)
$: fieldOptions = Object.keys(formSchema || {})
$: actionProviders = getActionProviders(
$currentAsset,
$selectedScreen,
$componentStore.selectedComponentId,
"ScrollTo",
{ includeSelf: nested }

View File

@ -2,7 +2,7 @@
import { Select, Label, Combobox } from "@budibase/bbui"
import { onMount } from "svelte"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
import { currentAsset, componentStore } from "stores/builder"
import { selectedScreen, componentStore } from "stores/builder"
import {
getActionProviders,
buildFormSchema,
@ -25,13 +25,13 @@
]
$: formComponent = getFormComponent(
$currentAsset.props,
$selectedScreen.props,
parameters.componentId
)
$: formSchema = buildFormSchema(formComponent)
$: fieldOptions = Object.keys(formSchema || {})
$: actionProviders = getActionProviders(
$currentAsset,
$selectedScreen,
$componentStore.selectedComponentId,
"ValidateForm",
{ includeSelf: nested }

View File

@ -1,13 +1,13 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset, componentStore } from "stores/builder"
import { getActionProviders } from "../../../../../../dataBinding"
import { selectedScreen, componentStore } from "stores/builder"
import { getActionProviders } from "dataBinding"
export let parameters
export let nested
$: actionProviders = getActionProviders(
$currentAsset,
$selectedScreen,
$componentStore.selectedComponentId,
"ValidateForm",
{ includeSelf: nested }

View File

@ -7,7 +7,7 @@
getDatasourceForProvider,
getSchemaForDatasource,
} from "../../../../../dataBinding"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
import { getFields } from "helpers/searchFields"
export let componentInstance
@ -21,8 +21,8 @@
let boundValue
$: text = getText(value)
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: schema = getSchema($currentAsset, datasource)
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: schema = getSchema($selectedScreen, datasource)
$: options = allowCellEditing
? Object.keys(schema || {})
: enrichedSchemaFields?.map(field => field.name)

View File

@ -1,14 +1,14 @@
<script>
import { Select } from "@budibase/bbui"
import { makePropSafe } from "@budibase/string-templates"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
import { findAllMatchingComponents } from "helpers/components"
export let value
const getValue = component => `{{ literal ${makePropSafe(component._id)} }}`
$: providers = findAllMatchingComponents($currentAsset?.props, c =>
$: providers = findAllMatchingComponents($selectedScreen?.props, c =>
c._component?.endsWith("/dataprovider")
)
</script>

View File

@ -22,7 +22,7 @@
queries as queriesStore,
viewsV2 as viewsV2Store,
views as viewsStore,
currentAsset,
selectedScreen,
componentStore,
datasources,
integrations,
@ -76,7 +76,7 @@
...query,
type: "query",
}))
$: dataProviders = findAllComponents($currentAsset.props)
$: dataProviders = findAllComponents($selectedScreen.props)
.filter(component => {
return (
component._component?.endsWith("/dataprovider") &&

View File

@ -7,7 +7,7 @@
getBindableProperties,
getComponentBindableProperties,
} from "../../../../../dataBinding"
import { selectedScreen, currentAsset, componentStore } from "stores/builder"
import { selectedScreen, componentStore } from "stores/builder"
import DraggableList from "../DraggableList/DraggableList.svelte"
import { createEventDispatcher } from "svelte"
import FieldSetting from "./FieldSetting.svelte"
@ -44,7 +44,7 @@
$: datasource =
componentInstance.dataSource ||
getDatasourceForProvider($currentAsset, componentInstance)
getDatasourceForProvider($selectedScreen, componentInstance)
$: resourceId = datasource?.resourceId || datasource?.tableId
@ -53,7 +53,7 @@
}
const updateState = value => {
schema = getSchema($currentAsset, datasource)
schema = getSchema($selectedScreen, datasource)
options = Object.keys(schema || {})
sanitisedValue = getValidColumns(convertOldFieldFormat(value), options)
updateSanitsedFields(sanitisedValue)

View File

@ -4,7 +4,7 @@
getDatasourceForProvider,
getSchemaForDatasource,
} from "../../../../dataBinding"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
import { createEventDispatcher } from "svelte"
export let componentInstance = {}
@ -12,8 +12,8 @@
export let placeholder
const dispatch = createEventDispatcher()
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: schema = getSchemaForDatasource($currentAsset, datasource).schema
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: schema = getSchemaForDatasource($selectedScreen, datasource).schema
$: options = Object.keys(schema || {})
$: boundValue = getValidValue(value, options)

View File

@ -6,7 +6,7 @@
getSchemaForDatasource,
} from "../../../../../dataBinding"
import FilterDrawer from "./FilterDrawer.svelte"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
const dispatch = createEventDispatcher()
@ -18,8 +18,8 @@
let drawer
$: tempValue = value
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: dsSchema = getSchemaForDatasource($currentAsset, datasource)?.schema
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: dsSchema = getSchemaForDatasource($selectedScreen, datasource)?.schema
$: schemaFields = Object.values(schema || dsSchema || {})
$: text = getText(value?.filter(filter => filter.field))

View File

@ -1,6 +1,6 @@
<script>
import { Combobox } from "@budibase/bbui"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
import { getComponentFieldOptions } from "helpers/formFields"
export let componentInstance
@ -8,7 +8,7 @@
export let type
$: options = getComponentFieldOptions(
$currentAsset?.props,
$selectedScreen?.props,
componentInstance?._id,
type
)

View File

@ -2,7 +2,7 @@
import { createEventDispatcher, setContext } from "svelte"
import ComponentSettingsSection from "../../../../pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/ComponentSettingsSection.svelte"
import { getDatasourceForProvider } from "../../../../dataBinding"
import { currentAsset, componentStore, previewStore } from "stores/builder"
import { selectedScreen, componentStore, previewStore } from "stores/builder"
import { Helpers } from "@budibase/bbui"
import { derived, writable } from "svelte/store"
import { Utils } from "@budibase/frontend-core"
@ -36,7 +36,7 @@
$: stepCount = cachedValue?.length || 0
$: updateStore(stepCount)
$: dataSource = getDatasourceForProvider($currentAsset, cachedInstance)
$: dataSource = getDatasourceForProvider($selectedScreen, cachedInstance)
$: emitCurrentStep($currentStep)
$: stepLabel = getStepLabel($multiStepStore)
$: stepDef = getDefinition(stepLabel)

View File

@ -3,7 +3,7 @@
getDatasourceForProvider,
getSchemaForDatasource,
} from "../../../../../dataBinding"
import { currentAsset, componentStore } from "stores/builder"
import { selectedScreen, componentStore } from "stores/builder"
import DraggableList from "../DraggableList/DraggableList.svelte"
import { createEventDispatcher } from "svelte"
import FieldSetting from "./FieldSetting.svelte"
@ -32,12 +32,12 @@
return schema
}
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: primaryDisplayColumnName = getSchemaForDatasource(
$currentAsset,
$selectedScreen,
datasource
)?.table?.primaryDisplay
$: schema = getSchema(currentAsset, datasource)
$: schema = getSchema(selectedScreen, datasource)
$: columns = getColumns({
columns: value,
schema,

View File

@ -4,7 +4,7 @@
getDatasourceForProvider,
getSchemaForDatasource,
} from "../../../../dataBinding"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
import { createEventDispatcher } from "svelte"
export let componentInstance = {}
@ -12,8 +12,8 @@
export let placeholder
const dispatch = createEventDispatcher()
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: schema = getSchemaForDatasource($currentAsset, datasource).schema
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: schema = getSchemaForDatasource($selectedScreen, datasource).schema
$: options = Object.keys(schema || {})
$: boundValue = getValidOptions(value, options)

View File

@ -7,7 +7,7 @@
getDatasourceForProvider,
getSchemaForDatasource,
} from "../../../../dataBinding"
import { tables, currentAsset, componentStore } from "stores/builder"
import { tables, selectedScreen, componentStore } from "stores/builder"
import FilterEditor from "./FilterEditor/FilterEditor.svelte"
export let componentInstance
@ -17,29 +17,29 @@
// Find the closest parent form
$: form = findClosestMatchingComponent(
$currentAsset.props,
$selectedScreen.props,
componentInstance._id,
component => component._component.endsWith("/form")
)
const resolveDatasource = (currentAsset, componentInstance, form) => {
const resolveDatasource = (selectedScreen, componentInstance, form) => {
if (!form && componentInstance._id != $componentStore.selectedComponentId) {
const block = findComponent(
currentAsset.props,
selectedScreen.props,
$componentStore.selectedComponentId
)
const def = componentStore.getDefinition(block._component)
return def?.block === true
? getDatasourceForProvider(currentAsset, block)
? getDatasourceForProvider(selectedScreen, block)
: {}
} else {
return getDatasourceForProvider(currentAsset, form)
return getDatasourceForProvider(selectedScreen, form)
}
}
// Get that form's schema
$: datasource = resolveDatasource($currentAsset, componentInstance, form)
$: formSchema = getSchemaForDatasource($currentAsset, datasource)?.schema
$: datasource = resolveDatasource($selectedScreen, componentInstance, form)
$: formSchema = getSchemaForDatasource($selectedScreen, datasource)?.schema
// Get the schema for the relationship field that this picker is using
$: columnSchema = formSchema?.[column]

View File

@ -1,6 +1,6 @@
<script>
import { ActionButton, notifications } from "@budibase/bbui"
import { currentAsset, componentStore } from "stores/builder"
import { selectedScreen, componentStore } from "stores/builder"
import { findClosestMatchingComponent } from "helpers/components"
import { makeDatasourceFormComponents } from "../../../../templates/commonComponents"
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
@ -11,7 +11,7 @@
const resetFormFields = async () => {
const form = findClosestMatchingComponent(
$currentAsset?.props,
$selectedScreen?.props,
componentInstance._id,
component => component._component.endsWith("/form")
)

View File

@ -4,7 +4,7 @@
getDatasourceForProvider,
getSchemaForDatasource,
} from "../../../../dataBinding"
import { currentAsset, tables } from "stores/builder"
import { selectedScreen, tables } from "stores/builder"
import { createEventDispatcher } from "svelte"
import { getFields } from "helpers/searchFields"
@ -13,8 +13,8 @@
export let placeholder
const dispatch = createEventDispatcher()
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: schema = getSchemaForDatasource($currentAsset, datasource).schema
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: schema = getSchemaForDatasource($selectedScreen, datasource).schema
$: options = getOptions(datasource, schema || {})
$: boundValue = getSelectedOption(value, options)

View File

@ -4,7 +4,7 @@
getDatasourceForProvider,
getSchemaForDatasource,
} from "../../../../dataBinding"
import { currentAsset } from "stores/builder"
import { selectedScreen } from "stores/builder"
import { createEventDispatcher } from "svelte"
import { canBeSortColumn } from "@budibase/shared-core"
@ -13,8 +13,8 @@
export let placeholder
const dispatch = createEventDispatcher()
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: schema = getSchemaForDatasource($currentAsset, datasource).schema
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: schema = getSchemaForDatasource($selectedScreen, datasource).schema
$: options = getSortableFields(schema)
$: boundValue = getValidValue(value, options)

View File

@ -10,7 +10,7 @@
Input,
DatePicker,
} from "@budibase/bbui"
import { currentAsset, selectedComponent } from "stores/builder"
import { selectedScreen, selectedComponent } from "stores/builder"
import { findClosestMatchingComponent } from "helpers/components"
import {
getSchemaForDatasource,
@ -127,13 +127,14 @@
],
}
const resolveDatasource = (currentAsset, componentInstance, parent) => {
const resolveDatasource = (selectedScreen, componentInstance, parent) => {
return (
getDatasourceForProvider(currentAsset, parent || componentInstance) || {}
getDatasourceForProvider(selectedScreen, parent || componentInstance) ||
{}
)
}
$: dataSourceSchema = getDataSourceSchema($currentAsset, $selectedComponent)
$: dataSourceSchema = getDataSourceSchema($selectedScreen, $selectedComponent)
$: field = fieldName || $selectedComponent?.field
$: schemaRules = parseRulesFromSchema(field, dataSourceSchema || {})
$: fieldType = type?.split("/")[1] || "string"

View File

@ -7,7 +7,6 @@ import {
findComponentPath,
} from "helpers/components"
import {
currentAsset,
componentStore,
screenStore,
appStore,
@ -15,6 +14,7 @@ import {
queries as queriesStores,
tables as tablesStore,
roles as rolesStore,
selectedScreen,
} from "stores/builder"
import {
makePropSafe,
@ -731,13 +731,11 @@ export const getEventContextBindings = ({
asset,
}) => {
let bindings = []
const selectedAsset = asset ?? get(currentAsset)
asset = asset ?? get(selectedScreen)
// Check if any context bindings are provided by the component for this
// setting
const component =
componentInstance ?? findComponent(selectedAsset.props, componentId)
const component = componentInstance ?? findComponent(asset.props, componentId)
if (!component) {
return bindings

View File

@ -9,7 +9,6 @@
appStore,
navigationStore,
selectedScreen,
currentAsset,
hoverStore,
} from "stores/builder"
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
@ -144,7 +143,7 @@
const { key, ctrlKey } = data
document.dispatchEvent(new KeyboardEvent("keydown", { key, ctrlKey }))
} else if (type === "duplicate-component" && data.id) {
const rootComponent = get(currentAsset).props
const rootComponent = get(selectedScreen).props
const component = findComponent(rootComponent, data.id)
componentStore.copy(component)
await componentStore.paste(component)
@ -154,7 +153,7 @@
loading = false
} else if (type === "move-component") {
const { componentId, destinationComponentId } = data
const rootComponent = get(currentAsset).props
const rootComponent = get(selectedScreen).props
// Get source and destination components
const source = findComponent(rootComponent, componentId)

View File

@ -7,12 +7,7 @@ import {
} from "./components"
import { navigationStore } from "./navigation.js"
import { themeStore } from "./theme.js"
import {
screenStore,
selectedScreen,
currentAsset,
sortedScreens,
} from "./screens.js"
import { screenStore, selectedScreen, sortedScreens } from "./screens.js"
import { builderStore } from "./builder.js"
import { hoverStore } from "./hover.js"
import { previewStore } from "./preview.js"
@ -52,7 +47,6 @@ export {
automationStore,
selectedAutomation,
automationHistoryStore,
currentAsset,
sortedScreens,
userStore,
isOnlyUser,

View File

@ -483,8 +483,6 @@ export const selectedScreen = derived(screenStore, $store => {
return $store.screens.find(screen => screen._id === $store.selectedScreenId)
})
export const currentAsset = selectedScreen
export const sortedScreens = derived(screenStore, $screenStore => {
return $screenStore.screens.slice().sort((a, b) => {
// Sort by role first

View File

@ -106,6 +106,10 @@ export default defineConfig(({ mode }) => {
find: "stores",
replacement: path.resolve("./src/stores"),
},
{
find: "dataBinding",
replacement: path.resolve("./src/dataBinding.js"),
},
{
find: "api",
replacement: path.resolve("./src/api.js"),