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

[tree view] Explore a better plugin model API #11567

Merged
merged 13 commits into from
Jan 12, 2024

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Jan 3, 2024

It is purely a private API but I'm trying to prepare the headless tree view step by step.

The problems I am trying to solve here are:

  • The controlledProp is not needed because the model name (the key of the object in useXXX.models) has to be equal to the controlled props (otherwise I can't deduce the type of models.xxx.value from the props).

    Solutions:

    • Remove the controlledProp from the model initialized and always use the model name.
  • The defaultValueProp do not enforce that props[defaultValueProp] contains a value compatible with the controlled prop type.

    Solutions:

    • Replacing it with a callback (it makes the API slightly more verbose but it solves this issue)
  • Calling models.xxx.setValue do not call the props callback (e.g: props.onExpandedNodesChange). This is very problematic because any plugin can call models.xxx.setValue but it's always a bad idea to do it.

    Solutions:

    • Removing the models.xxx.setValue on the typings of models defined in dependencies of the plugin makes sure that, at least with TS, you can't do this mistake.
    • Renaming models.xxx.setValue => models.xxx.setControlledValue to reduce the risk when using pure JS. To have a real safeguard we would need to generate the models object for each plugin, I'm not sure the perf overhead is worth it.

@flaviendelangle flaviendelangle self-assigned this Jan 3, 2024
@flaviendelangle flaviendelangle added the component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! label Jan 3, 2024
@mui-bot
Copy link

mui-bot commented Jan 3, 2024

Deploy preview: https://deploy-preview-11567--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 1b05695

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 3, 2024
Copy link

github-actions bot commented Jan 3, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 3, 2024
Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

@flaviendelangle flaviendelangle merged commit 69f1ca4 into mui:next Jan 12, 2024
15 checks passed
@flaviendelangle flaviendelangle deleted the models-api branch January 12, 2024 15:17
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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants