Skip to content

Commit

Permalink
fix(table): pass filteredData to onDownloadCsv
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Stone committed Jul 29, 2020
1 parent 7a82b38 commit 1b540b0
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/BarChartCard/BarChartCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const BarChartCard = ({
}}
actions={{
toolbar: {
onDownloadCSV: () => csvDownloadHandler(tableData, title),
onDownloadCSV: filteredData => csvDownloadHandler(filteredData, title),
},
}}
view={{
Expand Down
1 change: 1 addition & 0 deletions src/components/Table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ const Table = props => {
'rowEditBarButtons'
),
}}
data={data}
/>
) : null}
<div className="addons-iot-table-container">
Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/Table.story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ storiesOf('Watson IoT/Table', module)
...actions,
toolbar: {
...actions.toolbar,
onDownloadCSV: () => csvDownloadHandler(initialState.data, 'my table data'),
onDownloadCSV: filteredData => csvDownloadHandler(filteredData, 'my table data'),
},
}}
isSortable
Expand Down
9 changes: 8 additions & 1 deletion src/components/Table/TableToolbar/TableToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TableSearchPropTypes,
defaultI18NPropTypes,
ActiveTableToolbarPropType,
TableRowPropTypes,
} from '../TablePropTypes';
import { tableTranslateWithId } from '../../../utils/componentUtilityFunctions';
import { settings } from '../../../constants/Settings';
Expand Down Expand Up @@ -98,6 +99,8 @@ const propTypes = {
/** buttons to be shown with when activeBar is 'rowEdit' */
rowEditBarButtons: PropTypes.node,
}).isRequired,
/** Row value data for the body of the table */
data: TableRowPropTypes.isRequired,
};

const defaultProps = {
Expand Down Expand Up @@ -143,6 +146,7 @@ const TableToolbar = ({
totalItemsCount,
rowEditBarButtons,
},
data,
}) => (
<CarbonTableToolbar className={classnames(`${iotPrefix}--table-toolbar`, className)}>
<TableBatchActions
Expand Down Expand Up @@ -208,7 +212,10 @@ const TableToolbar = ({
) : null}
{onDownloadCSV ? (
<TableToolbarSVGButton
onClick={onDownloadCSV}
onClick={() => {
// hand back the filtered data
onDownloadCSV(data);
}}
description={i18n.downloadIconDescription}
testId="download-button"
renderIcon={Download20}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TableCard/TableCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ const TableCard = ({
toolbar: {
onClearAllFilters: () => {},
onToggleFilter: () => {},
onDownloadCSV: () => csvDownloadHandler(tableDataWithTimestamp, title),
onDownloadCSV: filteredData => csvDownloadHandler(filteredData, title),
},
}}
view={{
Expand Down
2 changes: 1 addition & 1 deletion src/components/TimeSeriesCard/TimeSeriesCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ const TimeSeriesCard = ({
}}
actions={{
toolbar: {
onDownloadCSV: () => csvDownloadHandler(tableData, title),
onDownloadCSV: filteredData => csvDownloadHandler(filteredData, title),
},
}}
view={{
Expand Down
128 changes: 128 additions & 0 deletions src/utils/__tests__/__snapshots__/publicAPI.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2430,6 +2430,134 @@ Map {
"isRequired": true,
"type": "shape",
},
"data": Object {
"args": Array [
Object {
"args": Array [
Object {
"children": Object {
"args": Array [
Array [
Object {
"type": "array",
},
],
],
"type": "oneOfType",
},
"id": Object {
"isRequired": true,
"type": "string",
},
"isSelectable": Object {
"type": "bool",
},
"rowActions": Object {
"args": Array [
Object {
"args": Array [
Object {
"disabled": Object {
"type": "bool",
},
"hasDivider": Object {
"type": "bool",
},
"id": Object {
"isRequired": true,
"type": "string",
},
"isDelete": Object {
"type": "bool",
},
"isEdit": Object {
"type": "bool",
},
"isOverflow": Object {
"type": "bool",
},
"labelText": Object {
"type": "string",
},
"renderIcon": Object {
"args": Array [
Array [
Object {
"args": Array [
Object {
"height": Object {
"type": "string",
},
"svgData": Object {
"isRequired": true,
"type": "object",
},
"viewBox": Object {
"isRequired": true,
"type": "string",
},
"width": Object {
"type": "string",
},
},
],
"type": "shape",
},
Object {
"args": Array [
Array [
"caretUp",
"caretDown",
"edit",
"close",
"checkmark",
"warning",
"arrowUp",
"arrowDown",
"user",
"info",
"help",
],
],
"type": "oneOf",
},
Object {
"type": "node",
},
Object {
"type": "object",
},
Object {
"type": "func",
},
],
],
"type": "oneOfType",
},
},
],
"type": "shape",
},
],
"type": "arrayOf",
},
"values": Object {
"args": Array [
Object {
"type": "any",
},
],
"isRequired": true,
"type": "objectOf",
},
},
],
"type": "shape",
},
],
"isRequired": true,
"type": "arrayOf",
},
"i18n": Object {
"args": Array [
Object {
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@
levenary "^1.1.1"
semver "^5.5.0"

"@babel/preset-env@^7.4.5", "@babel/preset-env@^7.8.7":
"@babel/preset-env@^7.4.5":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.10.4.tgz#fbf57f9a803afd97f4f32e4f798bb62e4b2bef5f"
integrity sha512-tcmuQ6vupfMZPrLrc38d0sF2OjLT3/bZ0dry5HchNCQbrokoQi4reXqclvkkAT5b+gWc23meVWpve5P/7+w/zw==
Expand Down Expand Up @@ -13275,11 +13275,6 @@ lodash@^4.0.0, lodash@^4.0.1, lodash@^4.13.1, lodash@^4.15.0, lodash@^4.17.10, l
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==

lodash@^4.17.19:
version "4.17.19"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==

log-driver@^1.2.7:
version "1.2.7"
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.7.tgz#63b95021f0702fedfa2c9bb0a24e7797d71871d8"
Expand Down

0 comments on commit 1b540b0

Please sign in to comment.