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
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/x-data-grid/src/models/api/gridCallbackDetails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GridControlledStateReasonLookup } from '../events/gridEventLookup';
import { GridApiCommunity } from './gridApiCommunity';

/**
* Additional details passed to the callbacks
Expand All @@ -8,4 +9,8 @@ export interface GridCallbackDetails<K extends keyof GridControlledStateReasonLo
* The reason for this callback to have been called.
*/
reason?: GridControlledStateReasonLookup[K];
/**
* 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 });
         }

}