Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TreeView] Improve typing to support optional dependencies in plugins and in the item #13523

Merged
merged 2 commits into from
Jun 19, 2024

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Jun 18, 2024

Internal improvements for #13388

If a function needs to execute some logic from a plugin, it can usually be done in two ways:

  1. The function calls some method exposed by the plugin (this is the role of the apiRef in both the Tree View and the Data Grid)
  2. The function calls a generic method that do not depend on the plugin and on which the plugin might be hooked (this is the role of the pre-processors on the Data Grid and of the item wrapper and enhancers on the Tree View. For now the Tree View have no concept of pre-processors because it does not require it yet).

Solution 1. is usually simpler to implement and to read, but it does not respect the separation of concern, if our function is inside a plugin A and wants to call a method of the plugin B, then we have a dependency, A require B in order to work.
For pro features, we tend to favor solution 2 to avoid leaking pro code inside the community package (which is why the item enhancers have been introduced for the Drag and Drop feature on the Tree View).
But on the Tree View, we also have to support 2 versions of the components in the same plan (SimpleTreeView and RichTreeView). @noraleonte is currently working on an editing feature that will only be available in the RichTreeView, this feature has a lot of dependencies (the keyboard navigation needs to be aware of it for example). We could rely on Solution 2 but it would make the codebase a lot harder to read. Instead, I am proposing to boost Solution 1. by introducing a notion of optional dependencies. The Plugin A is aware of the plugin B, it calls the method of the plugin B, but it is not sure if the plugin B is present or not.

@flaviendelangle flaviendelangle self-assigned this Jun 18, 2024
@flaviendelangle flaviendelangle added typescript component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! labels Jun 18, 2024
@@ -37,7 +37,7 @@ type TreeViewLogExpandedSignature = TreeViewPluginSignature<{
// The parameters of this plugin as they are passed to the plugin after calling `plugin.getDefaultizedParams`
defaultizedParams: TreeViewLogExpandedDefaultizedParameters;
// Dependencies of this plugin (we need the expansion plugin to access its model)
dependantPlugins: [UseTreeViewExpansionSignature];
dependencies: [UseTreeViewExpansionSignature];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do this renaming for a long time 😆

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, this is a relief 🙈

@mui-bot
Copy link

mui-bot commented Jun 18, 2024

@flaviendelangle flaviendelangle marked this pull request as ready for review June 18, 2024 07:54
Copy link
Contributor

@noraleonte noraleonte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, makes a lot of sense 🎉

@@ -37,7 +37,7 @@ type TreeViewLogExpandedSignature = TreeViewPluginSignature<{
// The parameters of this plugin as they are passed to the plugin after calling `plugin.getDefaultizedParams`
defaultizedParams: TreeViewLogExpandedDefaultizedParameters;
// Dependencies of this plugin (we need the expansion plugin to access its model)
dependantPlugins: [UseTreeViewExpansionSignature];
dependencies: [UseTreeViewExpansionSignature];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, this is a relief 🙈

@flaviendelangle flaviendelangle merged commit 6f68422 into mui:master Jun 19, 2024
17 checks passed
@flaviendelangle flaviendelangle deleted the optional-dependencies branch June 19, 2024 06:36
DungTiger pushed a commit to DungTiger/mui-x that referenced this pull request Jul 23, 2024
thomasmoon pushed a commit to thomasmoon/mui-x that referenced this pull request Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants