From 1351997eef0224738dbb87c1375f4cdeedebaaab Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Wed, 10 Oct 2018 10:12:00 -0400 Subject: [PATCH] TableCard: Add search to table header (https://github.com/woocommerce/woocommerce-admin/pull/495) * Add label override options to TableCard * Add search input to the tableHeader * Style search in table header --- .../client/analytics/report/products/index.js | 5 +++ .../components/filters/compare/button.js | 4 +- .../client/components/search/index.js | 2 +- .../client/components/search/style.scss | 7 +++- .../client/components/table/index.js | 39 ++++++++++++++++--- .../client/components/table/style.scss | 9 +++++ 6 files changed, 56 insertions(+), 10 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/report/products/index.js b/plugins/woocommerce-admin/client/analytics/report/products/index.js index f303589e1d6..913cd7a7202 100644 --- a/plugins/woocommerce-admin/client/analytics/report/products/index.js +++ b/plugins/woocommerce-admin/client/analytics/report/products/index.js @@ -125,6 +125,10 @@ export default class extends Component { const rows = this.getRowsContent( products ); const headers = this.getHeadersContent(); + const labels = { + helpText: __( 'Select at least two products to compare', 'wc-admin' ), + placeholder: __( 'Search by product name or SKU', 'wc-admin' ), + }; const tableQuery = { ...query, @@ -139,6 +143,7 @@ export default class extends Component { rowsPerPage={ rowsPerPage } headers={ headers } compareBy={ 'product' } + labels={ labels } ids={ products.map( p => p.product_id ) } onClickDownload={ noop } onQueryChange={ onQueryChange } diff --git a/plugins/woocommerce-admin/client/components/filters/compare/button.js b/plugins/woocommerce-admin/client/components/filters/compare/button.js index a77b427b019..9b447c09f73 100644 --- a/plugins/woocommerce-admin/client/components/filters/compare/button.js +++ b/plugins/woocommerce-admin/client/components/filters/compare/button.js @@ -15,13 +15,13 @@ const CompareButton = ( { count, children, helpText, onClick } ) => count < 2 ? ( - ) : ( - ); diff --git a/plugins/woocommerce-admin/client/components/search/index.js b/plugins/woocommerce-admin/client/components/search/index.js index 3e5ddfb4442..8eb06492b38 100644 --- a/plugins/woocommerce-admin/client/components/search/index.js +++ b/plugins/woocommerce-admin/client/components/search/index.js @@ -81,7 +81,7 @@ class Search extends Component { }; return (
- + { ( { listBoxId, activeId, onChange } ) => ( v.id ); + onQueryChange( 'compare' )( compareBy, [ ...selectedRows, ...ids ].join( ',' ) ); + } + } + filterCols( rows = [] ) { const { showCols } = this.state; // Header is a 1d array @@ -155,6 +166,7 @@ class TableCard extends Component { render() { const { compareBy, + labels, onClickDownload, onQueryChange, query, @@ -189,26 +201,32 @@ class TableCard extends Component { - { __( 'Compare', 'wc-admin' ) } + { labels.compareButton || __( 'Compare', 'wc-admin' ) } ), compareBy && ( -
- Placeholder for search -
+ ), onClickDownload && ( - { __( 'Download', 'wc-admin' ) } + { labels.downloadButton || __( 'Download', 'wc-admin' ) } ), ] } @@ -272,6 +290,15 @@ TableCard.propTypes = { required: PropTypes.bool, } ) ), + /** + * Custom labels for table header actions. + */ + labels: PropTypes.shape( { + compareButton: PropTypes.string, + downloadButton: PropTypes.string, + helpText: PropTypes.string, + placeholder: PropTypes.string, + } ), /** * A list of IDs, matching to the row list so that ids[ 0 ] contains the object ID for the object displayed in row[ 0 ]. */ diff --git a/plugins/woocommerce-admin/client/components/table/style.scss b/plugins/woocommerce-admin/client/components/table/style.scss index b94fe52139b..67416a99d06 100644 --- a/plugins/woocommerce-admin/client/components/table/style.scss +++ b/plugins/woocommerce-admin/client/components/table/style.scss @@ -13,11 +13,20 @@ &.has-compare { .woocommerce-card__action { + align-items: center; text-align: left; display: grid; width: 100%; grid-template-columns: auto 1fr auto; } + .woocommerce-search { + margin: 0 $gap; + } + .woocommerce-compare-button, + .woocommerce-table__download-button { + padding: 3px $gap-small; + height: auto; + } } }