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

[XGrid] Support column reordering inside the whole grid #1250

Merged
merged 2 commits into from
Apr 7, 2021

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Mar 18, 2021

Fixes #445.
Preview https://deploy-preview-1250--material-ui-x.netlify.app/components/data-grid/demo/

Breaking changes

  • [XGrid] Event GRID_COLUMN_REORDER_DRAG_OVER_HEADER is no longer emitted

My approach here was to turn every cell into a droppable target. If #206 gets implemented an additional check may be needed to determine if a column cell or a row cell was dropped. I'm using the value of dropEffect to determine if the user canceled the reordering (dropping outside or pressing Escape).

Result:

Peek 2021-03-18 00-07

@m4theushw
Copy link
Member Author

I need some help to fix the failing tests on CI. In all browsers they passed, but not on Safari. Locally, using the version I have, they passed too.

Screen Shot 2021-03-17 at 23 49 38

@@ -102,6 +101,21 @@ export const GridCell: React.FC<GridCellProps> = React.memo((props) => {
[publish, publishClick],
);

const onDragEnter = React.useCallback((event) => apiRef!.current.onColItemDragEnter(event), [
Copy link
Member

Choose a reason for hiding this comment

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

this onColItem... should be refactored and will be removed
#1201

Copy link
Member

@DanailH DanailH Mar 18, 2021

Choose a reason for hiding this comment

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

I think we still need to keep the APIs because they are used in the header cells but we will need to add handlers on the grid component itself that call those APIs to satisfy the requirement from #1201. We should change the names tho to match convention, e.g. handleDragEnd for example.

Copy link
Member

@dtassone dtassone Mar 18, 2021

Choose a reason for hiding this comment

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

apiRef should not be a trigger for events.

There should not be any method like handleDragEnd on it. You can subscribe to an handler using subscribeEvent but not just put them there. That's not its purpose.

Only api methods that can be used to retrieve data, or manipulate the grid.
Something like setColumnIndex(field, index) is appropriate in this case.
So users can reset the index outside the drag action.

@@ -52,6 +50,7 @@ export const GridCell: React.FC<GridCellProps> = React.memo((props) => {
const valueToRender = formattedValue || value;
const cellRef = React.useRef<HTMLDivElement>(null);
const apiRef = React.useContext(GridApiContext);
const { align = 'left', field } = column;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need the column now?

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 need it to call onColItemDragOver later in this file. Previously I just had the field and align from the column as props.

Copy link
Member

Choose a reason for hiding this comment

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

in #1201 we will remove this method of apiRef as they don't really make sense.
I think #1201 should come before this changes.
This method start an action instead of letting you subscribe to an event.

You can refactor by passing the field and retrieving the column directly in the handler using apiRef.

@dtassone
Copy link
Member

lot of refactoring are also coming on the grid cell as part of #1205

@oliviertassinari oliviertassinari added components: XGrid new feature New feature or request bug 🐛 Something doesn't work and removed new feature New feature or request labels Mar 27, 2021
@oliviertassinari
Copy link
Member

I need some help to fix the failing tests on CI. In all browsers they passed, but not on Safari. Locally, using the version I have, they passed too.

@m4theushw You can use our BrowserStack credentials to run the test in Safari, only. Here https://www.notion.so/BrowserStack-945f0ccb9f7749ccb9e84b9eb9b13ec7, use the "env" part.

@m4theushw m4theushw added the on hold There is a blocker, we need to wait label Mar 29, 2021
@@ -59,12 +67,6 @@ export const GRID_COL_RESIZE_STOP = 'colResizing:stop';

export const GRID_COLUMN_ORDER_CHANGE = 'columnOrderChange';

export const GRID_COLUMN_REORDER_START = 'columnReordering:dragStart';
Copy link
Member Author

Choose a reason for hiding this comment

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

IMO events should be named according to the DOM events that they listen to and not the context in which they are used. Different hooks could subscribe to the same event.

@m4theushw m4theushw removed the on hold There is a blocker, we need to wait label Apr 1, 2021
@m4theushw m4theushw merged commit c8d83c0 into mui:master Apr 7, 2021
@m4theushw m4theushw deleted the column-reorder branch April 7, 2021 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[XGrid] Column reordering is too limiting
4 participants