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

[DataGrid] Export option can be disable #3270

Merged
merged 10 commits into from
Dec 6, 2021

Conversation

alexfauquette
Copy link
Member

Fix #3064

docs/src/pages/components/data-grid/export/export.md Outdated Show resolved Hide resolved
docs/src/pages/components/data-grid/export/export.md Outdated Show resolved Hide resolved
packages/grid/_modules_/grid/models/gridExport.ts Outdated Show resolved Hide resolved
* If `true`, the Print export option will be removed from the GridToolbarExport menu.
* @default false
*/
disable?: boolean;
Copy link
Member

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.

Copy link
Member Author

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"

@m4theushw m4theushw added component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request labels Nov 27, 2021
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 27, 2021
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 29, 2021
*/
allColumns?: boolean;
/**
* If `true`, this export option will be removed from the GridToolbarExport menu.
Copy link
Member

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 }}

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@m4theushw m4theushw Nov 29, 2021

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.

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Or disableToolbarButton

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 29, 2021
@alexfauquette alexfauquette self-assigned this Dec 3, 2021
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 3, 2021
Copy link
Member

@m4theushw m4theushw left a 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 = {
Copy link
Member

Choose a reason for hiding this comment

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

Prefer interfaces always.

Suggested change
type GridExportDisplayOptions = {
interface GridExportDisplayOptions {

Same for GridExportOption.

Comment on lines 29 to 31
formatOptions?:
| (GridCsvExportOptions & GridExportDisplayOptions)
| (GridPrintExportOptions & GridExportDisplayOptions);
Copy link
Member

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.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Remove print button
### Remove the print button

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 5, 2021
@github-actions
Copy link

github-actions bot commented Dec 5, 2021

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 6, 2021
@alexfauquette alexfauquette merged commit 3622d8f into mui:master Dec 6, 2021
@alexfauquette alexfauquette deleted the remove-exporter branch December 6, 2021 12:45
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! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Allow export options to be removed from GridToolbarExport
3 participants