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] Add exporter for posts list in demo app #3279

Merged
merged 2 commits into from
Jun 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/simple/src/posts/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import BookIcon from '@material-ui/icons/Book';
import Chip from '@material-ui/core/Chip';
import { withStyles } from '@material-ui/core/styles';
import React, { Children, Fragment, cloneElement } from 'react';
import lodashGet from 'lodash/get';
import { unparse as convertToCSV } from 'papaparse/papaparse.min';
import {
BooleanField,
BulkDeleteButton,
ChipField,
Datagrid,
DateField,
downloadCSV,
EditButton,
Filter,
List,
Expand Down Expand Up @@ -45,6 +48,14 @@ const PostFilter = props => (
</Filter>
);

const exporter = (posts) => {
const data = posts.map(post => ({
...post,
backlinks: lodashGet(post, 'backlinks', []).map(backlink => backlink.url),
}))
return downloadCSV(convertToCSV({ data }), 'posts');
};

const styles = theme => ({
title: {
maxWidth: '20em',
Expand Down Expand Up @@ -96,6 +107,7 @@ const PostList = withStyles(styles)(({ classes, ...props }) => (
bulkActionButtons={<PostListBulkActions />}
filters={<PostFilter />}
sort={{ field: 'published_at', order: 'DESC' }}
exporter={exporter}
>
<Responsive
small={
Expand Down