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

[RFR] Migrate export button #3640

Merged
merged 5 commits into from
Sep 3, 2019
Merged

[RFR] Migrate export button #3640

merged 5 commits into from
Sep 3, 2019

Conversation

fzaninotto
Copy link
Member

As expected in #3623, using the new hooks changes the signature of the exporter function, but for the best.

-const exportComments = (data, fetchRelaterRecords, dispatch) => {
+const exportComments = (data, fetchRelaterRecords, dataProvider) => {
    // ...
}

This is a small BC break, because using the dispatch parameter in the exporter function was really cumbersome, and I doubt anyone has ever used it.

Also, people wishing to customize the export more deeply (with custom side effects, etc) can easily write their own. Here is the simplified version of the ExportButton component:

import {
    downloadCSV,
    useDataProvider,
    useNotify,
    GET_LIST,
} from 'react-admin';
import jsonExport from 'jsonexport/dist';

const ExportButton = ({ sort, filter, maxResults = 1000, resource }) => {
    const dataProvider = useDataProvider();
    const notify = useNotify();
    const payload = { sort, filter, pagination: { page: 1, perPage: maxResults }}
    const handleClick = dataProvider(GET_LIST, resource, payload)
        .then(({ data }) => jsonExport(data, (err, csv) => downloadCSV(csv, resource)))
        .catch(error => notify('ra.notification.http_error', 'warning'));

    return (
        <Button
            label="Export"
            onClick={handleClick}
        />
    );
};

Closes #3623

@fzaninotto fzaninotto added this to the 3.0.0 milestone Sep 2, 2019
Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Much nicer indeed 👍

UPGRADE.md Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/button/ExportButton.tsx Outdated Show resolved Hide resolved
fzaninotto and others added 2 commits September 3, 2019 09:18
Co-Authored-By: Gildas Garcia <gildas.garcia@gmail.com>
@djhi djhi merged commit 9b08ceb into next Sep 3, 2019
@djhi djhi deleted the migrate-ExportButton branch September 3, 2019 07:36
@fzaninotto fzaninotto changed the title [RFR] [BC Break] Migrate export button [RFR] Migrate export button Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants