Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Str} from 'expensify-common';
import type {ForwardedRef} from 'react';
import React, {forwardRef, useCallback, useEffect, useMemo, useState} from 'react';
import type {OnyxCollection} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import * as Expensicons from '@components/Icon/Expensicons';
import {usePersonalDetails} from '@components/OnyxProvider';
import {useOptionsList} from '@components/OptionListContextProvider';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import SelectionList from '@components/SelectionList';
Expand All @@ -18,7 +17,7 @@ import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {getCardFeedsForDisplay} from '@libs/CardFeedUtils';
import {getCardDescription, isCard, isCardHiddenFromSearch, mergeCardListWithWorkspaceFeeds} from '@libs/CardUtils';
import {getCardDescription, isCard, isCardHiddenFromSearch} from '@libs/CardUtils';
import Log from '@libs/Log';
import memoize from '@libs/memoize';
import type {Options, SearchOption} from '@libs/OptionsListUtils';
Expand All @@ -40,7 +39,7 @@ import StringUtils from '@libs/StringUtils';
import Timing from '@userActions/Timing';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Report} from '@src/types/onyx';
import type {CardFeeds, CardList, PersonalDetailsList, Policy, Report} from '@src/types/onyx';
import type PersonalDetails from '@src/types/onyx/PersonalDetails';
import {getEmptyObject} from '@src/types/utils/EmptyObject';
import {getSubstitutionMapKey} from './SearchRouter/getQueryWithSubstitutions';
Expand Down Expand Up @@ -85,6 +84,18 @@ type SearchAutocompleteListProps = {

/** Ref for textInput */
textInputRef?: React.RefObject<AnimatedTextInputRef | null>;

/** Personal details */
personalDetails: OnyxEntry<PersonalDetailsList>;

/** Reports */
reports: OnyxCollection<Report>;

/** All feeds */
allFeeds: Record<string, CardFeeds | undefined> | undefined;

/** All cards */
allCards: CardList;
};

const defaultListOptions = {
Expand Down Expand Up @@ -147,6 +158,10 @@ function SearchAutocompleteList(
shouldSubscribeToArrowKeyEvents = true,
onHighlightFirstItem,
textInputRef,
personalDetails,
reports,
allFeeds,
allCards,
}: SearchAutocompleteListProps,
ref: ForwardedRef<SelectionListHandle>,
) {
Expand All @@ -156,8 +171,6 @@ function SearchAutocompleteList(

const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const [recentSearches] = useOnyx(ONYXKEYS.RECENT_SEARCHES, {canBeMissing: true});
const personalDetails = usePersonalDetails();
const [reports = getEmptyObject<NonNullable<OnyxCollection<Report>>>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
const taxRates = getAllTaxRates();

const {options, areOptionsInitialized} = useOptionsList();
Expand Down Expand Up @@ -197,11 +210,7 @@ function SearchAutocompleteList(
const expenseTypes = Object.values(CONST.SEARCH.TRANSACTION_TYPE);
const booleanTypes = Object.values(CONST.SEARCH.BOOLEAN);

const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true});
const allCards = useMemo(() => mergeCardListWithWorkspaceFeeds(workspaceCardFeeds ?? CONST.EMPTY_OBJECT, userCardList), [userCardList, workspaceCardFeeds]);
const [allFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
Comment thread
OlimpiaZurek marked this conversation as resolved.
const cardAutocompleteList = Object.values(allCards);
const cardAutocompleteList = useMemo(() => Object.values(allCards), [allCards]);
const feedAutoCompleteList = useMemo(() => {
// We don't want to show the "Expensify Card" feed in the autocomplete suggestion list
// Thus passing an empty object to the `allCards` parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
setTextQuery={setTextAndUpdateSelection}
updateAutocompleteSubstitutions={updateAutocompleteSubstitutions}
ref={listRef}
personalDetails={personalDetails}
reports={reports}
allCards={allCards}
allFeeds={allFeeds}
/>
</View>
)}
Expand Down Expand Up @@ -454,6 +458,10 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
updateAutocompleteSubstitutions={updateAutocompleteSubstitutions}
ref={listRef}
shouldSubscribeToArrowKeyEvents={isAutocompleteListVisible}
personalDetails={personalDetails}
reports={reports}
allCards={allCards}
allFeeds={allFeeds}
/>
</View>
</View>
Expand Down
15 changes: 13 additions & 2 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {findFocusedRoute, useNavigationState} from '@react-navigation/native';
import {deepEqual} from 'fast-equals';
import React, {forwardRef, useCallback, useEffect, useRef, useState} from 'react';
import React, {forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {TextInputProps} from 'react-native';
import {InteractionManager, Keyboard, View} from 'react-native';
import type {ValueOf} from 'type-fest';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
import {usePersonalDetails} from '@components/OnyxProvider';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import type {GetAdditionalSectionsCallback} from '@components/Search/SearchAutocompleteList';
import SearchAutocompleteList from '@components/Search/SearchAutocompleteList';
Expand All @@ -20,6 +21,7 @@ import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {mergeCardListWithWorkspaceFeeds} from '@libs/CardUtils';
import {scrollToRight} from '@libs/InputUtils';
import Log from '@libs/Log';
import backHistory from '@libs/Navigation/helpers/backHistory';
Expand Down Expand Up @@ -82,7 +84,12 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
const styles = useThemeStyles();
const [, recentSearchesMetadata] = useOnyx(ONYXKEYS.RECENT_SEARCHES, {canBeMissing: true});
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});

const personalDetails = usePersonalDetails();
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true});
const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
const allCards = useMemo(() => mergeCardListWithWorkspaceFeeds(workspaceCardFeeds ?? CONST.EMPTY_OBJECT, userCardList), [userCardList, workspaceCardFeeds]);
const [allFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
const {shouldUseNarrowLayout} = useResponsiveLayout();
const listRef = useRef<SelectionListHandle>(null);

Expand Down Expand Up @@ -480,6 +487,10 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
onHighlightFirstItem={() => listRef.current?.updateAndScrollToFocusedIndex(1)}
ref={listRef}
textInputRef={textInputRef}
personalDetails={personalDetails}
reports={reports}
allFeeds={allFeeds}
allCards={allCards}
/>
</>
)}
Expand Down
5 changes: 1 addition & 4 deletions src/components/SelectionList/ChatListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useOnyx from '@hooks/useOnyx';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {isInvoiceRoom, isPolicyExpenseChat} from '@libs/ReportUtils';
Expand All @@ -27,9 +26,7 @@ function ChatListItem<TItem extends ListItem>({
}: ChatListItemProps<TItem>) {
const reportActionItem = item as unknown as ReportActionListItemType;
const reportID = Number(reportActionItem?.reportID ?? CONST.DEFAULT_NUMBER_ID);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
Comment thread
OlimpiaZurek marked this conversation as resolved.
canBeMissing: true,
});
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const styles = useThemeStyles();
const theme = useTheme();
const animatedHighlightStyle = useAnimatedHighlightStyle({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import type {OnyxCollection} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {SearchGroupBy} from '@components/Search/types';
import BaseListItem from '@components/SelectionList/BaseListItem';
Expand All @@ -17,7 +16,6 @@ import Text from '@components/Text';
import TransactionItemRow from '@components/TransactionItemRow';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand All @@ -28,8 +26,6 @@ import {setActiveTransactionThreadIDs} from '@userActions/TransactionThreadNavig
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy} from '@src/types/onyx';
import {getEmptyObject} from '@src/types/utils/EmptyObject';
import CardListItemHeader from './CardListItemHeader';
import MemberListItemHeader from './MemberListItemHeader';
import ReportListItemHeader from './ReportListItemHeader';
Expand All @@ -46,12 +42,12 @@ function TransactionGroupListItem<TItem extends ListItem>({
onLongPressRow,
shouldSyncFocus,
groupBy,
policies,
}: TransactionGroupListItemProps<TItem>) {
const groupItem = item as unknown as TransactionGroupListItemType;
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: true});
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${groupItem?.policyID}`];
const isEmpty = groupItem.transactions.length === 0;
const isDisabledOrEmpty = isEmpty || isDisabled;
Expand Down
4 changes: 4 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ type TaskListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {

type TransactionGroupListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
groupBy?: SearchGroupBy;
policies?: OnyxCollection<Policy>;
};

type ChatListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
Expand All @@ -473,6 +474,9 @@ type ChatListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {

/** All the data of the report collection */
allReports?: OnyxCollection<Report>;

/** The report data */
report?: Report;
};

type ValidListItem =
Expand Down
Loading