Group multiple useSelect to one in the dynamic segment from
This is just a tiny optimization I did when debugging the acceptance test, and I decided to keep it. [MAILPOET-6054]
This commit is contained in:
committed by
Aschepikov
parent
bd1cf97085
commit
dedd9d52c2
@@ -18,13 +18,7 @@ import { isFormValid } from './validator';
|
|||||||
import { PrivacyProtectionNotice } from './privacy-protection-notice';
|
import { PrivacyProtectionNotice } from './privacy-protection-notice';
|
||||||
import { storeName } from './store';
|
import { storeName } from './store';
|
||||||
|
|
||||||
import {
|
import { FilterValue } from './types';
|
||||||
FilterRow,
|
|
||||||
FilterValue,
|
|
||||||
GroupFilterValue,
|
|
||||||
Segment,
|
|
||||||
SubscriberCount,
|
|
||||||
} from './types';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isNewSegment: boolean;
|
isNewSegment: boolean;
|
||||||
@@ -45,36 +39,23 @@ const FilterAfter = Hooks.applyFilters(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export function Form({ isNewSegment, newsletterId }: Props): JSX.Element {
|
export function Form({ isNewSegment, newsletterId }: Props): JSX.Element {
|
||||||
const segment: Segment = useSelect(
|
const { segment, segmentFilters, subscriberCount, filterRows, errors } =
|
||||||
(select) => select(storeName).getSegment(),
|
useSelect((select) => {
|
||||||
[],
|
const segmentData = select(storeName).getSegment();
|
||||||
);
|
return {
|
||||||
|
segment: segmentData,
|
||||||
|
segmentFilters: select(storeName).getAvailableFilters(),
|
||||||
|
subscriberCount: select(storeName).getSubscriberCount(),
|
||||||
|
filterRows: select(storeName).findFiltersValueForSegment(segmentData),
|
||||||
|
errors: select(storeName).getErrors(),
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
const segmentFiltersCount = segment.filters.length;
|
const segmentFiltersCount = segment.filters.length;
|
||||||
const segmentFiltersLimitReached =
|
const segmentFiltersLimitReached =
|
||||||
MailPoet.capabilities.segmentFilters.value > 0 && // 0 is unlimited
|
MailPoet.capabilities.segmentFilters.value > 0 && // 0 is unlimited
|
||||||
segmentFiltersCount >= MailPoet.capabilities.segmentFilters.value;
|
segmentFiltersCount >= MailPoet.capabilities.segmentFilters.value;
|
||||||
|
|
||||||
const segmentFilters: GroupFilterValue[] = useSelect(
|
|
||||||
(select) => select(storeName).getAvailableFilters(),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const filterRows: FilterRow[] = useSelect(
|
|
||||||
(select) => select(storeName).findFiltersValueForSegment(segment),
|
|
||||||
[segment],
|
|
||||||
);
|
|
||||||
|
|
||||||
const subscriberCount: SubscriberCount = useSelect(
|
|
||||||
(select) => select(storeName).getSubscriberCount(),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const errors: string[] = useSelect(
|
|
||||||
(select) => select(storeName).getErrors(),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const { updateSegment, updateSegmentFilter, handleSave } =
|
const { updateSegment, updateSegmentFilter, handleSave } =
|
||||||
useDispatch(storeName);
|
useDispatch(storeName);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user