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

[DataGrid] Add missing api property to GridCallbackDetails #12742

Merged
merged 5 commits into from Apr 11, 2024

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Apr 11, 2024

closes: #12464

@sai6855 sai6855 added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! typescript labels Apr 11, 2024
@mui-bot
Copy link

mui-bot commented Apr 11, 2024

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

Generated by 🚫 dangerJS against 58295bf

@sai6855 sai6855 marked this pull request as draft April 11, 2024 07:12
@sai6855 sai6855 requested a review from romgrk April 11, 2024 09:15
@sai6855 sai6855 marked this pull request as ready for review April 11, 2024 09:20
Comment on lines 12 to 15
/**
* GridApi that let you manipulate the grid.
*/
api?: GridApiCommunity;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we should add the typing or remove the field. Also I don't love too much having optional fields, it doesn't seem very clear for an external user if they should expect an API object or not. I've tagged the rest of the team for review, let's see what they think.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should make the api required.
We used to pass it conditionally because apiRef was a Pro feature back then.
It's no longer the case – the apiRef is available in every plan.

diff --git a/packages/x-data-grid/src/hooks/core/useGridStateInitialization.ts b/packages/x-data-grid/src/hooks/core/useGridStateInitialization.ts
index 860d4d505..0ab86b644 100644
--- a/packages/x-data-grid/src/hooks/core/useGridStateInitialization.ts
+++ b/packages/x-data-grid/src/hooks/core/useGridStateInitialization.ts
@@ -92,11 +92,7 @@ export const useGridStateInitialization = <PrivateApi extends GridPrivateApiComm
         const model = controlState.stateSelector(newState, apiRef.current.instanceId);
 
         if (controlState.propOnChange && hasPropChanged) {
-          const details =
-            props.signature === GridSignature.DataGridPro
-              ? { api: apiRef.current, reason }
-              : { reason };
-          controlState.propOnChange(model, details);
+          controlState.propOnChange(model, { api: apiRef.current, reason });
         }

Comment on lines +12 to +15
/**
* GridApi that let you manipulate the grid.
*/
api: GridApiCommunity;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sidenote but I don't like that we don't have a strict convention of either always apiRef or always api. Sometimes we need to do awkward conversions like { current: api } to create a new "ref".

@cherniavskii cherniavskii changed the title [DataGrid] Add GridApiCommunity to GridCallbackDetails [DataGrid] Add missing api property to GridCallbackDetails Apr 11, 2024
@cherniavskii cherniavskii merged commit 9f6f609 into mui:master Apr 11, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid 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.

[data grid] onRowSelectionModelChange details return has incorrect type definitions
4 participants