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