-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Limit access to the apiRef
methods depending on the plan and the calling place
#3166
Comments
I will improve the example later 馃憤 |
We need to account for cases like the one mentioned here #3154. In short - if you control the |
Taking these methods as example, const GridPagination = ({ state, setPage, setPageSize }) => {
const rootProps = useGridRootProps();
const paginationState = gridPaginationSelector(state);
return (
<TablePagination
count={paginationState.rowCount}
page={paginationState.page}
rowsPerPageOptions={rootProps.rowsPerPageOptions}
onPageChange={(e, page) => setPage(page)}
onRowsPerPageChange={(e) => setPageSize(Number(e.target.value)}
/>
)
}
I exposed above but I prefer to not pass the |
I don't see the interest of totally removing the Couldn't we let We could always pass the apiRef methods usefull in a component as slot (like in your example with |
If I understood, |
With my proposal, |
Ok, so then |
Yes, neither on the pro, free or premium
|
For me sounds good. We only need to consider that if we want to block a method, e.g. For the implementation, we could have a single context storing both all methods and only the public ones. The |
Fully agree on that.
With my proposal, you can hide private methods even on the pro when accessed outside of the Grid scope (with the apiRef returned by |
I love this feedback on the survey:
It reinforces how exposing the event and the state in the MIT version so developers can rebuild our features if they wish. Considering the average hourly rate of a developer in the world, after one day of work, it's likely a lot more expensive for the organization to have the dev work on it, than purchase one license. While the dev says the above, I'm pretty confident his manager will ask him to stop right away 馃槅. As long as MUI builds a great community around the MIT version, I think that we are good. TL;DR, I think that us spending time on exposing more of the apiRef (currently nothing, so it's easy to do more, one method would already be more) is the right move. |
Closed by #6388 |
Context: 馃И Notion: apiRef MIT vs. Commercial
Current behavior
Note that the following examples describes what is theoretically possible to do.
Some examples shows how to use undocumented internals of the grid, this should never be done and could produce unwanted behaviors.
User code with
DataGridPro
Outside of the scope of the grid
Users can initialize the
apiRef
withuseGridApiRef
and pass it to theDataGridPro
as a prop.They can then use all the methods of
apiRef
as long as they do it after the first render.Inside the scope of the grid
Users can access the
apiRef
withuseGridApiContext
.They can then use all the methods of
apiRef
.User code with
DataGrid
Outside of the scope of the grid
Users can't pass the
apiRef
prop to theDataGrid
and can therefore not use anyapiRef
feature.Inside the scope of the grid
Users can access the
apiRef
withuseGridApiContext
.They can then use all the methods of
apiRef
.See the examples of the
DataGridPro
above.Problems with the current behavior
We are exposing all our internals
We started prefixing our internals with
unstable_
and we do not document them.But they are still accessible and auto-completed on people IDEs.
Ideally, methods that should never be used outside of the package code should not be accessible in any way outside of the package.
The access to the
apiRef
is inconsistent on theDataGrid
Our documentation indicates that the
apiRef
is only available forDataGridPro
.This is for instance made explicit with the pro icon on this paragraph.
Yet, this example is using the
apiRef
on theDataGrid
and is fully valid.The access to the
apiRef
should not depend on where the user code is.Proposals
Create a
privateApiRef
Concept
Have two
apiRef
instead of a single one.publicApiRef
is created inuseGridApiRef
, it only contains the public methods of the current plan and is accessible withuseGridApiContext
privateApiRef
is created inuseGridApiInitialization
, it contains both the public and the private API, is used in all our feature hooks and in the components not overridable with component slots, it can be accessed withuseGridPrivateApiContext
Note that all the plan would use the
publicApiRef
, with a content that changes according to the plan if we want to set some method public only on the pro and / or premium plan.Implementation example
You can find a POC on my fork flaviendelangle#11 that shows how we could set private methods on the
apiRef
.There are probably other solutions that we can explore, the goal here is only to show that if we want to have limit what is exposed, it can be achieved without splitting the
apiRef
because both the public and the privateapiRef
includes all the public methodsDynamically set a method to be public / private
Usage of public methods
Just like today.
useGridApiContext
would return the public API not wrapped in the proxy.Usage of private methods
In the feature hooks, we would pass the wrapped
apiRef
so it would always have access to the private apis.In the components, if we are using a method that is private or that can be private depending on the plan wee would use a new
useGridPrivateApiContext
that returns the public API wrapped in the proxy.Open the
apiRef
to the users of theDataGrid
The team is in favor of letting users of the
DataGrid
pass anapiRef
prop to the grid, just like on theDataGridPro
.The following example would then be possible:
What would still be blocked on the free plan
Methods of pro-only features
Whatever solution we decide to implement. the methods added to the
apiRef
by hooks only present on theDataGridPro
would not be accessible on theDataGrid
. Even in our internal code they are not added to theapiRef
.For instance #2946 in adding a
apiRef.current.pinColumn
in the newuseGridColumnPinning
hook. This hook is not called on theDataGrid
so the method is never added to theapiRef
for theDataGrid
.Forced props would still apply
Giving access to methods like
apiRef.current.setFilterModel
to users of theDataGrid
will not bypass the fact that theDataGrid
can only set one filter item. If you try to pass several items toapiRef.current.setFilterModel
, you will get an error.Some methods will have to be refactored.
For instance
apiRef.current.setSelectionModel
is not applying the limitation.But it is a lot more consistent to do it since with the current approach, a user of the
DataGrid
could rightfully callapiRef.current.setSelectionModel
with several rows inside a custom component and it would work.What if we want to limit access to a method to the pro plan
There are a few methods that we are still considering limiting.
The main candidates are all the methods around the editing (
apiRef.current.commitCellChange
,apiRef.current.commitRowChange
,apiRef.current.setEditCellValue
mainly).The following paragraphs explore what it would mean to block some arbitrary methods on the free plan. Even if we decide that the methods above should not be blocked, the global ideas would still apply to any future method we only want to expose on a given plan and that is created by hooks also called on a lower plan.
Therefore, the examples below uses very basic methods to illustrate the issue.
In those examples, we also take for granted that we implemented the proposal splitting the public and private
apiRef
.If the method is used in components overridable by component slots
Imagine that we want to block the method
apiRef.current.setPageSize
in the free plan.We could not take for granted that
useGridApiRef
contains the methodsetPageSize
and should use theprivateApiRef
to access it in our cross-plan components.A simplified version of our
GridPagination
would then look something like:But if users want to use the
Pagination
component slot. They could do it, but they could never truly build a working component since they would not have access touseGridPrivateApiContext
I think we should only block access based on the plan if those methods are never used on a component that can be overrided as a slot.
The text was updated successfully, but these errors were encountered: