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

[docs] Add description for all events #1572

Merged
merged 6 commits into from
May 17, 2021

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented May 6, 2021

Breaking changes

  • [XGrid] Event scrolling:rows renamed to rowsScroll for consistency.
  • [XGrid] Event scroll:rowEnd renamed to rowsScrollEnd for consistency.

Closes #1527


/**
* @ignore - do not document.
*/
export const GRID_ELEMENT_FOCUS_OUT = 'gridFocusOut';
Copy link
Member Author

Choose a reason for hiding this comment

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

I ignored it because I think this event could be removed. It's only used to detect if the multiple key is pressed and we agreed that the event argument should be used a single source of truth. Also, its name is confusing and hard to explain the conditions in which the event is fired.


/**
* @ignore - do not document.
*/
export const GRID_NATIVE_SCROLL = 'scroll';
Copy link
Member Author

Choose a reason for hiding this comment

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

It's never published.

Copy link
Member

Choose a reason for hiding this comment

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

Dead code to remove then?

Copy link
Member Author

Choose a reason for hiding this comment

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

/**
* Fired when a `mousedown` event happens in a cell. Called with a [[GridCellParams]] object.
* @event
*/
export const GRID_CELL_MOUSE_DOWN = 'cellMouseDown';
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we have this level of granularity when exposing events? I think we should document only the most obvious events (click, double-click, keydown) and wait users to request more.

Copy link
Member

Choose a reason for hiding this comment

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

IMO it is part of the api so ppl should be free to use it. I don't see the issue.

Documenting only the most obvious is not a proper api documentation as there will be missing things so the doc will be incomplete as soon as it's updated. Ppl will have to look at the typings to get the most accurate doc.

Copy link
Member

@oliviertassinari oliviertassinari May 6, 2021

Choose a reason for hiding this comment

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

The issue is about the long tail of use cases. What about touch start, touch move, touch end, or even the pointers events https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events#event_types_and_global_event_handlers? It doesn't really scale.

Copy link
Member Author

@m4theushw m4theushw May 6, 2021

Choose a reason for hiding this comment

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

I think we should think about what users would potentially create with these events. We are exposing all the column header drag events, but I don't think users would write another drag-and-drop feature from scratch. Having all the events we use internally makes the documentation long and may force users to question themselves: which event should I subscribe? mousedown or click?

Copy link
Member

@oliviertassinari oliviertassinari May 6, 2021

Choose a reason for hiding this comment

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

or force us to hold on refactoring until the next breaking changes release window (developers hate BCs, and enjoy handling them in a batch).

Copy link
Member Author

Choose a reason for hiding this comment

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

I marked more events with @ignore. My rationale is:

  • Ignore drag-and-drop events because they have a very specific use.
  • Ignore the less obvious events published by column headers (keep only click, double and keydown).
  • Ignore global events (GRID_FOCUS_OUT) because users can already subscribe to them using the ref prop. Also, if we're going to document them we should document EVERYTHING.

Copy link
Member

Choose a reason for hiding this comment

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

This is from ag grid https://www.ag-grid.com/react-grid/grid-events/

rowDataChanged The client has set new data into the grid using api.setRowData() or by changing the rowData bound property.
rowDataUpdated The client has updated data for the grid using api.applyTransaction(transaction) or by changing the rowData bound property with immutableData=true.
rowDragEnter A drag has started, or dragging was already started and the mouse has re-entered the grid having previously left the grid.
rowDragMove The mouse has moved while dragging.
rowDragLeave The mouse has left the grid while dragging.
rowDragEnd The drag has finished over the grid.

RowEvent
├── RowSelectedEvent {}
├── RowClickedEvent {}
├── RowDoubleClickedEvent {}
├── RowEditingStartedEvent {}
├── RowEditingStoppedEvent {}
├── RowGroupOpenedEvent {
├── RowValueChangedEvent {}
├── VirtualRowRemovedEvent {}
└── CellEvent
├── CellClickedEvent {}
├── CellMouseDownEvent {}
├── CellDoubleClickedEvent {}
├── CellMouseOverEvent {}
├── CellMouseOutEvent {}
├── CellContextMenuEvent {}
├── CellEditingStartedEvent {}
├── CellKeyDown {}
├── CellKeyPress {}
├── CellEditingStoppedEvent
└── CellValueChangedEvent

/**
* Fired when the rows are updated.
* @event
*/
export const GRID_ROWS_SET = 'rowsSet';
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't understand the difference between this one and GRID_ROWS_UPDATED.

Copy link
Member

Choose a reason for hiding this comment

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

GRID_ROWS_SET is published when the full set of rows is reset.
GRID_ROWS_UPDATED is published when you update one or more rows.

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 that the underlying question is: why does the difference matter (from a developer problem perspective)? For instance, the data grid handles the two events the same way. What if we merged them?

Copy link
Member

Choose a reason for hiding this comment

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

No it should not be the same. One reset the prop and do a full rerender and the other one is more optimised

Copy link
Member Author

Choose a reason for hiding this comment

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

@dtassone Can you describe the difference in a short text to add in the description?

Copy link
Member

@oliviertassinari oliviertassinari May 6, 2021

Choose a reason for hiding this comment

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

it's also when rows length change

Oh so if a developer uses the imperative API to add or remove records, then GRID_ROWS_SET is fired. I thought it was only for the rows prop. (One example of confusion in the description 😁). Would this be clearer? (docs is a lot about avoiding confusion)

  • GRID_ROWS_SET: Fired when the length of the rows changes or when a new set of rows is provided.
  • GRID_ROWS_UPDATED: Fired when at least one row is updated in place.

What happen for row deletions, is only GRID_ROWS_SET fired?

Copy link
Member Author

@m4theushw m4theushw May 6, 2021

Choose a reason for hiding this comment

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

I would not document both GRID_ROWS_UPDATED and GRID_ROWS_SET. It's not clear the conditions in which they are fired.

How will a developer understand what "reset" mean? Should we mention that it triggers when the rows prop change?

It's not triggered when the rows prop change, but when calling apiRef.current.updateRows. This should be clear in the description.

Reset word is pretty common, in the computer world...

IHMO this "reset" word may confuse users. One of the definitions is "to set again". But in the React world "set again" might not cause a rerender if the value is the same. If we are using "reset" in the context of when the value of something changes, this should be more explicit, maybe using "change".

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to call it GRID_ROWS_CHANGE I have no strong opinion anymore.

Reset as it does a clear and set to update the sort, filters...

GRID_ROWS_SET: Fired when the length of the rows changes or when a new set of rows is provided.
GRID_ROWS_UPDATED: Fired when at least one row is updated in place.

👍

I don't see why we are restricting, if some advanced trading app needs to use those events, let them do, that's why the grid is based on an event emitter, so it could be hacked, customized...
We can reassess at a later stage, this code will be refactored along with time, things will evolve over the versions.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can reassess at a later stage, this code will be refactored along with time, things will evolve over the versions.

That's a reason I would not document these two events. Once we have clearly conditions of when they should be published we can add to the docs. Users are free to use them anytime, it's just not exposed in the page.

AG-Grid has an event rowDataChanged that is published both when the prop changes and when programmatically changing the data.

Copy link
Member

Choose a reason for hiding this comment

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

* Fired after the filter model is changed and the new model is applied.
* Called with a [[GridFilterModelParams]] object.
* @event
*/
export const GRID_FILTER_MODEL_CHANGE = 'filterModelChange';
Copy link
Member Author

Choose a reason for hiding this comment

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

Side note: the description of the onFilterModelChange prop is wrong. This event is published after applying the filter model, not before.

Copy link
Member

@oliviertassinari oliviertassinari May 6, 2021

Choose a reason for hiding this comment

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

It looks like the implementation is wrong then. As far as I know, the application of the new model is a different concern it should always come after.

Regarding "Fired after the filter model is changed", IMHO "after" doesn't matter, it's about the user event action.

Copy link
Member Author

Choose a reason for hiding this comment

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

Description updated.

/**
* Fired when a `mousedown` event happens in a cell. Called with a [[GridCellParams]] object.
* @event
*/
export const GRID_CELL_MOUSE_DOWN = 'cellMouseDown';
Copy link
Member

@oliviertassinari oliviertassinari May 6, 2021

Choose a reason for hiding this comment

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

The issue is about the long tail of use cases. What about touch start, touch move, touch end, or even the pointers events https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events#event_types_and_global_event_handlers? It doesn't really scale.

/**
* Fired when the rows are updated.
* @event
*/
export const GRID_ROWS_SET = 'rowsSet';
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 that the underlying question is: why does the difference matter (from a developer problem perspective)? For instance, the data grid handles the two events the same way. What if we merged them?

* Fired after the filter model is changed and the new model is applied.
* Called with a [[GridFilterModelParams]] object.
* @event
*/
export const GRID_FILTER_MODEL_CHANGE = 'filterModelChange';
Copy link
Member

@oliviertassinari oliviertassinari May 6, 2021

Choose a reason for hiding this comment

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

It looks like the implementation is wrong then. As far as I know, the application of the new model is a different concern it should always come after.

Regarding "Fired after the filter model is changed", IMHO "after" doesn't matter, it's about the user event action.

packages/grid/_modules_/grid/constants/eventsConstants.ts Outdated Show resolved Hide resolved
packages/grid/_modules_/grid/constants/eventsConstants.ts Outdated Show resolved Hide resolved
@oliviertassinari oliviertassinari added component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation labels May 6, 2021
@m4theushw m4theushw merged commit b733055 into mui:master May 17, 2021
@m4theushw m4theushw deleted the event-descriptions branch May 17, 2021 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs] Add description for all the data grid events
3 participants