-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGridPro] Type the event publisher and listener #3022
Conversation
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
||
events.push({ | ||
name: event.escapedName!, | ||
description: renderMarkdownInline(description), | ||
params: escapeHTML(linkify(eventProperties.params, documentedInterfaces, 'html')), | ||
event: escapeHTML(`MuiEvent<${eventProperties.event ?? '{}'}>`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, I did the escape on the docs instead of doing it during the build
docs/src/pages/components/data-grid/events/CatalogOfEventsNoSnap.js
Outdated
Show resolved
Hide resolved
…ap.js Co-authored-by: Matheus Wichman <matheushw@outlook.com>
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
const onEvent: GridEventListener<GridEvents.${event.name}> = | ||
( | ||
${args.join('\n ')} | ||
) => {...} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation is not the same as https://deploy-preview-3022--material-ui-x.netlify.app/components/data-grid/events/#subscribing-to-events
<TableCell style={{ borderBottom: 'unset' }}> | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: escapeHTML(event.description), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
docs/src/pages/components/data-grid/events/CatalogOfEventsNoSnap.js
Outdated
Show resolved
Hide resolved
…ap.js Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Preview: https://deploy-preview-3022--material-ui-x.netlify.app/components/data-grid/events/#catalog-of-events
The goal is to have a strict typing on our event publisher / listener arguments. This have several benefits:
subscribeEvent
Changes
props.onRowClick
)useGridApiEventHandler
apiRef.current.publishEvent
apiRef.current.subscribeEvent
GridEvents.someEvent
and"someEvent"
everywhereWe still have the signature of the prop callbacks hardcoded in the comment because otherwise the documentation is not generated correctly from the prop-types.
We could autogen the comments of the TS file at some point but I don't want to over-engineer.
I improved the event table in the doc with a small example of subscription than shows the types and the params available.
This part can be moved to a follow up PR if you want.
Typing of the
event
paramsMuiBaseEvent
if the event potentially come from aapiRef
method (ex:rowEditCommit
is triggered viacommitRowChange
)Bug fixes
I found a few bugs / behavior inconsistencies after typing the events
cellNavigationKeyDown
event can receive aGridRowParams
asparams
argument when fired byhandleRowEditStop
inuseGridEditRows
. In this scenario it does not have afield
and should pick the 1st column. It was working but was not safe since it calledgetColumnIndex
withfield=undefined
.Public API changes :
onCellValueChange
removed because never calledcellDragStart
andcellDragEnd
events removed because never publishedI don't think any of this count as breaking change, it's only type modification and bug fixes.
Changelog
🎁 Add strict typing to the event publisher and listener [DataGridPro] Type the event publisher and listener #3022 (@flaviendelangle)
apiRef.current.subscribeEvent
/apiRef.current.publishEvent
anduseGridApiEventHandler
are now fully typed and gives you the correct arguments based on the event you are listening to or emitting.