Apply onQueryChange to more than just 'filter'
This commit is contained in:
parent
83fdaf6cd6
commit
c809fa6cb9
|
@ -60,7 +60,7 @@ const filterConfig = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: __( 'Product Comparison', 'wc-admin' ),
|
label: __( 'Product Comparison', 'wc-admin' ),
|
||||||
value: 'compare-product',
|
value: 'compare-products',
|
||||||
settings: {
|
settings: {
|
||||||
type: 'products',
|
type: 'products',
|
||||||
param: 'products',
|
param: 'products',
|
||||||
|
@ -78,7 +78,7 @@ const filterConfig = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: __( 'Product Category Comparison', 'wc-admin' ),
|
label: __( 'Product Category Comparison', 'wc-admin' ),
|
||||||
value: 'compare-product_cat',
|
value: 'compare-product_cats',
|
||||||
settings: {
|
settings: {
|
||||||
type: 'product_cats',
|
type: 'product_cats',
|
||||||
param: 'categories',
|
param: 'categories',
|
||||||
|
|
|
@ -183,7 +183,7 @@ class ProductsReportTable extends Component {
|
||||||
labels={ labels }
|
labels={ labels }
|
||||||
ids={ orderedProducts.map( p => p.product_id ) }
|
ids={ orderedProducts.map( p => p.product_id ) }
|
||||||
isLoading={ isRequesting }
|
isLoading={ isRequesting }
|
||||||
compareBy={ 'product' }
|
compareBy={ 'products' }
|
||||||
onQueryChange={ onQueryChange }
|
onQueryChange={ onQueryChange }
|
||||||
query={ tableQuery }
|
query={ tableQuery }
|
||||||
summary={ null } // @TODO
|
summary={ null } // @TODO
|
||||||
|
|
|
@ -109,19 +109,23 @@ class TableCard extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onCompare() {
|
onCompare() {
|
||||||
const { compareBy, onQueryChange } = this.props;
|
const { compareBy, compareParam, onQueryChange } = this.props;
|
||||||
const { selectedRows } = this.state;
|
const { selectedRows } = this.state;
|
||||||
if ( compareBy ) {
|
if ( compareBy ) {
|
||||||
onQueryChange( 'compare' )( compareBy, selectedRows.join( ',' ) );
|
onQueryChange( 'compare' )( compareBy, compareParam, selectedRows.join( ',' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearch( value ) {
|
onSearch( value ) {
|
||||||
const { compareBy, onQueryChange } = this.props;
|
const { compareBy, compareParam, onQueryChange } = this.props;
|
||||||
const { selectedRows } = this.state;
|
const { selectedRows } = this.state;
|
||||||
if ( compareBy ) {
|
if ( compareBy ) {
|
||||||
const ids = value.map( v => v.id );
|
const ids = value.map( v => v.id );
|
||||||
onQueryChange( 'compare' )( compareBy, [ ...selectedRows, ...ids ].join( ',' ) );
|
onQueryChange( 'compare' )(
|
||||||
|
compareBy,
|
||||||
|
compareParam,
|
||||||
|
[ ...selectedRows, ...ids ].join( ',' )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +251,7 @@ class TableCard extends Component {
|
||||||
<Search
|
<Search
|
||||||
key="search"
|
key="search"
|
||||||
placeholder={ labels.placeholder || __( 'Search by item name', 'wc-admin' ) }
|
placeholder={ labels.placeholder || __( 'Search by item name', 'wc-admin' ) }
|
||||||
type={ compareBy + 's' }
|
type={ compareBy }
|
||||||
onChange={ this.onSearch }
|
onChange={ this.onSearch }
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
@ -409,6 +413,10 @@ TableCard.propTypes = {
|
||||||
* The total number of rows (across all pages).
|
* The total number of rows (across all pages).
|
||||||
*/
|
*/
|
||||||
totalRows: PropTypes.number.isRequired,
|
totalRows: PropTypes.number.isRequired,
|
||||||
|
/**
|
||||||
|
* Url query parameter compare function operates on
|
||||||
|
*/
|
||||||
|
compareParam: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
TableCard.defaultProps = {
|
TableCard.defaultProps = {
|
||||||
|
@ -418,6 +426,7 @@ TableCard.defaultProps = {
|
||||||
query: {},
|
query: {},
|
||||||
rowHeader: 0,
|
rowHeader: 0,
|
||||||
rows: [],
|
rows: [],
|
||||||
|
compareParam: 'filter',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TableCard;
|
export default TableCard;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -108,8 +108,8 @@ export function onQueryChange( param, path = getPath(), query = getQuery() ) {
|
||||||
case 'sort':
|
case 'sort':
|
||||||
return ( key, dir ) => updateQueryString( { orderby: key, order: dir }, path, query );
|
return ( key, dir ) => updateQueryString( { orderby: key, order: dir }, path, query );
|
||||||
case 'compare':
|
case 'compare':
|
||||||
return ( key, ids ) =>
|
return ( key, queryParam, ids ) =>
|
||||||
updateQueryString( { filter: `compare-${ key }`, [ key ]: ids }, path, query );
|
updateQueryString( { [ queryParam ]: `compare-${ key }`, [ key ]: ids }, path, query );
|
||||||
default:
|
default:
|
||||||
return value => updateQueryString( { [ param ]: value }, path, query );
|
return value => updateQueryString( { [ param ]: value }, path, query );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue