-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Export option can be disable #3270
Conversation
* If `true`, the Print export option will be removed from the GridToolbarExport menu. | ||
* @default false | ||
*/ | ||
disable?: boolean; |
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.
Maybe it's too premature, but this attribute could be extract into an interface so every export option must inherit it and support disable
.
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.
Done in this commit: 9cbc962
I took the common options:
- fields
- allColumns
- disable
The only problem is for documentation comment, in which I have to replace "Print export" and "CSV export" by "this export"
ad82479
to
57dbcc8
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
ade28f8
to
459966e
Compare
*/ | ||
allColumns?: boolean; | ||
/** | ||
* If `true`, this export option will be removed from the GridToolbarExport menu. |
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.
What should be the behavior if the user calls exportDataAsCsv
with disable: true
? (same for print)
Should be raise an error ? Ignore it as you currently do ? Skip the export ?
The most coherent behavior would probably be to split the interfaces between the imperative method and the React component, to only have disable
on the React component.
This would be an argument in favor of csvOptions={false}
instead of csvOptions={{ disable: false }}
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.
Yes, if GridCsvExportOptions
is used by imperative methods, it does not make sens to put user interface customisation in it.
disable
could be defined in type GridExportOption
. But it does not make sens to add an option disable
that will disable all the other options.
Does someone else has an argument in favour of the disable
logic?
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.
I'm not very in favor of csvOptions={false}
, since the prop was meant to be an object initially. We have been using slots to allow simple customizations without forcing to override an entire component. For instance, the options of the column menu can be easily changed doing that: https://mui.com/components/data-grid/components/#column-menu. The same approach could be done here maybe. It would even allow users to add their export options.
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.
So you propose to export a <GridCsvExportItem />
and <GridPrintExportItem />
such that developers will define the Toolbar as follow:
<GridToolbarContainer>
<GridToolbarColumnsButton />
<GridToolbarFilterButton />
<GridToolbarDensitySelector />
<GridToolbarExportContainer>
<GridCsvExportItem options={...} />
<GridPrintExportItem options={...} />
<MyCustomExportItem options={...} />
</GridToolbarExportContainer>
</GridToolbarContainer>
Why not have both? Having a GridToolbarExportContainer
container is good if dev wants to do advanced customization, but if she only wants to remove a button, setting its props to false
seems natural.
I feel it like a pain when in react-admin I have to redefine a component to remove an option.
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.
My idea is not exactly as you proposed. We add a new toolbarExportButton
slot which has by default:
<GridToolbarExportContainer>
<GridCsvExportItem options={...} />
<GridPrintExportItem options={...} />
<MyCustomExportItem options={...} />
</GridToolbarExportContainer>
If the user wants to disable one of the items, he removes the respective option. My argument against passing false
is that the options prop is meant to be object. We're changing its meaning depending on its value. If the slot approach is too overkill, we could also add an allowedFormats
prop to the GridToolbarExportContainer
.
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.
In fact, the problem is the naming disable
, because we do not want to disable, the export. We want to remove its button. So we could simply rename the field display
and add it only in the <GridToolbarExport/>
props type
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.
Or disableToolbarButton
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
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.
I left some minor suggestions. Otherwise, looks good.
} | ||
|
||
type GridExportFormatOption = GridExportFormat; | ||
type GridExportDisplayOptions = { |
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.
Prefer interfaces always.
type GridExportDisplayOptions = { | |
interface GridExportDisplayOptions { |
Same for GridExportOption
.
formatOptions?: | ||
| (GridCsvExportOptions & GridExportDisplayOptions) | ||
| (GridPrintExportOptions & GridExportDisplayOptions); |
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.
It fits in one line.
formatOptions?: | |
| (GridCsvExportOptions & GridExportDisplayOptions) | |
| (GridPrintExportOptions & GridExportDisplayOptions); | |
formatOptions?: (GridCsvExportOptions | GridPrintExportOptions) & GridExportDisplayOptions; |
@@ -52,6 +52,14 @@ You can provide a [`valueFormatter`](/components/data-grid/columns/#value-format | |||
/> | |||
``` | |||
|
|||
### Remove export button |
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.
### Remove export button | |
### Remove the export button |
@@ -106,6 +114,14 @@ You can provide a [`valueFormatter`](/components/data-grid/columns/#value-format | |||
/> | |||
``` | |||
|
|||
### Remove print button |
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.
### Remove print button | |
### Remove the print button |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Fix #3064