Create fastApi helper functions and update project config to export tooling files #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

fastApiTableAdapterandfastApiTableAdapterComposablefunctions to act as an interface between the table component and a FastAPI-based backend/toolsfolderExplanation about the PR
New export is added for the Connect UI Toolkit
Before we only had the main export:
Now we also have the FastApi helpers, exported under the
/toolsnamespace:The helpers are exported into their own file so we can add new side functionality to the toolkit without adding extra weight into the core toolkit export.
FastApi helpers
Two new files are added to make our lives easier when using a FastApi-based backend for Connect extensions,
fastApiTableAdapterandfastApiTableAdapterComposable.These are meant to be used with the upcoming complex table component, so we don't have to repeat code in the extensions.
fastApiTableAdapteris a vanilla JS module, a function that takes an endpoint string and returns some functions such asload,nextorfilter.fastApiTableAdapterComposableis a Vue 3 composable wrapper over the base adapter, that exports some reactive state besides the adapter methods. Check the files and their tests for more information on how they work, or just ask in the comments.Example of how this could be used:
As you can see from this example, the only thing required is to specify the API endpoint used. The variables exposed by the composable are reactive, so when we call
load, theloadingvariable will change its value totrue, the endpoint will be called, theitemsandtotalproperties will be updated from the response, and then theloadingvariable will be assigned tofalseautomatically.When the
nextevent is triggered by the table, thenextmethod from the composable will increase the page number and do the same as for theloadmethod, and the same can be said for the other methods.Changes in project configuration
Each subproject will have its own tooling configuration (config for build, test, etc.). Luckily for us, every tool we use supports this scenario. Let's see the example for webpack config:
In the root folder we have our base
webpack.config.js. Webpack allows to export multiple configurations, so we can leverage this functionality by having a configuration for each subproject.In our case, we have a config file for the base UI Toolkit (
./components/webpack.config.js) and another for the tools (./tools/webpack.config.js). Each config is independent, so we can customise them to add only what is required. Simplifies the configs a lot.If we want to add another export under tools, we only need to deal with the configuration files of the
./toolsfolder; less chance to mess other things.Same pattern applies for Jest config. Let me know if you have any questions, I can explain further, it's a pretty interesting topic.
Other changes
./tasks/startscript is removed. This is not required, since we can have the same functionality just by running the basewebpack-dev-serverpackage with our current Webpack configuration. Also, this can handle multiple configurations perfectly fine. Less custom code -> better code.webpack-dev-serverwe can start an HTTPS server to serve the project while developing. Useful if we want to check this in some scenarios. The command isnpm run start:https;npm run build:corebuilds the project using only the Webpack config for the./componentsfoldernpm run build:toolsbuilds the project using only the Webpack config for the./toolsfolder