diff --git a/README.md b/README.md index 35b84a8816..4979f0ee8e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The low code platform you'll enjoy using

- Budibase is an open source low-code platform, and the easiest way to build internal apps that improve productivity. + Budibase is an open-source low-code platform that saves engineers 100s of hours building forms, portals, and approval apps, securely.

@@ -20,7 +20,7 @@

- Budibase design ui + Budibase design ui

@@ -57,7 +57,7 @@ ## ✨ Features ### Build and ship real software -Unlike other platforms, with Budibase you build and ship single page applications. Budibase applications have performance baked in and can be designed responsively, providing your users with a great experience. +Unlike other platforms, with Budibase you build and ship single page applications. Budibase applications have performance baked in and can be designed responsively, providing users with a great experience.

### Open source and extensible @@ -65,40 +65,36 @@ Budibase is open-source - licensed as GPL v3. This should fill you with confiden

### Load data or start from scratch -Budibase pulls in data from multiple sources, including MongoDB, CouchDB, PostgreSQL, MySQL, Airtable, S3, DynamoDB, or a REST API. And unlike other platforms, with Budibase you can start from scratch and create business apps with no datasources. [Request new datasources](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas). +Budibase pulls data from multiple sources, including MongoDB, CouchDB, PostgreSQL, MySQL, Airtable, S3, DynamoDB, or a REST API. And unlike other platforms, with Budibase you can start from scratch and create business apps with no data sources. [Request new datasources](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).

- Budibase data + Budibase data



### Design and build apps with powerful pre-made components -Budibase comes out of the box with beautifully designed, powerful components which you can use like building blocks to build your UI. We also expose a lot of your favourite CSS styling options so you can go that extra creative mile. [Request new component](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas). +Budibase comes out of the box with beautifully designed, powerful components which you can use like building blocks to build your UI. We also expose many of your favourite CSS styling options so you can go that extra creative mile. [Request new component](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).

- Budibase design + Budibase design



-### Automate processes, integrate with other tools, and connect to webhooks -Save time by automating manual processes and workflows. From connecting to webhooks, to automating emails, simply tell Budibase what to do and let it work for you. You can easily [create new automations for Budibase here](https://github.com/Budibase/automations) or [Request new automation](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas). - -

- Budibase automations -

+### Automate processes, integrate with other tools and connect to webhooks +Save time by automating manual processes and workflows. From connecting to webhooks to automating emails, simply tell Budibase what to do and let it work for you. You can easily [create new automations for Budibase here](https://github.com/Budibase/automations) or [Request new automation](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).

### Integrate with your favorite tools Budibase integrates with a number of popular tools allowing you to build apps that perfectly fit your stack.

- Budibase integrations + Budibase integrations



-### Admin paradise -Budibase is made to scale. With Budibase, you can self-host on your own infrastructure and globally manage users, onboarding, SMTP, apps, groups, theming and more. You can also provide users/groups with an app portal and disseminate user-management to the group manager. +### Deploy with confidence and security +Budibase is made to scale. With Budibase, you can self-host on your own infrastructure and globally manage users, onboarding, SMTP, apps, groups, theming and more. You can also provide users/groups with an app portal and disseminate user management to the group manager. - Checkout the promo video: https://youtu.be/xoljVpty_Kw @@ -119,17 +115,14 @@ As with anything that we build in Budibase, our new public API is simple to use, #### Docs You can learn more about the Budibase API at the following places: -- [General documentation](https://docs.budibase.com/docs/public-api) : Learn how to get your API key, how to use spec, and how to use with Postman +- [General documentation](https://docs.budibase.com/docs/public-api): Learn how to get your API key, how to use spec, and how to use Postman - [Interactive API documentation](https://docs.budibase.com/reference/post_applications) : Learn how to interact with the API -#### Guides - -- [Build an app with Budibase and Next.js](https://budibase.com/blog/building-a-crud-app-with-budibase-and-next.js/) +

## 🏁 Get started -Deploy Budibase self-hosted in your existing infrastructure, using Docker, Kubernetes, and Digital Ocean. -Or use Budibase Cloud if you don't need to self-host, and would like to get started quickly. +Deploy Budibase using Docker, Kubernetes, and Digital Ocean on your existing infrastructure. Or use Budibase Cloud if you don't need to self-host and would like to get started quickly. ### [Get started with self-hosting Budibase](https://docs.budibase.com/docs/hosting-methods) @@ -162,7 +155,7 @@ If you have a question or would like to talk with other Budibase users and join ## ❗ Code of conduct -Budibase is dedicated to providing a welcoming, diverse, and harrassment-free experience for everyone. We expect everyone in the Budibase community to abide by our [**Code of Conduct**](https://github.com/Budibase/budibase/blob/HEAD/docs/CODE_OF_CONDUCT.md). Please read it. +Budibase is dedicated to providing everyone a welcoming, diverse, and harassment-free experience. We expect everyone in the Budibase community to abide by our [**Code of Conduct**](https://github.com/Budibase/budibase/blob/HEAD/docs/CODE_OF_CONDUCT.md). Please read it.
@@ -171,16 +164,16 @@ Budibase is dedicated to providing a welcoming, diverse, and harrassment-free ex ## 🙌 Contributing to Budibase -From opening a bug report to creating a pull request: every contribution is appreciated and welcomed. If you're planning to implement a new feature or change the API please create an issue first. This way we can ensure your work is not in vain. -Environment setup instructions are available for [Debian](https://github.com/Budibase/budibase/tree/HEAD/docs/DEV-SETUP-DEBIAN.md) and [MacOSX](https://github.com/Budibase/budibase/tree/HEAD/docs/DEV-SETUP-MACOSX.md) +From opening a bug report to creating a pull request: every contribution is appreciated and welcomed. If you're planning to implement a new feature or change the API, please create an issue first. This way, we can ensure your work is not in vain. +Environment setup instructions are available [here](https://github.com/Budibase/budibase/tree/HEAD/docs/CONTRIBUTING.md). ### Not Sure Where to Start? -A good place to start contributing, is the [First time issues project](https://github.com/Budibase/budibase/projects/22). +A good place to start contributing is the [First time issues project](https://github.com/Budibase/budibase/projects/22). ### How the repository is organized Budibase is a monorepo managed by lerna. Lerna manages the building and publishing of the budibase packages. At a high level, here are the packages that make up Budibase. -- [packages/builder](https://github.com/Budibase/budibase/tree/HEAD/packages/builder) - contains code for the budibase builder client side svelte application. +- [packages/builder](https://github.com/Budibase/budibase/tree/HEAD/packages/builder) - contains code for the budibase builder client-side svelte application. - [packages/client](https://github.com/Budibase/budibase/tree/HEAD/packages/client) - A module that runs in the browser responsible for reading JSON definition and creating living, breathing web apps from it. @@ -193,7 +186,7 @@ For more information, see [CONTRIBUTING.md](https://github.com/Budibase/budibase ## 📝 License -Budibase is open-source, licensed as [GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html). The client and component libraries are licensed as [MPL](https://directory.fsf.org/wiki/License:MPL-2.0) - so the apps that you build can be licensed however you like. +Budibase is open-source, licensed as [GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html). The client and component libraries are licensed as [MPL](https://directory.fsf.org/wiki/License:MPL-2.0) - so the apps you build can be licensed however you like.

diff --git a/docs/DEV-SETUP-DEBIAN.md b/docs/DEV-SETUP-DEBIAN.md deleted file mode 100644 index e098862c64..0000000000 --- a/docs/DEV-SETUP-DEBIAN.md +++ /dev/null @@ -1,76 +0,0 @@ -## Dev Environment on Debian 11 - -### Install NVM & Node 14 - -NVM documentation: https://github.com/nvm-sh/nvm#installing-and-updating - -Install NVM - -``` -curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash -``` - -Install Node 14 - -``` -nvm install 14 -``` - -### Install npm requirements - -``` -npm install -g yarn jest lerna -``` - -### Install Docker and Docker Compose - -``` -apt install docker.io -pip3 install docker-compose -``` - -### Clone the repo - -``` -git clone https://github.com/Budibase/budibase.git -``` - -### Check Versions - -This setup process was tested on Debian 11 (bullseye) with version numbers show below. Your mileage may vary using anything else. - -- Docker: 20.10.5 -- Docker-Compose: 1.29.2 -- Node: v14.20.1 -- Yarn: 1.22.19 -- Lerna: 5.1.4 - -### Build - -``` -cd budibase -yarn setup -``` - -The yarn setup command runs several build steps i.e. - -``` -node ./hosting/scripts/setup.js && yarn && yarn build && yarn dev -``` - -So this command will actually run the application in dev mode. It creates .env files under `./packages/server` and `./packages/worker` and runs docker containers for each service via docker-compose. - -The dev version will be available on port 10000 i.e. - -http://127.0.0.1:10000/builder/admin - -### File descriptor issues with Vite and Chrome in Linux - -If your dev environment stalls forever, with some network requests stuck in flight, it's likely that Chrome is trying to open more file descriptors than your system allows. -To fix this, apply the following tweaks. - -Debian based distros: -Add `* - nofile 65536` to `/etc/security/limits.conf`. - -Arch: -Add `DefaultLimitNOFILE=65536` to `/etc/systemd/system.conf`. diff --git a/docs/DEV-SETUP-MACOSX.md b/docs/DEV-SETUP-MACOSX.md deleted file mode 100644 index 0e13d540b3..0000000000 --- a/docs/DEV-SETUP-MACOSX.md +++ /dev/null @@ -1,84 +0,0 @@ -## Dev Environment on MAC OSX 12 (Monterey) - -### Install Homebrew - -Install instructions [here](https://brew.sh/) - -| **NOTE**: If you are working on a M1 Apple Silicon which is running Z shell, you could need to add -`eval $(/opt/homebrew/bin/brew shellenv)` line to your `.zshrc`. This will make your zsh to find the apps you install -through brew. - -### Install Node - -Budibase requires a recent version of node 14: - -``` -brew install node npm -node -v -``` - -### Install npm requirements - -``` -npm install -g yarn jest lerna -``` - -### Install Docker and Docker Compose - -``` -brew install docker docker-compose -``` - -### Clone the repo - -``` -git clone https://github.com/Budibase/budibase.git -``` - -### Check Versions - -This setup process was tested on Mac OSX 12 (Monterey) with version numbers shown below. Your mileage may vary using anything else. - -- Docker: 20.10.14 -- Docker-Compose: 2.6.0 -- Node: 14.20.1 -- Yarn: 1.22.19 -- Lerna: 5.1.4 - -### Build - -``` -cd budibase -yarn setup -``` - -The yarn setup command runs several build steps i.e. - -``` -node ./hosting/scripts/setup.js && yarn && yarn build && yarn dev -``` - -So this command will actually run the application in dev mode. It creates .env files under `./packages/server` and `./packages/worker` and runs docker containers for each service via docker-compose. - -The dev version will be available on port 10000 i.e. - -http://127.0.0.1:10000/builder/admin - -| **NOTE**: If you are working on a M1 Apple Silicon, you will need to uncomment `# platform: linux/amd64` line in -[hosting/docker-compose-dev.yaml](../hosting/docker-compose.dev.yaml) - -### Troubleshootings - -#### Yarn setup errors - -If there are errors with the `yarn setup` command, you can try installing nvm and node 14. This is the same as the instructions for Debian 11. - -#### Node 14.20.1 not supported for arm64 - -If you are working with M1 or M2 Mac and trying the Node installation via `nvm`, probably you will find the error `curl: (22) The requested URL returned error: 404`. - -Version `v14.20.1` is not supported for arm64; in order to use it, you can switch the CPU architecture for this by the following command: - -```shell -arch -x86_64 zsh #Run this before nvm install -``` diff --git a/docs/DEV-SETUP-WINDOWS.md b/docs/DEV-SETUP-WINDOWS.md deleted file mode 100644 index f26a5a0882..0000000000 --- a/docs/DEV-SETUP-WINDOWS.md +++ /dev/null @@ -1,92 +0,0 @@ -## Dev Environment on Windows 10/11 (WSL2) - -### Install WSL with Ubuntu LTS - -Enable WSL 2 on Windows 10/11 for docker support. - -``` -wsl --set-default-version 2 -``` - -Install Ubuntu LTS. - -``` -wsl --install Ubuntu -``` - -Or follow the instruction here: -https://learn.microsoft.com/en-us/windows/wsl/install - -### Install Docker in windows - -Download the installer from docker and install it. - -Check this url for more detailed instructions: -https://docs.docker.com/desktop/install/windows-install/ - -You should follow the next steps from within the Ubuntu terminal. - -### Install NVM & Node 14 - -NVM documentation: https://github.com/nvm-sh/nvm#installing-and-updating - -Install NVM - -``` -curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash -``` - -Install Node 14 - -``` -nvm install 14 -``` - -### Install npm requirements - -``` -npm install -g yarn jest lerna -``` - -### Clone the repo - -``` -git clone https://github.com/Budibase/budibase.git -``` - -### Check Versions - -This setup process was tested on Windows 11 with version numbers show below. Your mileage may vary using anything else. - -- Docker: 20.10.7 -- Docker-Compose: 2.10.2 -- Node: v14.20.1 -- Yarn: 1.22.19 -- Lerna: 5.5.4 - -### Build - -``` -cd budibase -yarn setup -``` - -The yarn setup command runs several build steps i.e. - -``` -node ./hosting/scripts/setup.js && yarn && yarn build && yarn dev -``` - -So this command will actually run the application in dev mode. It creates .env files under `./packages/server` and `./packages/worker` and runs docker containers for each service via docker-compose. - -The dev version will be available on port 10000 i.e. - -http://127.0.0.1:10000/builder/admin - -### Working with the code - -Here are the instructions to work on the application from within Visual Studio Code (in Windows) through the WSL. All the commands and files are within the Ubuntu system and it should run as if you were working on a Linux machine. - -https://code.visualstudio.com/docs/remote/wsl - -Note you will be able to run the application from within the WSL terminal and you will be able to access the application from the a browser in Windows. diff --git a/i18n/README.es.md b/i18n/README.es.md index 227d5d5d5f..a7d1112914 100644 --- a/i18n/README.es.md +++ b/i18n/README.es.md @@ -207,8 +207,7 @@ Desde comunicar un bug a solventar un error en el codigo, toda contribucion es a implementar una nueva funcionalidad o un realizar un cambio en la API, por favor crea un [nuevo mensaje aqui](https://github.com/Budibase/budibase/issues), de esta manera nos encargaremos que tu trabajo no sea en vano. -Aqui tienes instrucciones de como configurar tu entorno Budibase para [Debian](https://github.com/Budibase/budibase/tree/HEAD/docs/DEV-SETUP-DEBIAN.md) -y [MacOSX](https://github.com/Budibase/budibase/tree/HEAD/docs/DEV-SETUP-MACOSX.md) +Aqui tienes instrucciones de como configurar tu entorno Budibase para [aquí](https://github.com/Budibase/budibase/tree/HEAD/docs/CONTRIBUTING.md). ### No estas seguro por donde empezar? Un buen lugar para empezar a contribuir con nosotros es [aqui](https://github.com/Budibase/budibase/projects/22). diff --git a/lerna.json b/lerna.json index 4049d5d734..f91c51d4bb 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.15.6", + "version": "2.16.0", "npmClient": "yarn", "packages": [ "packages/*", diff --git a/package.json b/package.json index 8c2b6b099c..af4c540604 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "kill-accountportal": "kill-port 3001 4003", "kill-all": "yarn run kill-builder && yarn run kill-server && yarn kill-accountportal", "dev": "yarn run kill-all && lerna run --parallel prebuild && lerna run --stream dev --ignore=@budibase/account-portal-ui --ignore @budibase/account-portal-server", - "dev:noserver": "yarn run kill-builder && lerna run --stream dev:stack:up && lerna run --stream dev --ignore @budibase/backend-core --ignore @budibase/server --ignore @budibase/worker --ignore=@budibase/account-portal-ui --ignore @budibase/account-portal-server", + "dev:noserver": "yarn run kill-builder && lerna run --stream dev:stack:up --ignore @budibase/account-portal-server && lerna run --stream dev --ignore @budibase/backend-core --ignore @budibase/server --ignore @budibase/worker --ignore=@budibase/account-portal-ui --ignore @budibase/account-portal-server", "dev:server": "yarn run kill-server && lerna run --stream dev --scope @budibase/worker --scope @budibase/server", "dev:accountportal": "yarn kill-accountportal && lerna run dev --stream --scope @budibase/account-portal-ui --scope @budibase/account-portal-server", "dev:all": "yarn run kill-all && lerna run --stream dev", diff --git a/packages/account-portal b/packages/account-portal index 1b9fa56fd7..485ec16a9e 160000 --- a/packages/account-portal +++ b/packages/account-portal @@ -1 +1 @@ -Subproject commit 1b9fa56fd7b0991b4963de9f3e8b4711abdcae71 +Subproject commit 485ec16a9eed48c548a5f1239772139f3319f028 diff --git a/packages/builder/src/builderStore/componentUtils.js b/packages/builder/src/builderStore/componentUtils.js index a7ee3ff351..733ce0948e 100644 --- a/packages/builder/src/builderStore/componentUtils.js +++ b/packages/builder/src/builderStore/componentUtils.js @@ -92,7 +92,14 @@ export const findAllMatchingComponents = (rootComponent, selector) => { } /** - * Finds the closes parent component which matches certain criteria + * Recurses through the component tree and finds all components. + */ +export const findAllComponents = rootComponent => { + return findAllMatchingComponents(rootComponent, () => true) +} + +/** + * Finds the closest parent component which matches certain criteria */ export const findClosestMatchingComponent = ( rootComponent, diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 52368a0723..cc3851c318 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -1,6 +1,7 @@ import { cloneDeep } from "lodash/fp" import { get } from "svelte/store" import { + findAllComponents, findAllMatchingComponents, findComponent, findComponentPath, @@ -102,6 +103,9 @@ export const getAuthBindings = () => { return bindings } +/** + * Gets all bindings for environment variables + */ export const getEnvironmentBindings = () => { let envVars = get(environment).variables return envVars.map(variable => { @@ -130,26 +134,22 @@ export const toBindingsArray = (valueMap, prefix, category) => { if (!binding) { return acc } - let config = { type: "context", runtimeBinding: binding, readableBinding: `${prefix}.${binding}`, icon: "Brackets", } - if (category) { config.category = category } - acc.push(config) - return acc }, []) } /** - * Utility - coverting a map of readable bindings to runtime + * Utility to covert a map of readable bindings to runtime */ export const readableToRuntimeMap = (bindings, ctx) => { if (!bindings || !ctx) { @@ -162,7 +162,7 @@ export const readableToRuntimeMap = (bindings, ctx) => { } /** - * Utility - coverting a map of runtime bindings to readable + * Utility to covert a map of runtime bindings to readable bindings */ export const runtimeToReadableMap = (bindings, ctx) => { if (!bindings || !ctx) { @@ -188,15 +188,23 @@ export const getComponentBindableProperties = (asset, componentId) => { if (!def?.context) { return [] } + const contexts = Array.isArray(def.context) ? def.context : [def.context] // Get the bindings for the component - return getProviderContextBindings(asset, component) + const componentContext = { + component, + definition: def, + contexts, + } + return generateComponentContextBindings(asset, componentContext) } /** - * Gets all data provider components above a component. + * Gets all component contexts available to a certain component. This handles + * both global and local bindings, taking into account a component's position + * in the component tree. */ -export const getContextProviderComponents = ( +export const getComponentContexts = ( asset, componentId, type, @@ -205,30 +213,55 @@ export const getContextProviderComponents = ( if (!asset || !componentId) { return [] } + let map = {} - // Get the component tree leading up to this component, ignoring the component - // itself - const path = findComponentPath(asset.props, componentId) - if (!options?.includeSelf) { - path.pop() - } - - // Filter by only data provider components - return path.filter(component => { + // Processes all contexts exposed by a component + const processContexts = scope => component => { const def = store.actions.components.getDefinition(component._component) if (!def?.context) { - return false + return } - - // If no type specified, return anything that exposes context - if (!type) { - return true + if (!map[component._id]) { + map[component._id] = { + component, + definition: def, + contexts: [], + } } - - // Otherwise only match components with the specific context type const contexts = Array.isArray(def.context) ? def.context : [def.context] - return contexts.find(context => context.type === type) != null - }) + contexts.forEach(context => { + // Ensure type matches + if (type && context.type !== type) { + return + } + // Ensure scope matches + let contextScope = context.scope || "global" + if (contextScope !== scope) { + return + } + // Ensure the context is compatible with the component's current settings + if (!isContextCompatibleWithComponent(context, component)) { + return + } + map[component._id].contexts.push(context) + }) + } + + // Process all global contexts + const allComponents = findAllComponents(asset.props) + allComponents.forEach(processContexts("global")) + + // Process all local contexts + const localComponents = findComponentPath(asset.props, componentId) + localComponents.forEach(processContexts("local")) + + // Exclude self if required + if (!options?.includeSelf) { + delete map[componentId] + } + + // Only return components which provide at least 1 matching context + return Object.values(map).filter(x => x.contexts.length > 0) } /** @@ -240,20 +273,19 @@ export const getActionProviders = ( actionType, options = { includeSelf: false } ) => { - if (!asset || !componentId) { + if (!asset) { return [] } - // Get the component tree leading up to this component, ignoring the component - // itself - const path = findComponentPath(asset.props, componentId) - if (!options?.includeSelf) { - path.pop() - } + // Get all components + const components = findAllComponents(asset.props) // Find matching contexts and generate bindings let providers = [] - path.forEach(component => { + components.forEach(component => { + if (!options?.includeSelf && component._id === componentId) { + return + } const def = store.actions.components.getDefinition(component._component) const actions = (def?.actions || []).map(action => { return typeof action === "string" ? { type: action } : action @@ -317,142 +349,132 @@ export const getDatasourceForProvider = (asset, component) => { * Gets all bindable data properties from component data contexts. */ const getContextBindings = (asset, componentId) => { - // Extract any components which provide data contexts - const dataProviders = getContextProviderComponents(asset, componentId) + // Get all available contexts for this component + const componentContexts = getComponentContexts(asset, componentId) - // Generate bindings for all matching components - return getProviderContextBindings(asset, dataProviders) + // Generate bindings for each context + return componentContexts + .map(componentContext => { + return generateComponentContextBindings(asset, componentContext) + }) + .flat() } /** - * Gets the context bindings exposed by a set of data provider components. + * Generates a set of bindings for a given component context */ -const getProviderContextBindings = (asset, dataProviders) => { - if (!asset || !dataProviders) { +const generateComponentContextBindings = (asset, componentContext) => { + console.log("Hello ") + const { component, definition, contexts } = componentContext + if (!component || !definition || !contexts?.length) { return [] } - // Ensure providers is an array - if (!Array.isArray(dataProviders)) { - dataProviders = [dataProviders] - } - // Create bindings for each data provider let bindings = [] - dataProviders.forEach(component => { - const def = store.actions.components.getDefinition(component._component) - const contexts = Array.isArray(def.context) ? def.context : [def.context] + contexts.forEach(context => { + if (!context?.type) { + return + } - // Create bindings for each context block provided by this data provider - contexts.forEach(context => { - if (!context?.type) { + let schema + let table + let readablePrefix + let runtimeSuffix = context.suffix + + if (context.type === "form") { + // Forms do not need table schemas + // Their schemas are built from their component field names + schema = buildFormSchema(component, asset) + readablePrefix = "Fields" + } else if (context.type === "static") { + // Static contexts are fully defined by the components + schema = {} + const values = context.values || [] + values.forEach(value => { + schema[value.key] = { + name: value.label, + type: value.type || "string", + } + }) + } else if (context.type === "schema") { + // Schema contexts are generated dynamically depending on their data + const datasource = getDatasourceForProvider(asset, component) + if (!datasource) { return } + const info = getSchemaForDatasource(asset, datasource) + schema = info.schema + table = info.table - let schema - let table - let readablePrefix - let runtimeSuffix = context.suffix - - if (context.type === "form") { - // Forms do not need table schemas - // Their schemas are built from their component field names - schema = buildFormSchema(component, asset) - readablePrefix = "Fields" - } else if (context.type === "static") { - // Static contexts are fully defined by the components - schema = {} - const values = context.values || [] - values.forEach(value => { - schema[value.key] = { - name: value.label, - type: value.type || "string", - } - }) - } else if (context.type === "schema") { - // Schema contexts are generated dynamically depending on their data - const datasource = getDatasourceForProvider(asset, component) - if (!datasource) { - return - } - const info = getSchemaForDatasource(asset, datasource) - schema = info.schema - table = info.table - - // Determine what to prefix bindings with - if (datasource.type === "jsonarray") { - // For JSON arrays, use the array name as the readable prefix - const split = datasource.label.split(".") - readablePrefix = split[split.length - 1] - } else if (datasource.type === "viewV2") { - // For views, use the view name - const view = Object.values(table?.views || {}).find( - view => view.id === datasource.id - ) - readablePrefix = view?.name - } else { - // Otherwise use the table name - readablePrefix = info.table?.name - } - } - if (!schema) { - return - } - - const keys = Object.keys(schema).sort() - - // Generate safe unique runtime prefix - let providerId = component._id - if (runtimeSuffix) { - providerId += `-${runtimeSuffix}` - } - - if (!filterCategoryByContext(component, context)) { - return - } - - const safeComponentId = makePropSafe(providerId) - - // Create bindable properties for each schema field - keys.forEach(key => { - const fieldSchema = schema[key] - - // Make safe runtime binding - const safeKey = key.split(".").map(makePropSafe).join(".") - const runtimeBinding = `${safeComponentId}.${safeKey}` - - // Optionally use a prefix with readable bindings - let readableBinding = component._instanceName - if (readablePrefix) { - readableBinding += `.${readablePrefix}` - } - readableBinding += `.${fieldSchema.name || key}` - - const bindingCategory = getComponentBindingCategory( - component, - context, - def + // Determine what to prefix bindings with + if (datasource.type === "jsonarray") { + // For JSON arrays, use the array name as the readable prefix + const split = datasource.label.split(".") + readablePrefix = split[split.length - 1] + } else if (datasource.type === "viewV2") { + // For views, use the view name + const view = Object.values(table?.views || {}).find( + view => view.id === datasource.id ) + readablePrefix = view?.name + } else { + // Otherwise use the table name + readablePrefix = info.table?.name + } + } + if (!schema) { + return + } - // Create the binding object - bindings.push({ - type: "context", - runtimeBinding, - readableBinding, - // Field schema and provider are required to construct relationship - // datasource options, based on bindable properties - fieldSchema, - providerId, - // Table ID is used by JSON fields to know what table the field is in - tableId: table?._id, - component: component._component, - category: bindingCategory.category, - icon: bindingCategory.icon, - display: { - name: fieldSchema.name || key, - type: fieldSchema.type, - }, - }) + const keys = Object.keys(schema).sort() + + // Generate safe unique runtime prefix + let providerId = component._id + if (runtimeSuffix) { + providerId += `-${runtimeSuffix}` + } + const safeComponentId = makePropSafe(providerId) + + // Create bindable properties for each schema field + keys.forEach(key => { + const fieldSchema = schema[key] + + // Make safe runtime binding + const safeKey = key.split(".").map(makePropSafe).join(".") + const runtimeBinding = `${safeComponentId}.${safeKey}` + + // Optionally use a prefix with readable bindings + let readableBinding = component._instanceName + if (readablePrefix) { + readableBinding += `.${readablePrefix}` + } + readableBinding += `.${fieldSchema.name || key}` + + // Determine which category this binding belongs in + const bindingCategory = getComponentBindingCategory( + component, + context, + definition + ) + // Create the binding object + bindings.push({ + type: "context", + runtimeBinding, + readableBinding: `${readableBinding}`, + // Field schema and provider are required to construct relationship + // datasource options, based on bindable properties + fieldSchema, + providerId, + // Table ID is used by JSON fields to know what table the field is in + tableId: table?._id, + component: component._component, + category: bindingCategory.category, + icon: bindingCategory.icon, + display: { + name: `${fieldSchema.name || key}`, + type: fieldSchema.type, + }, }) }) }) @@ -460,25 +482,38 @@ const getProviderContextBindings = (asset, dataProviders) => { return bindings } -// Exclude a data context based on the component settings -const filterCategoryByContext = (component, context) => { - const { _component } = component +/** + * Checks if a certain data context is compatible with a certain instance of a + * configured component. + */ +const isContextCompatibleWithComponent = (context, component) => { + if (!component) { + return false + } + const { _component, actionType } = component + const { type } = context + + // Certain types of form blocks only allow certain contexts if (_component.endsWith("formblock")) { if ( - (component.actionType === "Create" && context.type === "schema") || - (component.actionType === "View" && context.type === "form") + (actionType === "Create" && type === "schema") || + (actionType === "View" && type === "form") ) { return false } } + + // Allow the context by default return true } // Enrich binding category information for certain components const getComponentBindingCategory = (component, context, def) => { + // Default category to component name let icon = def.icon let category = component._instanceName + // Form block edge case if (component._component.endsWith("formblock")) { if (context.type === "form") { category = `${component._instanceName} - Fields` @@ -496,7 +531,7 @@ const getComponentBindingCategory = (component, context, def) => { } /** - * Gets all bindable properties from the logged in user. + * Gets all bindable properties from the logged-in user. */ export const getUserBindings = () => { let bindings = [] @@ -566,6 +601,7 @@ const getDeviceBindings = () => { /** * Gets all selected rows bindings for tables in the current asset. + * TODO: remove in future because we don't need a separate store for this */ const getSelectedRowsBindings = asset => { let bindings = [] @@ -608,6 +644,9 @@ const getSelectedRowsBindings = asset => { return bindings } +/** + * Generates a state binding for a certain key name + */ export const makeStateBinding = key => { return { type: "context", @@ -662,6 +701,9 @@ const getUrlBindings = asset => { return urlParamBindings.concat([queryParamsBinding]) } +/** + * Generates all bindings for role IDs + */ const getRoleBindings = () => { return (get(rolesStore) || []).map(role => { return { @@ -1035,11 +1077,48 @@ export const getAllStateVariables = () => { getAllAssets().forEach(asset => { findAllMatchingComponents(asset.props, component => { const settings = getComponentSettings(component._component) - settings - .filter(setting => setting.type === "event") - .forEach(setting => { - eventSettings.push(component[setting.key]) - }) + + const parseEventSettings = (settings, comp) => { + settings + .filter(setting => setting.type === "event") + .forEach(setting => { + eventSettings.push(comp[setting.key]) + }) + } + + const parseComponentSettings = (settings, component) => { + // Parse the nested button configurations + settings + .filter(setting => setting.type === "buttonConfiguration") + .forEach(setting => { + const buttonConfig = component[setting.key] + + if (Array.isArray(buttonConfig)) { + buttonConfig.forEach(button => { + const nestedSettings = getComponentSettings(button._component) + parseEventSettings(nestedSettings, button) + }) + } + }) + + parseEventSettings(settings, component) + } + + // Parse the base component settings + parseComponentSettings(settings, component) + + // Parse step configuration + const stepSetting = settings.find( + setting => setting.type === "stepConfiguration" + ) + const steps = stepSetting ? component[stepSetting.key] : [] + const stepDefinition = getComponentSettings( + "@budibase/standard-components/multistepformblockstep" + ) + + steps.forEach(step => { + parseComponentSettings(stepDefinition, step) + }) }) }) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index c649a58504..55208bb97e 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -707,10 +707,9 @@ export const getFrontendStore = () => { else { if (setting.type === "dataProvider") { // Validate data provider exists, or else clear it - const treeId = parent?._id || component._id - const path = findComponentPath(screen?.props, treeId) - const providers = path.filter(component => - component._component?.endsWith("/dataprovider") + const providers = findAllMatchingComponents( + screen?.props, + component => component._component?.endsWith("/dataprovider") ) // Validate non-empty values const valid = providers?.some(dp => value.includes?.(dp._id)) @@ -732,6 +731,16 @@ export const getFrontendStore = () => { return null } + // Find all existing components of this type so that we can give this + // component a unique name + const screen = get(selectedScreen).props + const otherComponents = findAllMatchingComponents( + screen, + x => x._component === definition.component && x._id !== screen._id + ) + let name = definition.friendlyName || definition.name + name = `${name} ${otherComponents.length + 1}` + // Generate basic component structure let instance = { _id: Helpers.uuid(), @@ -741,7 +750,7 @@ export const getFrontendStore = () => { hover: {}, active: {}, }, - _instanceName: `New ${definition.friendlyName || definition.name}`, + _instanceName: name, ...presetProps, } diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index f9b688210a..91329525c3 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -373,6 +373,7 @@ confirmText="Save" onConfirm={saveRelationship} disabled={!valid} + size="L" >
Tables diff --git a/packages/builder/src/components/common/RelationshipSelector.svelte b/packages/builder/src/components/common/RelationshipSelector.svelte index 0636deaf08..63f0357a8f 100644 --- a/packages/builder/src/components/common/RelationshipSelector.svelte +++ b/packages/builder/src/components/common/RelationshipSelector.svelte @@ -17,7 +17,7 @@
-
+
diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/utils.js b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/utils.js index aa076fdd3e..bdcd3a7838 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/utils.js +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/utils.js @@ -1,5 +1,4 @@ -import { getContextProviderComponents } from "builderStore/dataBinding" -import { store } from "builderStore" +import { getComponentContexts } from "builderStore/dataBinding" import { capitalise } from "helpers" // Generates bindings for all components that provider "datasource like" @@ -8,58 +7,49 @@ import { capitalise } from "helpers" // Some examples are saving rows or duplicating rows. export const getDatasourceLikeProviders = ({ asset, componentId, nested }) => { // Get all form context providers - const formComponents = getContextProviderComponents( + const formComponentContexts = getComponentContexts( asset, componentId, "form", - { includeSelf: nested } + { + includeSelf: nested, + } ) - // Get all schema context providers - const schemaComponents = getContextProviderComponents( + const schemaComponentContexts = getComponentContexts( asset, componentId, "schema", - { includeSelf: nested } + { + includeSelf: nested, + } ) - // Generate contexts for all form providers - const formContexts = formComponents.map(component => ({ - component, - context: extractComponentContext(component, "form"), - })) - - // Generate contexts for all schema providers - const schemaContexts = schemaComponents.map(component => ({ - component, - context: extractComponentContext(component, "schema"), - })) - // Check for duplicate contexts by the same component. In this case, attempt // to label contexts with their suffixes - schemaContexts.forEach(schemaContext => { + schemaComponentContexts.forEach(schemaContext => { // Check if we have a form context for this component const id = schemaContext.component._id - const existing = formContexts.find(x => x.component._id === id) + const existing = formComponentContexts.find(x => x.component._id === id) if (existing) { - if (existing.context.suffix) { - const suffix = capitalise(existing.context.suffix) + if (existing.contexts[0].suffix) { + const suffix = capitalise(existing.contexts[0].suffix) existing.readableSuffix = ` - ${suffix}` } - if (schemaContext.context.suffix) { - const suffix = capitalise(schemaContext.context.suffix) + if (schemaContext.contexts[0].suffix) { + const suffix = capitalise(schemaContext.contexts[0].suffix) schemaContext.readableSuffix = ` - ${suffix}` } } }) // Generate bindings for all contexts - const allContexts = formContexts.concat(schemaContexts) - return allContexts.map(({ component, context, readableSuffix }) => { + const allContexts = formComponentContexts.concat(schemaComponentContexts) + return allContexts.map(({ component, contexts, readableSuffix }) => { let readableBinding = component._instanceName let runtimeBinding = component._id - if (context.suffix) { - runtimeBinding += `-${context.suffix}` + if (contexts[0].suffix) { + runtimeBinding += `-${contexts[0].suffix}` } if (readableSuffix) { readableBinding += readableSuffix @@ -70,13 +60,3 @@ export const getDatasourceLikeProviders = ({ asset, componentId, nested }) => { } }) } - -// Gets a context definition of a certain type from a component definition -const extractComponentContext = (component, contextType) => { - const def = store.actions.components.getDefinition(component?._component) - if (!def) { - return null - } - const contexts = Array.isArray(def.context) ? def.context : [def.context] - return contexts.find(context => context?.type === contextType) -} diff --git a/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte b/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte index 83255ec325..9fd220e798 100644 --- a/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte @@ -1,15 +1,16 @@