Merge branch 'master' into fix/1012-2

This commit is contained in:
Peter Fabian 2019-01-24 11:18:23 +01:00
commit d75c963bb1
10 changed files with 77 additions and 81 deletions

View File

@ -193,6 +193,7 @@ export default compose(
const selectProps = { const selectProps = {
primaryData, primaryData,
tableData: extendedTableData, tableData: extendedTableData,
query: { ...tableQuery, ...query },
}; };
if ( columnPrefsKey ) { if ( columnPrefsKey ) {

View File

@ -7,8 +7,7 @@ import { __ } from '@wordpress/i18n';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { getRequestByIdString } from 'lib/async-requests'; import { getCategoryLabels } from 'lib/async-requests';
import { NAMESPACE } from 'store/constants';
export const charts = [ export const charts = [
{ {
@ -49,10 +48,7 @@ export const filters = [
settings: { settings: {
type: 'categories', type: 'categories',
param: 'categories', param: 'categories',
getLabels: getRequestByIdString( NAMESPACE + 'products/categories', category => ( { getLabels: getCategoryLabels,
id: category.id,
label: category.name,
} ) ),
labels: { labels: {
placeholder: __( 'Type to search for a category', 'wc-admin' ), placeholder: __( 'Type to search for a category', 'wc-admin' ),
button: __( 'Single Category', 'wc-admin' ), button: __( 'Single Category', 'wc-admin' ),
@ -68,10 +64,7 @@ export const filters = [
settings: { settings: {
type: 'categories', type: 'categories',
param: 'categories', param: 'categories',
getLabels: getRequestByIdString( NAMESPACE + 'products/categories', cat => ( { getLabels: getCategoryLabels,
id: cat.id,
label: cat.name,
} ) ),
labels: { labels: {
helpText: __( 'Select at least two categories to compare', 'wc-admin' ), helpText: __( 'Select at least two categories to compare', 'wc-admin' ),
placeholder: __( 'Search for categories to compare', 'wc-admin' ), placeholder: __( 'Search for categories to compare', 'wc-admin' ),

View File

@ -7,8 +7,7 @@ import { __ } from '@wordpress/i18n';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { getRequestByIdString } from 'lib/async-requests'; import { getCouponLabels } from 'lib/async-requests';
import { NAMESPACE } from 'store/constants';
export const charts = [ export const charts = [
{ {
@ -44,10 +43,7 @@ export const filters = [
settings: { settings: {
type: 'coupons', type: 'coupons',
param: 'coupons', param: 'coupons',
getLabels: getRequestByIdString( NAMESPACE + 'coupons', coupon => ( { getLabels: getCouponLabels,
id: coupon.id,
label: coupon.code,
} ) ),
labels: { labels: {
placeholder: __( 'Type to search for a coupon', 'wc-admin' ), placeholder: __( 'Type to search for a coupon', 'wc-admin' ),
button: __( 'Single Coupon', 'wc-admin' ), button: __( 'Single Coupon', 'wc-admin' ),
@ -62,10 +58,7 @@ export const filters = [
settings: { settings: {
type: 'coupons', type: 'coupons',
param: 'coupons', param: 'coupons',
getLabels: getRequestByIdString( NAMESPACE + 'coupons', coupon => ( { getLabels: getCouponLabels,
id: coupon.id,
label: coupon.code,
} ) ),
labels: { labels: {
title: __( 'Compare Coupon Codes', 'wc-admin' ), title: __( 'Compare Coupon Codes', 'wc-admin' ),
update: __( 'Compare', 'wc-admin' ), update: __( 'Compare', 'wc-admin' ),

View File

@ -8,7 +8,7 @@ import { decodeEntities } from '@wordpress/html-entities';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { getRequestByIdString } from 'lib/async-requests'; import { getCustomerLabels, getRequestByIdString } from 'lib/async-requests';
import { NAMESPACE } from 'store/constants'; import { NAMESPACE } from 'store/constants';
export const filters = [ export const filters = [
@ -129,10 +129,7 @@ export const advancedFilters = {
input: { input: {
component: 'Search', component: 'Search',
type: 'usernames', type: 'usernames',
getLabels: getRequestByIdString( NAMESPACE + 'customers', customer => ( { getLabels: getCustomerLabels,
id: customer.id,
label: customer.username,
} ) ),
}, },
}, },
email: { email: {

View File

@ -7,8 +7,7 @@ import { __, _x } from '@wordpress/i18n';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { getRequestByIdString } from 'lib/async-requests'; import { getCustomerLabels, getProductLabels } from 'lib/async-requests';
import { NAMESPACE } from 'store/constants';
export const charts = [ export const charts = [
{ {
@ -64,10 +63,7 @@ export const advancedFilters = {
input: { input: {
component: 'Search', component: 'Search',
type: 'products', type: 'products',
getLabels: getRequestByIdString( NAMESPACE + 'products', product => ( { getLabels: getProductLabels,
id: product.id,
label: product.name,
} ) ),
}, },
}, },
user: { user: {
@ -95,10 +91,7 @@ export const advancedFilters = {
input: { input: {
component: 'Search', component: 'Search',
type: 'usernames', type: 'usernames',
getLabels: getRequestByIdString( NAMESPACE + 'customers', customer => ( { getLabels: getCustomerLabels,
id: customer.id,
label: customer.username,
} ) ),
}, },
}, },
order: { order: {
@ -126,10 +119,13 @@ export const advancedFilters = {
input: { input: {
component: 'Search', component: 'Search',
type: 'orders', type: 'orders',
getLabels: getRequestByIdString( NAMESPACE + 'orders', order => ( { getLabels: async value => {
id: order.id, const orderIds = value.split( ',' );
label: '#' + order.id, return await orderIds.map( orderId => ( {
} ) ), id: orderId,
label: '#' + orderId,
} ) );
},
}, },
}, },
ip_address: { ip_address: {

View File

@ -7,8 +7,7 @@ import { __, _x } from '@wordpress/i18n';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { getRequestByIdString } from 'lib/async-requests'; import { getCouponLabels, getProductLabels } from 'lib/async-requests';
import { NAMESPACE } from 'store/constants';
const { orderStatuses } = wcSettings; const { orderStatuses } = wcSettings;
@ -110,10 +109,7 @@ export const advancedFilters = {
input: { input: {
component: 'Search', component: 'Search',
type: 'products', type: 'products',
getLabels: getRequestByIdString( NAMESPACE + 'products', product => ( { getLabels: getProductLabels,
id: product.id,
label: product.name,
} ) ),
}, },
}, },
coupon: { coupon: {
@ -141,10 +137,7 @@ export const advancedFilters = {
input: { input: {
component: 'Search', component: 'Search',
type: 'coupons', type: 'coupons',
getLabels: getRequestByIdString( NAMESPACE + 'coupons', coupon => ( { getLabels: getCouponLabels,
id: coupon.id,
label: coupon.code,
} ) ),
}, },
}, },
customer: { customer: {

View File

@ -7,8 +7,7 @@ import { __ } from '@wordpress/i18n';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { getRequestByIdString } from 'lib/async-requests'; import { getProductLabels, getCategoryLabels, getVariationLabels } from 'lib/async-requests';
import { NAMESPACE } from 'store/constants';
export const charts = [ export const charts = [
{ {
@ -48,10 +47,7 @@ const filterConfig = {
settings: { settings: {
type: 'products', type: 'products',
param: 'products', param: 'products',
getLabels: getRequestByIdString( NAMESPACE + 'products', product => ( { getLabels: getProductLabels,
id: product.id,
label: product.name,
} ) ),
labels: { labels: {
placeholder: __( 'Type to search for a product', 'wc-admin' ), placeholder: __( 'Type to search for a product', 'wc-admin' ),
button: __( 'Single Product', 'wc-admin' ), button: __( 'Single Product', 'wc-admin' ),
@ -73,10 +69,7 @@ const filterConfig = {
settings: { settings: {
type: 'categories', type: 'categories',
param: 'categories', param: 'categories',
getLabels: getRequestByIdString( NAMESPACE + 'products/categories', category => ( { getLabels: getCategoryLabels,
id: category.id,
label: category.name,
} ) ),
labels: { labels: {
placeholder: __( 'Type to search for a product category', 'wc-admin' ), placeholder: __( 'Type to search for a product category', 'wc-admin' ),
button: __( 'Single Product Category', 'wc-admin' ), button: __( 'Single Product Category', 'wc-admin' ),
@ -92,10 +85,7 @@ const filterConfig = {
settings: { settings: {
type: 'products', type: 'products',
param: 'products', param: 'products',
getLabels: getRequestByIdString( NAMESPACE + 'products', product => ( { getLabels: getProductLabels,
id: product.id,
label: product.name,
} ) ),
labels: { labels: {
helpText: __( 'Select at least two products to compare', 'wc-admin' ), helpText: __( 'Select at least two products to compare', 'wc-admin' ),
placeholder: __( 'Search for products to compare', 'wc-admin' ), placeholder: __( 'Search for products to compare', 'wc-admin' ),
@ -111,10 +101,7 @@ const filterConfig = {
settings: { settings: {
type: 'categories', type: 'categories',
param: 'categories', param: 'categories',
getLabels: getRequestByIdString( NAMESPACE + 'products/categories', category => ( { getLabels: getCategoryLabels,
id: category.id,
label: category.name,
} ) ),
labels: { labels: {
helpText: __( 'Select at least two product categories to compare', 'wc-admin' ), helpText: __( 'Select at least two product categories to compare', 'wc-admin' ),
placeholder: __( 'Search for product categories to compare', 'wc-admin' ), placeholder: __( 'Search for product categories to compare', 'wc-admin' ),
@ -151,19 +138,7 @@ const variationsConfig = {
settings: { settings: {
type: 'variations', type: 'variations',
param: 'variations', param: 'variations',
getLabels: getRequestByIdString( getLabels: getVariationLabels,
query => NAMESPACE + `products/${ query.products }/variations`,
variation => {
return {
id: variation.id,
label: variation.attributes.reduce(
( desc, attribute, index, arr ) =>
desc + `${ attribute.option }${ arr.length === index + 1 ? '' : ', ' }`,
''
),
};
}
),
labels: { labels: {
helpText: __( 'Select at least two variations to compare', 'wc-admin' ), helpText: __( 'Select at least two variations to compare', 'wc-admin' ),
placeholder: __( 'Search for variations to compare', 'wc-admin' ), placeholder: __( 'Search for variations to compare', 'wc-admin' ),

View File

@ -10,6 +10,11 @@ import { identity } from 'lodash';
*/ */
import { getIdsFromQuery, stringifyQuery } from '@woocommerce/navigation'; import { getIdsFromQuery, stringifyQuery } from '@woocommerce/navigation';
/**
* Internal dependencies
*/
import { NAMESPACE } from 'store/constants';
/** /**
* Get a function that accepts ids as they are found in url parameter and * Get a function that accepts ids as they are found in url parameter and
* returns a promise with an optional method applied to results * returns a promise with an optional method applied to results
@ -32,3 +37,40 @@ export function getRequestByIdString( path, handleData = identity ) {
return apiFetch( { path: pathString + payload } ).then( data => data.map( handleData ) ); return apiFetch( { path: pathString + payload } ).then( data => data.map( handleData ) );
}; };
} }
export const getCategoryLabels = getRequestByIdString(
NAMESPACE + 'products/categories',
category => ( {
id: category.id,
label: category.name,
} )
);
export const getCouponLabels = getRequestByIdString( NAMESPACE + 'coupons', coupon => ( {
id: coupon.id,
label: coupon.code,
} ) );
export const getCustomerLabels = getRequestByIdString( NAMESPACE + 'customers', customer => ( {
id: customer.id,
label: customer.username,
} ) );
export const getProductLabels = getRequestByIdString( NAMESPACE + 'products', product => ( {
id: product.id,
label: product.name,
} ) );
export const getVariationLabels = getRequestByIdString(
query => NAMESPACE + `products/${ query.products }/variations`,
variation => {
return {
id: variation.id,
label: variation.attributes.reduce(
( desc, attribute, index, arr ) =>
desc + `${ attribute.option }${ arr.length === index + 1 ? '' : ', ' }`,
''
),
};
}
);

View File

@ -193,7 +193,10 @@ export class Autocomplete extends Component {
} }
} }
// create a regular expression to filter the options // create a regular expression to filter the options
const search = new RegExp( escapeRegExp( query ), 'i' ); const expression = 'undefined' !== typeof completer.getSearchExpression
? completer.getSearchExpression( escapeRegExp( query ) )
: escapeRegExp( query );
const search = new RegExp( expression, 'i' );
// filter the options we already have // filter the options we already have
const filteredOptions = filterOptions( search, this.state.options, selected ); const filteredOptions = filterOptions( search, this.state.options, selected );
// update the state // update the state

View File

@ -23,6 +23,9 @@ export default {
options() { options() {
return wcSettings.dataEndpoints.countries || []; return wcSettings.dataEndpoints.countries || [];
}, },
getSearchExpression( query ) {
return '^' + query;
},
getOptionKeywords( country ) { getOptionKeywords( country ) {
return [ country.code, decodeEntities( country.name ) ]; return [ country.code, decodeEntities( country.name ) ];
}, },