/** * WordPress dependencies */ import { SelectControl, TextControl } from '@safe-wordpress/components'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import { keys } from 'lodash'; import type { StringMatch } from '@neliosr/types'; const MATCH_LABELS: Record< StringMatch[ 'matchType' ], string > = { is: _x( 'is equal to', 'text', 'nelio-session-recordings' ), 'is-not': _x( 'is not equal to', 'text', 'nelio-session-recordings' ), includes: _x( 'includes', 'text', 'nelio-session-recordings' ), 'does-not-include': _x( 'does not include', 'text', 'nelio-session-recordings' ), regex: _x( 'matches regular expression', 'text', 'nelio-session-recordings' ), }; const MATCH_OPTIONS = keys( MATCH_LABELS ).map( ( value: StringMatch[ 'matchType' ] ) => ( { value, label: MATCH_LABELS[ value ], } ) ); export type StringMatchControlProps = { readonly label?: string; readonly match: StringMatch; readonly valueHelp?: string; readonly onStringMatchChange: ( newStringMatch: StringMatch ) => void; }; export const StringMatchControl = ( props: StringMatchControlProps ): JSX.Element => { const { label, match: { matchType, matchValue }, valueHelp, onStringMatchChange, } = props; return ( <> onStringMatchChange( { matchType: newMatchType, matchValue, } ) } /> { onStringMatchChange( { matchType, matchValue: newMatchValue, } ); } } /> ); };