From 539a388bace5cf861fce99252e0a252b342e2c97 Mon Sep 17 00:00:00 2001 From: fargito Date: Mon, 27 May 2019 14:31:23 +0200 Subject: [PATCH 1/2] add exporter for posts list in demo app --- examples/simple/src/posts/PostList.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/simple/src/posts/PostList.js b/examples/simple/src/posts/PostList.js index dcfd0ac2ab5..6e39855de8d 100644 --- a/examples/simple/src/posts/PostList.js +++ b/examples/simple/src/posts/PostList.js @@ -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 get from 'lodash/get'; +import { unparse as convertToCSV } from 'papaparse/papaparse.min'; import { BooleanField, BulkDeleteButton, ChipField, Datagrid, DateField, + downloadCSV, EditButton, Filter, List, @@ -45,6 +48,14 @@ const PostFilter = props => ( ); +const exporter = (posts) => { + const data = posts.map(post => ({ + ...post, + backlinks: get(post, 'backlinks', []).map(backlink => backlink.url), + })) + return downloadCSV(convertToCSV({ data }), 'posts'); +}; + const styles = theme => ({ title: { maxWidth: '20em', @@ -96,6 +107,7 @@ const PostList = withStyles(styles)(({ classes, ...props }) => ( bulkActionButtons={} filters={} sort={{ field: 'published_at', order: 'DESC' }} + exporter={exporter} > Date: Mon, 27 May 2019 16:24:24 +0200 Subject: [PATCH 2/2] rename get as lodashGet --- examples/simple/src/posts/PostList.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/simple/src/posts/PostList.js b/examples/simple/src/posts/PostList.js index 6e39855de8d..9619fb74a56 100644 --- a/examples/simple/src/posts/PostList.js +++ b/examples/simple/src/posts/PostList.js @@ -2,7 +2,7 @@ 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 get from 'lodash/get'; +import lodashGet from 'lodash/get'; import { unparse as convertToCSV } from 'papaparse/papaparse.min'; import { BooleanField, @@ -51,7 +51,7 @@ const PostFilter = props => ( const exporter = (posts) => { const data = posts.map(post => ({ ...post, - backlinks: get(post, 'backlinks', []).map(backlink => backlink.url), + backlinks: lodashGet(post, 'backlinks', []).map(backlink => backlink.url), })) return downloadCSV(convertToCSV({ data }), 'posts'); };