wip: component auto import
This is a POC for automatically importing custom components into the BEAM app. #165
TBD: the actual structure of the hook in customer_app/hooks.py
This PR does not address any custom routing requirements, which is very likely required.
Coverage Report
@agritheory I think we have a few additional scenarios here (that may be inclusive with each other):
-
Component discovery: If a user wants to expose a directory under which their custom Beam components would live, then we should be able to apply that via hooks too.
- I think the structure of the hooks might be an array of paths to match the
dirsproperty ofunplugin. - This would allow users to develop new components in a single place without having to manually register each component, and also allow over-writing existing Beam components.
- We could also allow users to exclude components from being registered (either explicitly via the config or by disabling sub-directory discovery and nesting components in a different or sub-directory).
- I think the structure of the hooks might be an array of paths to match the
- Routing: You've already covered this in #165 but additional routes could also be over-written or extended on top of the default Beam routes.
I'm thinking the hooks structure could look something like the following (if we wanted pure Python):
# hooks.py
beam_override = {
"components": ["./custom_app/beam/components/"],
# (or alternatively)
# "components": {"Repack": "./custom_app/beam/components/Repack.vue"},
"routes": [
{
path: '/repack',
name: 'repack',
component: "Repack.vue",
meta: { "doctype": "Stock Entry", "requiresAuth": True },
}
],
}
or something like this (if we wanted to process JS/TS files directly instead):
# hooks.py
beam_override_file = "public/js/beam/setup.ts"
// setup.ts
// if we wanted to supply a directory
const dirs = ["./custom_app/beam/components/"]
// if we wanted to explicitly define components
import Repack from "./custom_app/beam/components/Repack.vue"
const components = { Repack: Repack }
// if we wanted to over-write/extend routes
const routes = [
{
path: '/repack',
name: 'repack',
component: Repack,
meta: { "doctype": "Stock Entry", "requiresAuth": true },
}
]
export {
dirs,
components,
routes
}
The latter approach might also allow us to pass existing context to do stuff like dynamic routing.
This hook would be read in the Vite entry-file and the routes and components set up based on the priority order of: Custom App > Beam (default).
What do you think?
@Alchez hooks.py Is the appropriately default configuration file for a Frappe project, I think it's where we want to be. If functions are required, they can be serialized to JSON, which we're already doing in ATable's format function for example.
I it does make sense to respect a "just a directory" approach as well as listing individual files. These approaches can be combined with a "*" key:
"components": ["./custom_app/beam/components/"],
# (or alternatively)
# "components": {"*": "./custom_app/beam/components/"},
# "components": {"Repack": "./custom_app/beam/components/Repack.vue"},
@Alchez Got in some time on this this afternoon with the following WIP:
- hooks resolve in the apps resolution order as specified in apps.json
- Moved route and component config to hooks.py so the can be more easily overridden in config by client apps as needed
- Builds successfully but without importing the components or routes. That's based on this work that I didn't completely understand but seemed like a promising route
- Typing needs some attention, TS is not a fan of me saying "it's an object, what's the problem"
- We want the
/homepage to be configurable in the UI and role restricted, but that's a future step built on this work