From 01fc28f675f041775a5215b41a2f1d27128df2c4 Mon Sep 17 00:00:00 2001 From: GCyganek Date: Fri, 10 Oct 2025 14:02:34 +0200 Subject: [PATCH 1/3] Make WorkspaceCategoriesSettingsPage use new SelectionList --- .../SpendCategorySelectorListItem.tsx | 6 +-- .../SelectionList/ListItem/types.ts | 10 +++- .../SelectionListWithSections/types.ts | 4 +- .../WorkspaceCategoriesSettingsPage.tsx | 50 ++++++++----------- 4 files changed, 35 insertions(+), 35 deletions(-) rename src/{pages/workspace/categories => components/SelectionList/ListItem}/SpendCategorySelectorListItem.tsx (83%) diff --git a/src/pages/workspace/categories/SpendCategorySelectorListItem.tsx b/src/components/SelectionList/ListItem/SpendCategorySelectorListItem.tsx similarity index 83% rename from src/pages/workspace/categories/SpendCategorySelectorListItem.tsx rename to src/components/SelectionList/ListItem/SpendCategorySelectorListItem.tsx index d30be7adfe2b..41c2610d744a 100644 --- a/src/pages/workspace/categories/SpendCategorySelectorListItem.tsx +++ b/src/components/SelectionList/ListItem/SpendCategorySelectorListItem.tsx @@ -1,10 +1,10 @@ import React from 'react'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; -import BaseListItem from '@components/SelectionListWithSections/BaseListItem'; -import type {BaseListItemProps, ListItem} from '@components/SelectionListWithSections/types'; import useThemeStyles from '@hooks/useThemeStyles'; +import BaseListItem from './BaseListItem'; +import type {ListItem, SpendCategorySelectorListItemProps} from './types'; -function SpendCategorySelectorListItem({item, onSelectRow, isFocused}: BaseListItemProps) { +function SpendCategorySelectorListItem({item, onSelectRow, isFocused}: SpendCategorySelectorListItemProps) { const styles = useThemeStyles(); const {groupID, categoryID} = item; diff --git a/src/components/SelectionList/ListItem/types.ts b/src/components/SelectionList/ListItem/types.ts index b11dfc1c6028..2f7d1e9b995f 100644 --- a/src/components/SelectionList/ListItem/types.ts +++ b/src/components/SelectionList/ListItem/types.ts @@ -6,7 +6,12 @@ import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import type CursorStyles from '@styles/utils/cursor/types'; import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; import type {ReceiptErrors} from '@src/types/onyx/Transaction'; +import type BaseListItem from './BaseListItem'; +import type ListItemRenderer from './ListItemRenderer'; +import type MultiSelectListItem from './MultiSelectListItem'; import type RadioListItem from './RadioListItem'; +import type SingleSelectListItem from './SingleSelectListItem'; +import type SpendCategorySelectorListItem from './SpendCategorySelectorListItem'; type ListItem = { /** Text to display */ @@ -229,7 +234,7 @@ type ListItemProps = CommonListItemProps & { shouldUseDefaultRightHandSideCheckmark?: boolean; }; -type ValidListItem = typeof RadioListItem; +type ValidListItem = typeof RadioListItem | typeof BaseListItem | typeof ListItemRenderer | typeof MultiSelectListItem | typeof SingleSelectListItem | typeof SpendCategorySelectorListItem; type BaseListItemProps = CommonListItemProps & { item: TItem; @@ -256,6 +261,8 @@ type SingleSelectListItemProps = ListItemProps; type MultiSelectListItemProps = ListItemProps; +type SpendCategorySelectorListItemProps = ListItemProps; + export type { BaseListItemProps, ExtendedTargetedEvent, @@ -266,4 +273,5 @@ export type { ValidListItem, SingleSelectListItemProps, MultiSelectListItemProps, + SpendCategorySelectorListItemProps, }; diff --git a/src/components/SelectionListWithSections/types.ts b/src/components/SelectionListWithSections/types.ts index 8413f2f2df03..39a89f57cbe8 100644 --- a/src/components/SelectionListWithSections/types.ts +++ b/src/components/SelectionListWithSections/types.ts @@ -21,7 +21,6 @@ import type {SearchColumnType, SearchGroupBy, SearchQueryJSON} from '@components import type {ForwardedFSClassProps} from '@libs/Fullstory/types'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import type UnreportedExpenseListItem from '@pages/UnreportedExpenseListItem'; -import type SpendCategorySelectorListItem from '@pages/workspace/categories/SpendCategorySelectorListItem'; // eslint-disable-next-line no-restricted-imports import type CursorStyles from '@styles/utils/cursor/types'; import type CONST from '@src/CONST'; @@ -556,8 +555,7 @@ type ValidListItem = | typeof SearchQueryListItem | typeof SearchRouterItem | typeof TravelDomainListItem - | typeof UnreportedExpenseListItem - | typeof SpendCategorySelectorListItem; + | typeof UnreportedExpenseListItem; type Section = { /** Title of the section */ diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 78377fcb3754..453ac475acc7 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -4,8 +4,10 @@ import CategorySelectorModal from '@components/CategorySelector/CategorySelector import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; -import SelectionList from '@components/SelectionListWithSections'; -import type {ListItem} from '@components/SelectionListWithSections/types'; +import SelectionList from '@components/SelectionList'; +import SpendCategorySelectorListItem from '@components/SelectionList/ListItem/SpendCategorySelectorListItem'; +import type {ListItem} from '@components/SelectionList/ListItem/types'; +import type {ListItem as SelectionListWithSectionsListItem} from '@components/SelectionListWithSections/types'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -25,7 +27,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; -import SpendCategorySelectorListItem from './SpendCategorySelectorListItem'; type WorkspaceCategoriesSettingsPageProps = WithPolicyConnectionsProps & ( @@ -55,38 +56,31 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet setWorkspaceRequiresCategory(policyID, value, policyTagLists, policyCategories, allTransactionViolations); }; - const {sections} = useMemo(() => { + const data = useMemo(() => { if (!(currentPolicy && currentPolicy.mccGroup)) { - return {sections: [{data: []}]}; + return []; } - return { - sections: [ - { - data: Object.entries(currentPolicy.mccGroup).map( - ([mccKey, mccGroup]) => - ({ - categoryID: mccGroup.category, - keyForList: mccKey, - groupID: mccKey, - tabIndex: -1, - pendingAction: mccGroup?.pendingAction, - }) as ListItem, - ), - }, - ], - }; + return Object.entries(currentPolicy.mccGroup).map( + ([mccKey, mccGroup]): ListItem => ({ + categoryID: mccGroup.category, + keyForList: mccKey, + groupID: mccKey, + tabIndex: -1, + pendingAction: mccGroup?.pendingAction, + }), + ); }, [currentPolicy]); const hasEnabledCategories = hasEnabledOptions(policyCategories ?? {}); const isToggleDisabled = !policy?.areCategoriesEnabled || !hasEnabledCategories || isConnectedToAccounting; - const setNewCategory = (selectedCategory: ListItem) => { - if (!selectedCategory.keyForList || !groupID) { + const setNewCategory = (selectedCategory: SelectionListWithSectionsListItem, currentGroupID: string) => { + if (!selectedCategory.keyForList) { return; } if (categoryID !== selectedCategory.keyForList) { - setWorkspaceDefaultSpendCategory(policyID, groupID, selectedCategory.keyForList); + setWorkspaceDefaultSpendCategory(policyID, currentGroupID, selectedCategory.keyForList); } Keyboard.dismiss(); @@ -127,16 +121,16 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet /> - {!!currentPolicy && (sections.at(0)?.data?.length ?? 0) > 0 && ( + {!!currentPolicy && data.length > 0 && ( {translate('workspace.categories.defaultSpendCategories')} {translate('workspace.categories.spendCategoriesDescription')} } - sections={sections} + data={data} ListItem={SpendCategorySelectorListItem} onSelectRow={(item) => { if (!item.groupID || !item.categoryID) { @@ -156,7 +150,7 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet isVisible={isSelectorModalVisible} currentCategory={categoryID} onClose={() => setIsSelectorModalVisible(false)} - onCategorySelected={setNewCategory} + onCategorySelected={(selectedCategory) => setNewCategory(selectedCategory, groupID)} label={groupID[0].toUpperCase() + groupID.slice(1)} /> )} From adcd8c87fbbf6dd256d447134610d4dec9939157 Mon Sep 17 00:00:00 2001 From: GCyganek Date: Fri, 10 Oct 2025 14:35:42 +0200 Subject: [PATCH 2/3] Fix type --- src/components/SelectionList/ListItem/types.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/SelectionList/ListItem/types.ts b/src/components/SelectionList/ListItem/types.ts index 2f7d1e9b995f..125591b72c7b 100644 --- a/src/components/SelectionList/ListItem/types.ts +++ b/src/components/SelectionList/ListItem/types.ts @@ -7,7 +7,6 @@ import type CursorStyles from '@styles/utils/cursor/types'; import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; import type {ReceiptErrors} from '@src/types/onyx/Transaction'; import type BaseListItem from './BaseListItem'; -import type ListItemRenderer from './ListItemRenderer'; import type MultiSelectListItem from './MultiSelectListItem'; import type RadioListItem from './RadioListItem'; import type SingleSelectListItem from './SingleSelectListItem'; @@ -234,7 +233,7 @@ type ListItemProps = CommonListItemProps & { shouldUseDefaultRightHandSideCheckmark?: boolean; }; -type ValidListItem = typeof RadioListItem | typeof BaseListItem | typeof ListItemRenderer | typeof MultiSelectListItem | typeof SingleSelectListItem | typeof SpendCategorySelectorListItem; +type ValidListItem = typeof RadioListItem | typeof BaseListItem | typeof MultiSelectListItem | typeof SingleSelectListItem | typeof SpendCategorySelectorListItem; type BaseListItemProps = CommonListItemProps & { item: TItem; From f7e666dd789ee6a594d7a2388868efdab0756466 Mon Sep 17 00:00:00 2001 From: GCyganek Date: Sun, 12 Oct 2025 09:14:49 +0200 Subject: [PATCH 3/3] Move selection list header content and onSelectItem above header --- .../WorkspaceCategoriesSettingsPage.tsx | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 453ac475acc7..5ce8af365dfe 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -90,6 +90,23 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet }); }; + const onSelectItem = (item: ListItem) => { + if (!item.groupID || !item.categoryID) { + return; + } + + setIsSelectorModalVisible(true); + setCategoryID(item.categoryID); + setGroupID(item.groupID); + }; + + const selectionListHeaderContent = ( + + {translate('workspace.categories.defaultSpendCategories')} + {translate('workspace.categories.spendCategoriesDescription')} + + ); + return ( 0 && ( - {translate('workspace.categories.defaultSpendCategories')} - {translate('workspace.categories.spendCategoriesDescription')} - - } + customListHeaderContent={selectionListHeaderContent} data={data} ListItem={SpendCategorySelectorListItem} - onSelectRow={(item) => { - if (!item.groupID || !item.categoryID) { - return; - } - setIsSelectorModalVisible(true); - setCategoryID(item.categoryID); - setGroupID(item.groupID); - }} + onSelectRow={onSelectItem} /> )}