/** * WordPress dependencies */ import { Dashicon, SelectControl } from '@safe-wordpress/components'; import { useDispatch, useSelect } from '@safe-wordpress/data'; import { createInterpolateElement } from '@safe-wordpress/element'; import { _x, sprintf } from '@safe-wordpress/i18n'; /** * External dependencies */ import { findIndex } from 'lodash'; import { v4 as uuid } from 'uuid'; import { usePluginSetting } from '@nab/data'; import { createSegment } from '@nab/utils'; import type { Dict, Segment as RealSegment, SegmentationRule, SegmentId, } from '@nab/types'; type Segment = Omit< RealSegment, 'segmentationRules' >; /** * Internal dependencies */ import './style.scss'; import { useExperimentAttribute } from '../hooks'; import { Segment as SegmentView } from '../segment'; import { SegmentList } from '../segment-list'; import { ReusableSegmentDialog } from '../reusable-segment-dialog'; import { store as NAB_EDITOR } from '../../store'; export const SegmentationSection = (): JSX.Element => { const [ segment, updateActiveSegment ] = useActiveSegment(); const [ status ] = useExperimentAttribute( 'status' ); const [ segmentEvaluation, setSegmentEvaluation ] = useSegmentEvaluation(); const globalSegmentEvaluation = usePluginSetting( 'segmentEvaluation' ); const isExperimentPaused = ( status || '' ).includes( 'paused' ); const removeActiveSegment = useActiveSegmentRemover(); const canSegmentBeRemoved = ! isExperimentPaused; const canSegmentBeDuplicated = ! isExperimentPaused; const rules = useSegmentRules( segment?.id ); const { addSegments, addSegmentationRulesIntoSegment } = useDispatch( NAB_EDITOR ); const duplicateSegment = () => { if ( ! segment ) { return; } const newSegment = { ...createSegment(), attributes: { ...segment.attributes, name: segment.attributes.name ? sprintf( /* translators: %s: Name of an item being duplicated. */ _x( 'Copy of %s', 'text', 'nelio-ab-testing' ), segment.attributes.name ) : '', }, }; const newRules: ReadonlyArray< SegmentationRule > = rules.map( ( r ) => ( { ...r, id: uuid(), } ) ); void addSegments( newSegment ); void addSegmentationRulesIntoSegment( newSegment.id, newRules ); }; return (
{ _x( 'Add a new segment to narrow your tested audience and target only a subset of your visitors.', 'user', 'nelio-ab-testing' ) }
) }