[Fleet] Improve Egonomics and Clarity for Imports #100566
Labels
Team:Fleet
Team label for Observability Data Collection Fleet team
technical debt
Improvement of the software architecture and operational architecture
Wanted to call out two specific areas for improvements for how we import modules in the Fleet codebase:
1. Multiple imports from directories with the same name
It's common in the Fleet codebase that we import components from a few locations, e.g.
When two or more of these imports occur in same file, it can introduce some confusion around "what components come from where", e.g:
kibana/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/index.tsx
Lines 40 to 56 in a818b2a
In the above example, we have the following
component
imports:We might be able to improve clarity around these imports by using unique pathnames other than
components
to denote shared/common components, but there are likely other improvements we can make as well.For example, we could consider the following changes to the above imports:
This is something I came across a lot when moving files around during the implementation of #99848.
2. "Long-reaching" imports
We have a number of places - most notably when we import from
common
- where imports come from many directories above a given module. For example, in the same file as above:kibana/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/index.tsx
Line 46 in a818b2a
This seems to be mitigated by the convention of placing "checkpoint" modules that re-export from parent directories further down the chain, which act largely as a way to limit the number of directories we need to reach into, although they can also export application-level modules as well.
These kinds of noisy imports could potentially be resolved without the need for these intermediary "re-export" modules via TypeScript's path mapping feature, but that may require higher-level configuration changes in Kibana's TypeScript setup.
The text was updated successfully, but these errors were encountered: