@@ -4,8 +4,10 @@ import {
44} from '@appquality/unguess-design-system' ;
55import { ReactComponent as EditIcon } from '@zendeskgarden/svg-icons/src/12/pencil-stroke.svg' ;
66import { FormikProps } from 'formik' ;
7+ import { ComponentProps , useMemo } from 'react' ;
78import { useTranslation } from 'react-i18next' ;
89import { useParams } from 'react-router-dom' ;
10+ import analytics from 'src/analytics' ;
911import { ReactComponent as CopyIcon } from 'src/assets/icons/copy-icon.svg' ;
1012import {
1113 GetCampaignsByCidVideoTagsApiResponse ,
@@ -31,6 +33,42 @@ export const TitleDropdown = ({
3133 const { campaignId } = useParams ( ) ;
3234 const [ addVideoTags ] = usePostCampaignsByCidVideoTagsMutation ( ) ;
3335 const titleMaxLength = 70 ;
36+ const options : ComponentProps < typeof Autocomplete > [ 'options' ] = useMemo (
37+ ( ) =>
38+ ( titles || [ ] ) . map ( ( i ) => ( {
39+ id : i . id . toString ( ) ,
40+ value : i . id . toString ( ) ,
41+ label : `${ i . name } (${ i . usageNumber } )` ,
42+ isSelected : formProps . values . title === i . id ,
43+ actions : ( { closeModal } ) => (
44+ < EditTagModal
45+ type = "theme"
46+ tag = { i }
47+ closeModal = { closeModal }
48+ title = { t ( '__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_TITLE' ) }
49+ label = { t ( '__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_LABEL' ) }
50+ description = { t (
51+ '__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_DESCRIPTION' ,
52+ {
53+ usageNumber : i . usageNumber ,
54+ count : Number ( i . usageNumber ) ,
55+ }
56+ ) }
57+ />
58+ ) ,
59+ actionIcon : < EditIcon /> ,
60+ itemID : i . id . toString ( ) ,
61+ onOptionActionClick : ( ) => {
62+ analytics . track ( 'tagEditModalOpened' , {
63+ tagId : i . id . toString ( ) ,
64+ tagType : 'theme' ,
65+ tagName : i . name ,
66+ associatedObservations : i . usageNumber ,
67+ } ) ;
68+ } ,
69+ } ) ) ,
70+ [ titles , formProps . values . title ]
71+ ) ;
3472
3573 if ( ! titles ) {
3674 return null ;
@@ -39,6 +77,7 @@ export const TitleDropdown = ({
3977 return (
4078 < Field >
4179 < Autocomplete
80+ options = { options }
4281 data-qa = "video-title-dropdown"
4382 isEditable
4483 isCreatable
@@ -49,6 +88,12 @@ export const TitleDropdown = ({
4988 const title = titles . find ( ( i ) => i . id === Number ( selection . value ) ) ;
5089 return title ?. name || '' ;
5190 } }
91+ onClick = { ( ) =>
92+ analytics . track ( 'tagDropdownOpened' , {
93+ dropdownType : 'theme' ,
94+ availableTagsCount : options . length ,
95+ } )
96+ }
5297 selectionValue = { formProps . values . title . toString ( ) }
5398 onCreateNewOption = { async ( value ) => {
5499 if ( value . length > titleMaxLength ) {
@@ -83,29 +128,6 @@ export const TitleDropdown = ({
83128 if ( ! selectionValue || ! inputValue ) return ;
84129 formProps . setFieldValue ( 'title' , Number ( selectionValue ) ) ;
85130 } }
86- options = { ( titles || [ ] ) . map ( ( i ) => ( {
87- id : i . id . toString ( ) ,
88- value : i . id . toString ( ) ,
89- label : `${ i . name } (${ i . usageNumber } )` ,
90- isSelected : formProps . values . title === i . id ,
91- actions : ( { closeModal } ) => (
92- < EditTagModal
93- tag = { i }
94- closeModal = { closeModal }
95- title = { t ( '__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_TITLE' ) }
96- label = { t ( '__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_LABEL' ) }
97- description = { t (
98- '__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_DESCRIPTION' ,
99- {
100- usageNumber : i . usageNumber ,
101- count : Number ( i . usageNumber ) ,
102- }
103- ) }
104- />
105- ) ,
106- itemID : i . id . toString ( ) ,
107- actionIcon : < EditIcon /> ,
108- } ) ) }
109131 startIcon = { < CopyIcon /> }
110132 placeholder = { t (
111133 '__VIDEO_PAGE_ACTIONS_OBSERVATION_FORM_FIELD_TITLE_PLACEHOLDER'
0 commit comments