@@ -25,7 +25,6 @@ import TextLink from '@components/TextLink';
2525import useAutoTurnSelectionModeOffWhenHasNoActiveOption from '@hooks/useAutoTurnSelectionModeOffWhenHasNoActiveOption' ;
2626import useCleanupSelectedOptions from '@hooks/useCleanupSelectedOptions' ;
2727import useEnvironment from '@hooks/useEnvironment' ;
28- import useFilteredSelection from '@hooks/useFilteredSelection' ;
2928import useLocalize from '@hooks/useLocalize' ;
3029import useMobileSelectionMode from '@hooks/useMobileSelectionMode' ;
3130import useNetwork from '@hooks/useNetwork' ;
@@ -52,7 +51,6 @@ import CONST from '@src/CONST';
5251import ONYXKEYS from '@src/ONYXKEYS' ;
5352import ROUTES from '@src/ROUTES' ;
5453import SCREENS from '@src/SCREENS' ;
55- import type { PolicyCategory } from '@src/types/onyx' ;
5654import type DeepValueOf from '@src/types/utils/DeepValueOf' ;
5755
5856type PolicyOption = ListItem & {
@@ -90,9 +88,8 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
9088 const isConnectionVerified = connectedIntegration && ! isConnectionUnverified ( policy , connectedIntegration ) ;
9189 const currentConnectionName = getCurrentConnectionName ( policy ) ;
9290 const isQuickSettingsFlow = route . name === SCREENS . SETTINGS_CATEGORIES . SETTINGS_CATEGORIES_ROOT ;
93- const filterCategories = useCallback ( ( category : PolicyCategory | undefined ) => ! ! category && category . pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE , [ ] ) ;
9491
95- const [ selectedCategories , setSelectedCategories ] = useFilteredSelection ( policyCategories , filterCategories ) ;
92+ const [ selectedCategories , setSelectedCategories ] = useState < string [ ] > ( [ ] ) ;
9693 const canSelectMultiple = isSmallScreenWidth ? isMobileSelectionModeEnabled : true ;
9794
9895 const fetchCategories = useCallback ( ( ) => {
@@ -107,9 +104,37 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
107104 // eslint-disable-next-line react-hooks/exhaustive-deps
108105 } , [ ] ) ;
109106
110- const cleanupSelectedOption = useCallback ( ( ) => setSelectedCategories ( [ ] ) , [ setSelectedCategories ] ) ;
107+ const cleanupSelectedOption = useCallback ( ( ) => setSelectedCategories ( [ ] ) , [ ] ) ;
111108 useCleanupSelectedOptions ( cleanupSelectedOption ) ;
112109
110+ useEffect ( ( ) => {
111+ if ( selectedCategories . length === 0 || ! canSelectMultiple ) {
112+ return ;
113+ }
114+
115+ setSelectedCategories ( ( prevSelectedCategories ) => {
116+ const newSelectedCategories = [ ] ;
117+
118+ for ( const categoryName of prevSelectedCategories ) {
119+ const categoryExists = policyCategories ?. [ categoryName ] ;
120+ if ( ! categoryExists ) {
121+ const renamedCategory = Object . entries ( policyCategories ?? { } ) . find ( ( [ , category ] ) => category . previousCategoryName === categoryName ) ;
122+ if ( renamedCategory ) {
123+ newSelectedCategories . push ( renamedCategory [ 0 ] ) ;
124+ continue ;
125+ }
126+ }
127+
128+ if ( categoryExists && categoryExists . pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ) {
129+ newSelectedCategories . push ( categoryName ) ;
130+ }
131+ }
132+
133+ return newSelectedCategories ;
134+ } ) ;
135+ // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
136+ } , [ policyCategories ] ) ;
137+
113138 useSearchBackPress ( {
114139 onClearSelection : ( ) => setSelectedCategories ( [ ] ) ,
115140 onNavigationCallBack : ( ) => Navigation . goBack ( backTo ) ,
0 commit comments