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
This commit is contained in:
parent
5a6749b15c
commit
1351997eef
|
@ -125,6 +125,10 @@ export default class extends Component {
|
||||||
|
|
||||||
const rows = this.getRowsContent( products );
|
const rows = this.getRowsContent( products );
|
||||||
const headers = this.getHeadersContent();
|
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 = {
|
const tableQuery = {
|
||||||
...query,
|
...query,
|
||||||
|
@ -139,6 +143,7 @@ export default class extends Component {
|
||||||
rowsPerPage={ rowsPerPage }
|
rowsPerPage={ rowsPerPage }
|
||||||
headers={ headers }
|
headers={ headers }
|
||||||
compareBy={ 'product' }
|
compareBy={ 'product' }
|
||||||
|
labels={ labels }
|
||||||
ids={ products.map( p => p.product_id ) }
|
ids={ products.map( p => p.product_id ) }
|
||||||
onClickDownload={ noop }
|
onClickDownload={ noop }
|
||||||
onQueryChange={ onQueryChange }
|
onQueryChange={ onQueryChange }
|
||||||
|
|
|
@ -15,13 +15,13 @@ const CompareButton = ( { count, children, helpText, onClick } ) =>
|
||||||
count < 2 ? (
|
count < 2 ? (
|
||||||
<Tooltip text={ helpText }>
|
<Tooltip text={ helpText }>
|
||||||
<span>
|
<span>
|
||||||
<Button isDefault disabled={ true }>
|
<Button className="woocommerce-compare-button" isDefault disabled={ true }>
|
||||||
{ children }
|
{ children }
|
||||||
</Button>
|
</Button>
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
) : (
|
) : (
|
||||||
<Button isDefault onClick={ onClick }>
|
<Button className="woocommerce-compare-button" isDefault onClick={ onClick }>
|
||||||
{ children }
|
{ children }
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Search extends Component {
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div className="woocommerce-search">
|
<div className="woocommerce-search">
|
||||||
<Gridicon className="woocommerce-search__icon" icon="search" />
|
<Gridicon className="woocommerce-search__icon" icon="search" size={ 18 } />
|
||||||
<Autocomplete completer={ autocompleter } onSelect={ this.selectResult }>
|
<Autocomplete completer={ autocompleter } onSelect={ this.selectResult }>
|
||||||
{ ( { listBoxId, activeId, onChange } ) => (
|
{ ( { listBoxId, activeId, onChange } ) => (
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
.woocommerce-search__input {
|
.woocommerce-search__input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: $gap-small $gap-small $gap-small 36px;
|
padding: $gap-smaller $gap-small $gap-smaller 36px;
|
||||||
border: 1px solid $core-grey-light-700;
|
border: 1px solid $core-grey-light-700;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,11 @@
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
border: 1px solid $core-grey-light-700;
|
border: 1px solid $core-grey-light-700;
|
||||||
|
position: absolute;
|
||||||
|
top: 36px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 10;
|
||||||
|
|
||||||
&:empty {
|
&:empty {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { getIdsFromQuery } from 'lib/nav-utils';
|
||||||
import MenuItem from 'components/ellipsis-menu/menu-item';
|
import MenuItem from 'components/ellipsis-menu/menu-item';
|
||||||
import MenuTitle from 'components/ellipsis-menu/menu-title';
|
import MenuTitle from 'components/ellipsis-menu/menu-title';
|
||||||
import Pagination from 'components/pagination';
|
import Pagination from 'components/pagination';
|
||||||
|
import Search from 'components/search';
|
||||||
import Table from './table';
|
import Table from './table';
|
||||||
import TableSummary from './summary';
|
import TableSummary from './summary';
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ class TableCard extends Component {
|
||||||
};
|
};
|
||||||
this.toggleCols = this.toggleCols.bind( this );
|
this.toggleCols = this.toggleCols.bind( this );
|
||||||
this.onCompare = this.onCompare.bind( this );
|
this.onCompare = this.onCompare.bind( this );
|
||||||
|
this.onSearch = this.onSearch.bind( this );
|
||||||
this.selectRow = this.selectRow.bind( this );
|
this.selectRow = this.selectRow.bind( this );
|
||||||
this.selectAllRows = this.selectAllRows.bind( this );
|
this.selectAllRows = this.selectAllRows.bind( this );
|
||||||
}
|
}
|
||||||
|
@ -84,6 +86,15 @@ class TableCard extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSearch( value ) {
|
||||||
|
const { compareBy, onQueryChange } = this.props;
|
||||||
|
const { selectedRows } = this.state;
|
||||||
|
if ( compareBy ) {
|
||||||
|
const ids = value.map( v => v.id );
|
||||||
|
onQueryChange( 'compare' )( compareBy, [ ...selectedRows, ...ids ].join( ',' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
filterCols( rows = [] ) {
|
filterCols( rows = [] ) {
|
||||||
const { showCols } = this.state;
|
const { showCols } = this.state;
|
||||||
// Header is a 1d array
|
// Header is a 1d array
|
||||||
|
@ -155,6 +166,7 @@ class TableCard extends Component {
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
compareBy,
|
compareBy,
|
||||||
|
labels,
|
||||||
onClickDownload,
|
onClickDownload,
|
||||||
onQueryChange,
|
onQueryChange,
|
||||||
query,
|
query,
|
||||||
|
@ -189,26 +201,32 @@ class TableCard extends Component {
|
||||||
<CompareButton
|
<CompareButton
|
||||||
key="compare"
|
key="compare"
|
||||||
count={ selectedRows.length }
|
count={ selectedRows.length }
|
||||||
helpText={ __( 'Select at least two items to compare', 'wc-admin' ) }
|
helpText={
|
||||||
|
labels.helpText || __( 'Select at least two items to compare', 'wc-admin' )
|
||||||
|
}
|
||||||
onClick={ this.onCompare }
|
onClick={ this.onCompare }
|
||||||
>
|
>
|
||||||
{ __( 'Compare', 'wc-admin' ) }
|
{ labels.compareButton || __( 'Compare', 'wc-admin' ) }
|
||||||
</CompareButton>
|
</CompareButton>
|
||||||
),
|
),
|
||||||
compareBy && (
|
compareBy && (
|
||||||
<div key="search" style={ { padding: '4px 12px', color: '#6c7781' } }>
|
<Search
|
||||||
Placeholder for search
|
key="search"
|
||||||
</div>
|
placeholder={ labels.placeholder || __( 'Search by item name', 'wc-admin' ) }
|
||||||
|
type={ compareBy + 's' }
|
||||||
|
onChange={ this.onSearch }
|
||||||
|
/>
|
||||||
),
|
),
|
||||||
onClickDownload && (
|
onClickDownload && (
|
||||||
<IconButton
|
<IconButton
|
||||||
key="download"
|
key="download"
|
||||||
|
className="woocommerce-table__download-button"
|
||||||
onClick={ onClickDownload }
|
onClick={ onClickDownload }
|
||||||
icon="arrow-down"
|
icon="arrow-down"
|
||||||
size={ 18 }
|
size={ 18 }
|
||||||
isDefault
|
isDefault
|
||||||
>
|
>
|
||||||
{ __( 'Download', 'wc-admin' ) }
|
{ labels.downloadButton || __( 'Download', 'wc-admin' ) }
|
||||||
</IconButton>
|
</IconButton>
|
||||||
),
|
),
|
||||||
] }
|
] }
|
||||||
|
@ -272,6 +290,15 @@ TableCard.propTypes = {
|
||||||
required: PropTypes.bool,
|
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 ].
|
* A list of IDs, matching to the row list so that ids[ 0 ] contains the object ID for the object displayed in row[ 0 ].
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,11 +13,20 @@
|
||||||
|
|
||||||
&.has-compare {
|
&.has-compare {
|
||||||
.woocommerce-card__action {
|
.woocommerce-card__action {
|
||||||
|
align-items: center;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
display: grid;
|
display: grid;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
grid-template-columns: auto 1fr auto;
|
grid-template-columns: auto 1fr auto;
|
||||||
}
|
}
|
||||||
|
.woocommerce-search {
|
||||||
|
margin: 0 $gap;
|
||||||
|
}
|
||||||
|
.woocommerce-compare-button,
|
||||||
|
.woocommerce-table__download-button {
|
||||||
|
padding: 3px $gap-small;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue