refine icon indicating copy to clipboard operation
refine copied to clipboard

[BUG] MUI useDataGrid's dataGridProps type not compatible with DataGridPro

Open jamesdh opened this issue 1 year ago • 8 comments

Describe the bug

Upon trying to upgrade from MUI DataGrid to DataGridPro, I'm getting the following TS errors:

TS2322: Type ... is not assignable to type DataGridProProps<any>
Types of property onFilterModelChange are incompatible.
Types of parameters details and details are incompatible.
Types of property reason are incompatible.

Steps To Reproduce

Create an extremely basic component w/ useDataGrid:

import React from 'react';
import {List, useDataGrid} from '@refinedev/mui';
import {DataGridPro} from '@mui/x-data-grid-pro';

const ListPage = () => {
  const { dataGridProps } = useDataGrid<any>({})
  return (
    <List>
       <DataGridPro {...dataGridProps} columns={[]} />
    </List>
  )
}

Expected behavior

The dataGridProps type returned from useDataGrid will also be compatible with DataGridPro.

Packages

  • "@refinedev/core": "4.49.2"
  • "@refinedev/mui": "5.15.1"
  • "@mui/material": "5.15.8"
  • "@mui/x-data-grid-pro": "7.5.1"

Additional Context

No response

jamesdh avatar May 28 '24 17:05 jamesdh

Downgrading @mui/x-data-grid-pro to 6.20.0 helped resolve this. It's a bit odd, as prior to upgrading to the Pro license, the regular @mui/x-data-grid was working fine w/ 7.5.1

jamesdh avatar May 29 '24 16:05 jamesdh

Hey @jamesdh sorry for the issue! I've investigated this a bit. Looks like this is just a type issue and caused by a faulty type from our useDataGrid hooks return type. We have onFilterModelChange as DataGridProps["onFilterModelChange"] in the return type (the function has two arguments model and details) but we're only using the model and doesn't even have details in the implementation 😅

We can update the return type to reflect our implementation (which still satisfies the onFilterModelChange prop of DataGrid components) and get rid of this error easily.

Here's the part defining the return type of the hook:

https://github.com/refinedev/refine/blob/77df5be781497681b1ef2718538d76ad41d76901/packages/mui/src/hooks/useDataGrid/index.ts#L33-L53

Instead of inferring it directly from the DataGridProps, we can define onFilterModelChange as:

onFilterModelChange: (model: GridFilterModel) => void;

If you want to contribute to Refine and help us fix the issue, check out the Contributing Guide to get started!

aliemir avatar May 30 '24 08:05 aliemir

Hello @jamesdh @aliemir , I would like to contribute for working on this issue. Can you please assign it to me?

bhargavpshah98 avatar Jun 09 '24 07:06 bhargavpshah98

@bhargavpshah98 absolutely! Feel free to submit a PR for it!

jamesdh avatar Jun 09 '24 15:06 jamesdh

Hey @bhargavpshah98, assigned the issue! I think my comment above will be enough to get the task done but let us know if you need any help! 🙏

@jamesdh, did you had a chance to check my comment above about the solution, do you need any workaround for now, or does just casting the proper types resolves the issue in your codebase? 🙏

aliemir avatar Jun 10 '24 16:06 aliemir

Hello, @aliemir , Thank you for assigning the task. Yeah, that sounds good. I will reach out if I need any help or guidance.

bhargavpshah98 avatar Jun 10 '24 18:06 bhargavpshah98

Hello @aliemir @jamesdh , I need some help regarding testing of the code and the changes I found in the codebase. Let me know the best way to connect with you.

bhargavpshah98 avatar Jun 13 '24 20:06 bhargavpshah98

@bhargavpshah98 the easiest way is to create a draft PR and ask for feedback on your changes directly.

jamesdh avatar Jun 15 '24 13:06 jamesdh

Hello @aliemir. Is this issue still open and available to pick up?

Sergio16T avatar Jul 11 '24 21:07 Sergio16T

Hey @Sergio16T, issue is still open and available 🚀 I can assign it to you if you're willing to work on it, let me know if any help is needed 🙏

aliemir avatar Jul 16 '24 06:07 aliemir

@aliemir Thank you! That sounds good, Please assign it to me.

Sergio16T avatar Jul 17 '24 18:07 Sergio16T

@aliemir PR is ready for review.

Sergio16T avatar Jul 17 '24 19:07 Sergio16T