Convert "is in Country" select to multiple select

[MAILPOET-3952]
This commit is contained in:
Brezo Cordero
2021-12-08 21:09:18 -06:00
committed by Veljko V
parent 9a9ab257c2
commit 8292cd9fd3
4 changed files with 35 additions and 18 deletions

View File

@ -57,7 +57,9 @@ export function validateWooCommerce(formItems: WooCommerceFormItem): boolean {
if (formItems.action === WooCommerceActionTypes.PURCHASED_PRODUCT && purchasedProductIsInvalid) { if (formItems.action === WooCommerceActionTypes.PURCHASED_PRODUCT && purchasedProductIsInvalid) {
return false; return false;
} }
if (formItems.action === WooCommerceActionTypes.CUSTOMER_IN_COUNTRY && !formItems.country_code) { const countryCodeIsInvalid = formItems.country_code === undefined
|| formItems.country_code.length === 0;
if (formItems.action === WooCommerceActionTypes.CUSTOMER_IN_COUNTRY && countryCodeIsInvalid) {
return false; return false;
} }
const numberOfOrdersIsInvalid = !formItems.number_of_orders_count const numberOfOrdersIsInvalid = !formItems.number_of_orders_count
@ -320,21 +322,32 @@ export const WooCommerceFields: React.FunctionComponent<Props> = ({ filterIndex
); );
} else if (segment.action === WooCommerceActionTypes.CUSTOMER_IN_COUNTRY) { } else if (segment.action === WooCommerceActionTypes.CUSTOMER_IN_COUNTRY) {
optionFields = ( optionFields = (
<div> <>
<ReactSelect <Grid.CenteredRow>
dimension="small" <ReactSelect
key="select-segment-country" dimension="small"
isFullWidth key="select-segment-country"
placeholder={MailPoet.I18n.t('selectWooCountry')} isFullWidth
options={countryOptions} isMulti
value={find(['value', segment.country_code], countryOptions)} placeholder={MailPoet.I18n.t('selectWooCountry')}
onChange={(option: SelectOption): void => updateSegmentFilter( options={countryOptions}
{ country_code: option.value }, value={
filterIndex filter(
)} (option) => {
automationId="select-segment-country" if (!segment.country_code) return undefined;
/> return segment.country_code.indexOf(option.value) !== -1;
</div> },
countryOptions
)
}
onChange={(options: SelectOption[]): void => updateSegmentFilter(
{ country_code: (options || []).map((x: SelectOption) => x.value) },
filterIndex
)}
automationId="select-segment-country"
/>
</Grid.CenteredRow>
</>
); );
} }

View File

@ -81,7 +81,7 @@ export interface WooCommerceFormItem extends FormItem {
total_spent_type?: string; total_spent_type?: string;
total_spent_amount?: number; total_spent_amount?: number;
total_spent_days?: number; total_spent_days?: number;
country_code?: string; country_code?: string[];
} }
export interface WooCommerceSubscriptionFormItem extends FormItem { export interface WooCommerceSubscriptionFormItem extends FormItem {

View File

@ -51,6 +51,10 @@ class DynamicSegmentsResponseBuilder {
$filter['id'] = $dynamicFilter->getId(); $filter['id'] = $dynamicFilter->getId();
$filter['segmentType'] = $dynamicFilter->getFilterData()->getFilterType(); // We need to add filterType with key segmentType due to BC $filter['segmentType'] = $dynamicFilter->getFilterData()->getFilterType(); // We need to add filterType with key segmentType due to BC
$filter['action'] = $dynamicFilter->getFilterData()->getAction(); $filter['action'] = $dynamicFilter->getFilterData()->getAction();
if (isset($filter['country_code']) && !is_array($filter['country_code'])) {
// Convert to multiple values filter
$filter['country_code'] = [$filter['country_code']];
}
if (isset($filter['wordpressRole']) && !is_array($filter['wordpressRole'])) { if (isset($filter['wordpressRole']) && !is_array($filter['wordpressRole'])) {
// new filters are always array, they support multiple values, the old didn't convert old filters to new format // new filters are always array, they support multiple values, the old didn't convert old filters to new format
$filter['wordpressRole'] = [$filter['wordpressRole']]; $filter['wordpressRole'] = [$filter['wordpressRole']];

View File

@ -215,7 +215,7 @@
'wooTotalSpentAmount': __('amount'), 'wooTotalSpentAmount': __('amount'),
'selectWooPurchasedCategory': __('Search categories'), 'selectWooPurchasedCategory': __('Search categories'),
'selectWooPurchasedProduct': __('Search products'), 'selectWooPurchasedProduct': __('Search products'),
'selectWooCountry': __('Select country'), 'selectWooCountry': __('Search countries'),
'woocommerce': _x('WooCommerce', 'Dynamic segment creation: User selects this to use any woocommerce filters'), 'woocommerce': _x('WooCommerce', 'Dynamic segment creation: User selects this to use any woocommerce filters'),
'dynamicSegmentSizeIsCalculated': __('Calculating segment size…'), 'dynamicSegmentSizeIsCalculated': __('Calculating segment size…'),