Fix JS warning and default rating, use enums
MAILPOET-5413
This commit is contained in:
committed by
Aschepikov
parent
725012ae56
commit
f15d2f1cda
@@ -9,6 +9,8 @@ import {
|
|||||||
FilterProps,
|
FilterProps,
|
||||||
DaysPeriodItem,
|
DaysPeriodItem,
|
||||||
Timeframes,
|
Timeframes,
|
||||||
|
ReviewRating,
|
||||||
|
CountType,
|
||||||
} from '../../../types';
|
} from '../../../types';
|
||||||
import { validateDaysPeriod, DaysPeriodField } from '../days_period_field';
|
import { validateDaysPeriod, DaysPeriodField } from '../days_period_field';
|
||||||
import { isInEnum } from '../../../../../utils';
|
import { isInEnum } from '../../../../../utils';
|
||||||
@@ -36,18 +38,20 @@ export function NumberOfReviewsFields({
|
|||||||
useDispatch(storeName);
|
useDispatch(storeName);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (segment.count_type === undefined) {
|
if (!isInEnum(segment.count_type, CountType)) {
|
||||||
void updateSegmentFilter({ count_type: '=' }, filterIndex);
|
void updateSegmentFilter({ count_type: CountType.EQUALS }, filterIndex);
|
||||||
|
}
|
||||||
|
if (!isInEnum(segment.rating, ReviewRating)) {
|
||||||
|
void updateSegmentFilter({ rating: ReviewRating.ANY }, filterIndex);
|
||||||
|
}
|
||||||
|
if (!isInEnum(segment.timeframe, Timeframes)) {
|
||||||
|
void updateSegmentFilter(
|
||||||
|
{ timeframe: Timeframes.IN_THE_LAST },
|
||||||
|
filterIndex,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, [updateSegmentFilter, segment, filterIndex]);
|
}, [updateSegmentFilter, segment, filterIndex]);
|
||||||
|
|
||||||
if (!isInEnum(segment.timeframe, Timeframes)) {
|
|
||||||
void updateSegmentFilter(
|
|
||||||
{ timeframe: Timeframes.IN_THE_LAST },
|
|
||||||
filterIndex,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid.CenteredRow>
|
<Grid.CenteredRow>
|
||||||
@@ -58,12 +62,24 @@ export function NumberOfReviewsFields({
|
|||||||
void updateSegmentFilterFromEvent('rating', filterIndex, e);
|
void updateSegmentFilterFromEvent('rating', filterIndex, e);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<option value="any">{MailPoet.I18n.t('wooAnyStarRating')}</option>
|
<option value={ReviewRating.ANY}>
|
||||||
<option value="1">{MailPoet.I18n.t('wooOneStarRating')}</option>
|
{MailPoet.I18n.t('wooAnyStarRating')}
|
||||||
<option value="2">{MailPoet.I18n.t('wooTwoStarRating')}</option>
|
</option>
|
||||||
<option value="3">{MailPoet.I18n.t('wooThreeStarRating')}</option>
|
<option value={ReviewRating.ONE}>
|
||||||
<option value="4">{MailPoet.I18n.t('wooFourStarRating')}</option>
|
{MailPoet.I18n.t('wooOneStarRating')}
|
||||||
<option value="5">{MailPoet.I18n.t('wooFiveStarRating')}</option>
|
</option>
|
||||||
|
<option value={ReviewRating.TWO}>
|
||||||
|
{MailPoet.I18n.t('wooTwoStarRating')}
|
||||||
|
</option>
|
||||||
|
<option value={ReviewRating.THREE}>
|
||||||
|
{MailPoet.I18n.t('wooThreeStarRating')}
|
||||||
|
</option>
|
||||||
|
<option value={ReviewRating.FOUR}>
|
||||||
|
{MailPoet.I18n.t('wooFourStarRating')}
|
||||||
|
</option>
|
||||||
|
<option value={ReviewRating.FIVE}>
|
||||||
|
{MailPoet.I18n.t('wooFiveStarRating')}
|
||||||
|
</option>
|
||||||
</Select>
|
</Select>
|
||||||
<Select
|
<Select
|
||||||
key="select"
|
key="select"
|
||||||
@@ -73,10 +89,16 @@ export function NumberOfReviewsFields({
|
|||||||
}}
|
}}
|
||||||
automationId="select-number-of-reviews-type"
|
automationId="select-number-of-reviews-type"
|
||||||
>
|
>
|
||||||
<option value="=">{MailPoet.I18n.t('equals')}</option>
|
<option value={CountType.EQUALS}>{MailPoet.I18n.t('equals')}</option>
|
||||||
<option value="!=">{MailPoet.I18n.t('notEquals')}</option>
|
<option value={CountType.NOT_EQUALS}>
|
||||||
<option value=">">{MailPoet.I18n.t('moreThan')}</option>
|
{MailPoet.I18n.t('notEquals')}
|
||||||
<option value="<">{MailPoet.I18n.t('lessThan')}</option>
|
</option>
|
||||||
|
<option value={CountType.MORE_THAN}>
|
||||||
|
{MailPoet.I18n.t('moreThan')}
|
||||||
|
</option>
|
||||||
|
<option value={CountType.LESS_THAN}>
|
||||||
|
{MailPoet.I18n.t('lessThan')}
|
||||||
|
</option>
|
||||||
</Select>
|
</Select>
|
||||||
<Input
|
<Input
|
||||||
data-automation-id="input-number-of-reviews-count"
|
data-automation-id="input-number-of-reviews-count"
|
||||||
|
@@ -105,6 +105,22 @@ export interface WordpressRoleFormItem extends FormItem {
|
|||||||
form_ids?: string[];
|
form_ids?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ReviewRating {
|
||||||
|
ANY = 'any',
|
||||||
|
ONE = '1',
|
||||||
|
TWO = '2',
|
||||||
|
THREE = '3',
|
||||||
|
FOUR = '4',
|
||||||
|
FIVE = '5',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum CountType {
|
||||||
|
EQUALS = '=',
|
||||||
|
NOT_EQUALS = '!=',
|
||||||
|
MORE_THAN = '>',
|
||||||
|
LESS_THAN = '<',
|
||||||
|
}
|
||||||
|
|
||||||
export interface WooCommerceFormItem extends FormItem {
|
export interface WooCommerceFormItem extends FormItem {
|
||||||
category_ids?: string[];
|
category_ids?: string[];
|
||||||
product_ids?: string[];
|
product_ids?: string[];
|
||||||
@@ -122,8 +138,8 @@ export interface WooCommerceFormItem extends FormItem {
|
|||||||
used_payment_method_days?: string;
|
used_payment_method_days?: string;
|
||||||
shipping_methods?: string[];
|
shipping_methods?: string[];
|
||||||
used_shipping_method_days?: string;
|
used_shipping_method_days?: string;
|
||||||
rating?: string;
|
rating?: ReviewRating;
|
||||||
count_type?: string;
|
count_type?: CountType;
|
||||||
count?: string;
|
count?: string;
|
||||||
days?: string;
|
days?: string;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user