@@ -29,30 +29,10 @@ type Hierarchy = Record<string, Category & {[key: string]: Hierarchy & Category}
2929 * @param options - an initial object array
3030 * @param options[].enabled - a flag to enable/disable option in a list
3131 * @param options[].name - a name of an option
32- * @param [isOneLine] - a flag to determine if text should be one line
3332 */
34- function getCategoryOptionTree ( options : Record < string , Category > | Category [ ] , isOneLine = false , selectedOptions : Category [ ] = [ ] ) : OptionTree [ ] {
33+ function getCategoryOptionTree ( options : Record < string , Category > | Category [ ] , selectedOptions : Category [ ] = [ ] ) : OptionTree [ ] {
3534 const optionCollection = new Map < string , OptionTree > ( ) ;
3635 for ( const option of Object . values ( options ) ) {
37- if ( isOneLine ) {
38- if ( optionCollection . has ( option . name ) ) {
39- continue ;
40- }
41-
42- const decodedCategoryName = getDecodedCategoryName ( option . name ) ;
43- optionCollection . set ( option . name , {
44- text : decodedCategoryName ,
45- keyForList : option . name ,
46- searchText : option . name ,
47- tooltipText : decodedCategoryName ,
48- isDisabled : ! option . enabled || option . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ,
49- isSelected : ! ! option . isSelected ,
50- pendingAction : option . pendingAction ,
51- } ) ;
52-
53- continue ;
54- }
55-
5636 const array = option . name . split ( CONST . PARENT_CHILD_SEPARATOR ) ;
5737
5838 for ( let index = 0 ; index < array . length ; index ++ ) {
@@ -70,13 +50,14 @@ function getCategoryOptionTree(options: Record<string, Category> | Category[], i
7050 if ( optionCollection . has ( searchText ) ) {
7151 continue ;
7252 }
73-
74- const decodedCategoryName = getDecodedCategoryName ( optionName ) ;
53+ const leafName = getDecodedCategoryName ( optionName . trim ( ) ) ;
54+ const decodedCategoryName = getDecodedCategoryName ( option . name ) ;
55+ const tooltipText = isChild ? decodedCategoryName : getDecodedCategoryName ( searchText ) ;
7556 optionCollection . set ( searchText , {
76- text : `${ indents } ${ decodedCategoryName } ` ,
57+ text : `${ indents } ${ leafName } ` ,
7758 keyForList : searchText ,
7859 searchText,
79- tooltipText : decodedCategoryName ,
60+ tooltipText,
8061 isDisabled : isChild ? ! option . enabled || option . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE : isParentOptionDisabled ,
8162 isSelected : isChild ? ! ! option . isSelected : ! ! selectedParentOption ,
8263 pendingAction : option . pendingAction ,
@@ -124,7 +105,7 @@ function getCategoryListSections({
124105 }
125106
126107 if ( numberOfEnabledCategories === 0 && selectedOptions . length > 0 ) {
127- const data = getCategoryOptionTree ( selectedOptionsWithDisabledState , true ) ;
108+ const data = getCategoryOptionTree ( selectedOptionsWithDisabledState ) ;
128109 categorySections . push ( {
129110 // "Selected" section
130111 title : '' ,
@@ -143,7 +124,7 @@ function getCategoryListSections({
143124 isSelected : selectedOptions . some ( ( selectedOption ) => selectedOption . name === category . name ) ,
144125 } ) ) ;
145126
146- const data = getCategoryOptionTree ( searchCategories , true ) ;
127+ const data = getCategoryOptionTree ( searchCategories ) ;
147128 categorySections . push ( {
148129 // "Search" section
149130 title : '' ,
@@ -155,7 +136,7 @@ function getCategoryListSections({
155136 }
156137
157138 if ( selectedOptions . length > 0 ) {
158- const data = getCategoryOptionTree ( selectedOptionsWithDisabledState , true ) ;
139+ const data = getCategoryOptionTree ( selectedOptionsWithDisabledState ) ;
159140 categorySections . push ( {
160141 // "Selected" section
161142 title : '' ,
@@ -168,7 +149,7 @@ function getCategoryListSections({
168149 const filteredCategories = enabledCategories . filter ( ( category ) => ! selectedOptionNames . has ( category . name ) ) ;
169150
170151 if ( numberOfEnabledCategories < CONST . STANDARD_LIST_ITEM_LIMIT ) {
171- const data = getCategoryOptionTree ( filteredCategories , false , selectedOptionsWithDisabledState ) ;
152+ const data = getCategoryOptionTree ( filteredCategories , selectedOptionsWithDisabledState ) ;
172153 categorySections . push ( {
173154 // "All" section when items amount less than the threshold
174155 title : '' ,
@@ -192,7 +173,7 @@ function getCategoryListSections({
192173 if ( filteredRecentlyUsedCategories . length > 0 ) {
193174 const cutRecentlyUsedCategories = filteredRecentlyUsedCategories . slice ( 0 , maxRecentReportsToShow ) ;
194175
195- const data = getCategoryOptionTree ( cutRecentlyUsedCategories , true ) ;
176+ const data = getCategoryOptionTree ( cutRecentlyUsedCategories ) ;
196177 categorySections . push ( {
197178 // "Recent" section
198179 title : translate ( 'common.recent' ) ,
@@ -201,7 +182,7 @@ function getCategoryListSections({
201182 } ) ;
202183 }
203184
204- const data = getCategoryOptionTree ( filteredCategories , false , selectedOptionsWithDisabledState ) ;
185+ const data = getCategoryOptionTree ( filteredCategories , selectedOptionsWithDisabledState ) ;
205186 categorySections . push ( {
206187 // "All" section when items amount more than the threshold
207188 title : translate ( 'common.all' ) ,
0 commit comments