Skip to content

Commit

Permalink
add check for selected items
Browse files Browse the repository at this point in the history
  • Loading branch information
allroundexperts committed Apr 4, 2024
1 parent 928bfae commit 936b9dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
isKeyboardShown?: boolean;

/** Component to display on the right side of each child */
rightHandSideComponent?: ((item: ListItem) => ReactElement<ListItem>) | ReactElement | null;
rightHandSideComponent?: ((item: ListItem) => ReactElement<ListItem> | null) | ReactElement | null;

/** Whether to show the loading indicator for new options */
isLoadingNewOptions?: boolean;
Expand Down
24 changes: 23 additions & 1 deletion src/pages/EditReportFieldDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React, {useMemo} from 'react';
import React, {useCallback, useMemo} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/RadioListItem';
import type {ListItem} from '@components/SelectionList/types';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {RecentlyUsedReportFields} from '@src/types/onyx';
Expand Down Expand Up @@ -35,9 +39,26 @@ type EditReportFieldDropdownPageProps = EditReportFieldDropdownPageComponentProp

function EditReportFieldDropdownPage({onSubmit, fieldKey, fieldValue, fieldOptions, recentlyUsedReportFields}: EditReportFieldDropdownPageProps) {
const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');
const theme = useTheme();
const {translate} = useLocalize();
const recentlyUsedOptions = useMemo(() => recentlyUsedReportFields?.[fieldKey] ?? [], [recentlyUsedReportFields, fieldKey]);

const itemRightSideComponent = useCallback(
(item: ListItem) => {
if (item.text === fieldValue) {
return (
<Icon
src={Expensicons.Checkmark}
fill={theme.iconSuccessFill}
/>
);
}

return null;
},
[theme.iconSuccessFill, fieldValue],
);

const [sections, headerMessage] = useMemo(() => {
const validFieldOptions = fieldOptions?.filter((option) => !!option);

Expand Down Expand Up @@ -90,6 +111,7 @@ function EditReportFieldDropdownPage({onSubmit, fieldKey, fieldValue, fieldOptio
headerMessage={headerMessage}
ListItem={RadioListItem}
isRowMultilineSupported
rightHandSideComponent={itemRightSideComponent}
/>
);
}
Expand Down

0 comments on commit 936b9dc

Please sign in to comment.