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:
Rostislav Wolny
2024-06-05 15:38:06 +02:00
committed by Aschepikov
parent bd1cf97085
commit dedd9d52c2

View File

@@ -18,13 +18,7 @@ import { isFormValid } from './validator';
import { PrivacyProtectionNotice } from './privacy-protection-notice';
import { storeName } from './store';
import {
FilterRow,
FilterValue,
GroupFilterValue,
Segment,
SubscriberCount,
} from './types';
import { FilterValue } from './types';
interface Props {
isNewSegment: boolean;
@@ -45,36 +39,23 @@ const FilterAfter = Hooks.applyFilters(
);
export function Form({ isNewSegment, newsletterId }: Props): JSX.Element {
const segment: Segment = useSelect(
(select) => select(storeName).getSegment(),
[],
);
const { segment, segmentFilters, subscriberCount, filterRows, errors } =
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 segmentFiltersLimitReached =
MailPoet.capabilities.segmentFilters.value > 0 && // 0 is unlimited
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 } =
useDispatch(storeName);