Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f5c2942
Adjustments [DEV]
mitchmaps Sep 16, 2019
9fe1626
Introduced new logic for creating the footer markup
mitchmaps Sep 23, 2019
316a20e
Refactored the rendering logic for header vs footer totals
mitchmaps Sep 23, 2019
552da75
Edited placement
mitchmaps Sep 25, 2019
301d747
Addded entry to unreleased
mitchmaps Sep 25, 2019
942c840
Merge branch 'master' into add-totals-to-data-table
mitchmaps Sep 25, 2019
b02cb70
Update UNRELEASED.md
mitchmaps Sep 25, 2019
0a0f43c
Renamed prop
mitchmaps Sep 25, 2019
e980d78
Changed prop name to be more action oriented
mitchmaps Sep 27, 2019
bbf44b7
Merge branch 'add-totals-to-data-table' of https://github.com/Shopify…
mitchmaps Sep 27, 2019
84237d7
Updated unreleased
mitchmaps Sep 27, 2019
362277d
added test for getting codecov >90%
mitchmaps Sep 27, 2019
9da2ce2
Merge branch 'master' into add-totals-to-data-table
mitchmaps Sep 27, 2019
6c03919
Renamed test for the new prop
mitchmaps Sep 27, 2019
be23d0d
Merge branch 'add-totals-to-data-table' of https://github.com/Shopify…
mitchmaps Sep 27, 2019
c8a05f9
renamed prop to the final showTotalsInFooter
mitchmaps Sep 27, 2019
95b901f
Edited the markup to use a <tfoot> for the footer totals
mitchmaps Sep 30, 2019
e774654
Edited rendering logic for footer totals
mitchmaps Sep 30, 2019
71c9e53
Added example for the new totals prop in the readme
mitchmaps Sep 30, 2019
4ad1e2a
Added correct top border for a totals row in the footer
mitchmaps Oct 7, 2019
beee999
Merge branch 'master' into add-totals-to-data-table
mitchmaps Oct 7, 2019
4741623
Merge branch 'master' into add-totals-to-data-table
mitchmaps Oct 7, 2019
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
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Enhancements

- Added showTotalsFooter prop to `DataTable` for control over placement of Totals row ([#2200](https://github.com/Shopify/polaris-react/pull/2200))
- Removed the need for z-indexes in `Icon` ([#2207](https://github.com/Shopify/polaris-react/pull/2207))
- Added `hasFocusableParent` to `Spinner` ([#2176](https://github.com/Shopify/polaris-react/pull/2176))

### Bug fixes
Expand Down
5 changes: 5 additions & 0 deletions src/components/DataTable/DataTable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ $breakpoint: 768px;
border-bottom: border();
}

.Cell-total-footer {
border-top: border();
border-bottom: none;
}

.Footer {
padding: spacing();
background: color('sky', 'light');
Expand Down
21 changes: 19 additions & 2 deletions src/components/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface DataTableProps {
headings: string[];
/** List of numeric column totals, highlighted in the table’s header below column headings. Use empty strings as placeholders for columns with no total. */
totals?: TableData[];
/** Placement of totals row within table, true for t */
showTotalsInFooter?: boolean;
/** Lists of data points which map to table body rows. */
rows: TableData[][];
/** Truncate content in first column instead of wrapping.
Expand Down Expand Up @@ -120,7 +122,13 @@ class DataTable extends React.PureComponent<CombinedProps, DataTableState> {
}

render() {
const {headings, totals, rows, footerContent} = this.props;
const {
headings,
totals,
showTotalsInFooter,
rows,
footerContent,
} = this.props;
const {
condensed,
columnVisibilityData,
Expand Down Expand Up @@ -150,6 +158,11 @@ class DataTable extends React.PureComponent<CombinedProps, DataTableState> {
<div className={styles.Footer}>{footerContent}</div>
) : null;

const headerTotalsMarkup = !showTotalsInFooter ? totalsMarkup : null;
const footerTotalsMarkup = showTotalsInFooter ? (
<tfoot>{totalsMarkup}</tfoot>
) : null;

return (
<div className={wrapperClassName}>
<Navigation
Expand All @@ -170,9 +183,10 @@ class DataTable extends React.PureComponent<CombinedProps, DataTableState> {
<table className={styles.Table} ref={this.table}>
<thead>
{headingMarkup}
{totalsMarkup}
{headerTotalsMarkup}
</thead>
<tbody>{bodyMarkup}</tbody>
{footerTotalsMarkup}
</table>
</div>
{footerMarkup}
Expand Down Expand Up @@ -320,9 +334,12 @@ class DataTable extends React.PureComponent<CombinedProps, DataTableState> {
content = total;
}

const totalInFooter = this.props.showTotalsInFooter;

return (
<Cell
total
totalInFooter={totalInFooter}
firstColumn={index === 0}
key={id}
content={content}
Expand Down
47 changes: 47 additions & 0 deletions src/components/DataTable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,53 @@ function DataTableFooterExample() {
}
```

### Data table with totals in footer

Use to reposition the totals row in a more appropriate location based on the data stored in the
table for merchants to better understand its meaning.

```jsx
function DataTableExample() {
const rows = [
['Emerald Silk Gown', '$875.00', 124689, 140, '$122,500.00'],
['Mauve Cashmere Scarf', '$230.00', 124533, 83, '$19,090.00'],
[
'Navy Merino Wool Blazer with khaki chinos and yellow belt',
'$445.00',
124518,
32,
'$14,240.00',
],
];

return (
<Page title="Sales by product">
<Card>
<DataTable
columnContentTypes={[
'text',
'numeric',
'numeric',
'numeric',
'numeric',
]}
headings={[
'Product',
'Price',
'SKU Number',
'Net quantity',
'Net sales',
]}
rows={rows}
totals={['', '', '', 255, '$155,830.00']}
showTotalsInFooter
/>
</Card>
</Page>
);
}
```

### Data table with row heading links

Use to help merchants find relevant, finer grained data sets.
Expand Down
3 changes: 3 additions & 0 deletions src/components/DataTable/components/Cell/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CellProps {
truncate?: boolean;
header?: boolean;
total?: boolean;
totalInFooter?: boolean;
sorted?: boolean;
sortable?: boolean;
sortDirection?: SortDirection;
Expand All @@ -31,6 +32,7 @@ export function Cell({
truncate,
header,
total,
totalInFooter,
sorted,
sortable,
sortDirection,
Expand All @@ -47,6 +49,7 @@ export function Cell({
firstColumn && truncate && styles['Cell-truncated'],
header && styles['Cell-header'],
total && styles['Cell-total'],
totalInFooter && styles['Cell-total-footer'],
numeric && styles['Cell-numeric'],
sortable && styles['Cell-sortable'],
sorted && styles['Cell-sorted'],
Expand Down
9 changes: 9 additions & 0 deletions src/components/DataTable/tests/DataTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ describe('<DataTable />', () => {

totalsCells.forEach((total) => expect(total.text()).toBe(''));
});

it('renders totals in the footer with a showTotalsInFooter prop', () => {
const totals = ['', '', ''];
const dataTable = mountWithAppProvider(
<DataTable {...defaultProps} totals={totals} showTotalsInFooter />,
);

expect(dataTable.find('tfoot')).toHaveLength(1);
});
});

describe('rows', () => {
Expand Down