11import React , { useEffect , useState } from 'react'
2+ import { components } from 'react-select/lib/components'
23import Utils from 'common/utils/utils'
34import { RuleContextValues } from 'common/types/rules.types'
45import Constants from 'common/constants'
5- import Icon from 'components/Icon'
6-
7- export interface OptionType {
8- enabled ?: boolean
9- label : string
10- value : string
11- }
6+ import { GroupLabel } from 'components/base/SearchableDropdown'
7+ import SearchableDropdown , {
8+ OptionType ,
9+ } from 'components/base/SearchableDropdown'
1210
1311interface RuleConditionPropertySelectProps {
1412 ruleIndex : number
@@ -24,32 +22,6 @@ interface RuleConditionPropertySelectProps {
2422 isValueFromContext : boolean
2523}
2624
27- const GroupLabel = ( {
28- groupName,
29- tooltipText,
30- } : {
31- groupName : string
32- tooltipText ?: string
33- } ) => {
34- return (
35- < div className = 'd-flex align-items-center gap-1' >
36- < div > { groupName } </ div >
37- { tooltipText && (
38- < Tooltip
39- title = {
40- < h5 className = 'mb-1 cursor-pointer' >
41- < Icon name = 'info-outlined' height = { 16 } width = { 16 } />
42- </ h5 >
43- }
44- place = 'right'
45- >
46- { tooltipText }
47- </ Tooltip >
48- ) }
49- </ div >
50- )
51- }
52-
5325const RuleConditionPropertySelect = ( {
5426 allowedContextValues,
5527 dataTest,
@@ -90,20 +62,21 @@ const RuleConditionPropertySelect = ({
9062 contextOptions . find ( ( option ) => option . value === propertyValue ) ?. label ||
9163 propertyValue
9264 const isEditing = localCurrentValue !== propertyValue
93- const traitAsGroupedOptions =
65+ const showTraitOptions =
9466 localCurrentValue && ( ! isValueFromContext || isEditing )
95- ? [
96- {
97- label : (
98- < GroupLabel
99- groupName = 'Traits'
100- tooltipText = { Constants . strings . USER_PROPERTY_DESCRIPTION }
101- />
102- ) ,
103- options : [ { label : localCurrentValue , value : localCurrentValue } ] ,
104- } ,
105- ]
106- : [ ]
67+ const traitAsGroupedOptions = showTraitOptions
68+ ? [
69+ {
70+ label : (
71+ < GroupLabel
72+ groupName = 'Traits'
73+ tooltipText = { Constants . strings . USER_PROPERTY_DESCRIPTION }
74+ />
75+ ) ,
76+ options : [ { label : localCurrentValue , value : localCurrentValue } ] ,
77+ } ,
78+ ]
79+ : [ ]
10780
10881 const contextAsGroupedOptions =
10982 contextOptions ?. length > 0
@@ -129,22 +102,20 @@ const RuleConditionPropertySelect = ({
129102 ...contextAsGroupedOptions ,
130103 ]
131104
105+ const showTitle = ! showTraitOptions && operator !== 'PERCENTAGE_SPLIT'
106+
132107 return (
133108 < >
134- < Select
135- data-test = { dataTest }
109+ < SearchableDropdown
110+ dataTest = { dataTest }
111+ value = { propertyValue }
112+ isClearable = { true }
136113 placeholder = { 'Trait / Context value' }
137- value = {
138- localCurrentValue
139- ? { label : displayedLabel , value : propertyValue }
140- : null
141- }
114+ options = { optionsWithTrait }
115+ noOptionsMessage = { 'Start typing to select a trait' }
142116 onBlur = { ( ) => {
143117 setRuleProperty ( ruleIndex , 'property' , { value : localCurrentValue } )
144118 } }
145- isSearchable = {
146- operator !== 'PERCENTAGE_SPLIT' || isContextPropertyEnabled
147- }
148119 onInputChange = { ( e : string , metadata : any ) => {
149120 if ( metadata . action !== 'input-change' ) {
150121 return
@@ -156,10 +127,25 @@ const RuleConditionPropertySelect = ({
156127 value : Utils . safeParseEventValue ( e ?. value ) ,
157128 } )
158129 } }
159- options = { [ ...optionsWithTrait ] }
160- style = { { width : '200px' } }
161- noOptionsMessage = { ( ) => {
162- return 'Start typing to select a trait'
130+ displayedLabel = { displayedLabel }
131+ components = { {
132+ Menu : ( { ...props } : any ) => {
133+ return (
134+ < components . Menu { ...props } >
135+ < React . Fragment >
136+ { showTitle && (
137+ < p
138+ style = { { fontStyle : 'italic' , paddingTop : 6 } }
139+ className = 'mb-0 faint text-center'
140+ >
141+ Pick a value or type a trait name
142+ </ p >
143+ ) }
144+ { props . children }
145+ </ React . Fragment >
146+ </ components . Menu >
147+ )
148+ } ,
163149 } }
164150 />
165151 </ >
0 commit comments