Skip to content

Commit b2a48bf

Browse files
committed
feat: download
1 parent 8139d64 commit b2a48bf

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { defineMessages, useIntl } from 'react-intl';
2+
import { CSVLink } from 'react-csv';
3+
4+
const messages = defineMessages({
5+
export_csv_file: {
6+
id: 'Export CSV file',
7+
defaultMessage: 'Export CSV file',
8+
},
9+
});
10+
11+
const TableActions = ({ schema, columns, items }) => {
12+
const intl = useIntl();
13+
return (
14+
items?.length > 0 && (
15+
<div className="actions">
16+
<CSVLink
17+
className="ui button"
18+
filename={schema.title ? `${schema.title}.csv` : 'export.csv'}
19+
separator=";"
20+
headers={columns}
21+
data={items}
22+
>
23+
{intl.formatMessage(messages.export_csv_file)}
24+
</CSVLink>
25+
</div>
26+
)
27+
);
28+
};
29+
30+
export default TableActions;

src/components/Blocks/DataTableBlock/View.jsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import paginationRightSVG from '@plone/volto/icons/right-key.svg';
88
import sortUp from '@plone/volto/icons/sort-up.svg';
99
import sortDown from '@plone/volto/icons/sort-down.svg';
1010
import { defineMessages, useIntl } from 'react-intl';
11-
import { CSVLink } from 'react-csv';
11+
import TableActions from '@eeacms/volto-react-table-widget/components/Blocks/DataTableBlock/TableActions';
1212

1313
const messages = defineMessages({
1414
page_size: {
@@ -19,10 +19,6 @@ const messages = defineMessages({
1919
id: 'all',
2020
defaultMessage: 'All',
2121
},
22-
export_csv_file: {
23-
id: 'Export CSV file',
24-
defaultMessage: 'Export CSV file',
25-
},
2622
});
2723

2824
const View = ({ data, id, path, properties }) => {
@@ -180,7 +176,7 @@ const View = ({ data, id, path, properties }) => {
180176
>
181177
{column.render('Header')}
182178
{column.defaultCanSort && (
183-
<span class="sort">
179+
<span className="sort">
184180
{column.isSorted ? (
185181
column.isSortedDesc ? (
186182
<Icon name={sortUp} />
@@ -260,17 +256,13 @@ const View = ({ data, id, path, properties }) => {
260256
</select>
261257
</>
262258
)}
263-
<div className="actions">
264-
<CSVLink
265-
className="ui button"
266-
filename={schema.title ? `${schema.title}.csv` : 'export.csv'}
267-
separator=";"
268-
headers={csv_columns}
269-
data={data?.items || []}
270-
>
271-
{intl.formatMessage(messages.export_csv_file)}
272-
</CSVLink>
273-
</div>
259+
<TableActions
260+
path={path}
261+
block_id={id}
262+
schema={schema}
263+
columns={csv_columns}
264+
items={data?.items || []}
265+
/>
274266
</div>
275267
)}
276268
</div>

0 commit comments

Comments
 (0)