Skip to content

Commit

Permalink
Merge pull request #3279 from fargito/fix-backlink-csv
Browse files Browse the repository at this point in the history
[RFR] Add exporter for posts list in demo app
  • Loading branch information
djhi authored Jun 5, 2019
2 parents ae1a5c2 + 4429fa8 commit a13b7d9
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit a13b7d9

Please sign in to comment.