Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA][Search v1] TransactionListItem and SearchTableHeader #41102

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d25bcdf
Add template of SearchTableHeader
WojtekBoman Apr 23, 2024
c423cb8
Add template of ExpenseListItem
WojtekBoman Apr 24, 2024
6235eb1
Merge branch 'main' into search-v1/search-table-header
WojtekBoman Apr 26, 2024
a948542
Merge branch 'search-v1/search-table-header' into search-v1/search-list
WojtekBoman Apr 26, 2024
ff30cb5
Add test data to SearchPage
WojtekBoman Apr 26, 2024
13273b6
Rename ExpenseListItem to TransactionListItem
WojtekBoman Apr 26, 2024
0ec7b8a
Modify TransactionListItem
WojtekBoman Apr 26, 2024
c598002
Merge branch 'main' into search-v1/search-list
WojtekBoman Apr 29, 2024
dcad06e
Refactor SearchUtils
WojtekBoman Apr 29, 2024
c2c2203
add styles for narrow screens for TransactionListItem
Kicu Apr 29, 2024
26a354f
Add SearchTransactionType
WojtekBoman Apr 29, 2024
1969563
handle clicking on TransactionListItem
Kicu Apr 29, 2024
19c976e
Add flex1 to views with text
WojtekBoman Apr 29, 2024
cda5777
improve TransactionListItem on narrow screens
Kicu Apr 29, 2024
6ff87da
add small fixes to TransactionListItem after review
Kicu Apr 30, 2024
c7925fb
Merge branch 'main' into search-v1/search-list
Kicu Apr 30, 2024
71d1b58
add using actual api results
Kicu Apr 30, 2024
29d2fa5
Handle opening search page with invalid queries
WojtekBoman Apr 30, 2024
596c997
improve TransactionListItem layout on narrow screens
Kicu Apr 30, 2024
aa625fa
add more small fixes to TransactionListItem
Kicu Apr 30, 2024
7995911
Add fixes to Search
WojtekBoman Apr 30, 2024
241b602
Fix lint
WojtekBoman Apr 30, 2024
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
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ const ONYXKEYS = {

/** This is deprecated, but needed for a migration, so we still need to include it here so that it will be initialized in Onyx.init */
DEPRECATED_POLICY_MEMBER_LIST: 'policyMemberList_',

// Search Page related
SEARCH: 'search_'
},

/** List of Form ids */
Expand Down Expand Up @@ -563,6 +566,7 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.NEXT_STEP]: OnyxTypes.ReportNextStep;
[ONYXKEYS.COLLECTION.POLICY_JOIN_MEMBER]: OnyxTypes.PolicyJoinMember;
[ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS]: OnyxTypes.PolicyConnectionSyncProgress;
[ONYXKEYS.COLLECTION.SEARCH]: OnyxTypes.SearchResults;
};

type OnyxValuesMapping = {
Expand Down
124 changes: 67 additions & 57 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,78 @@
import React from 'react';
import type {GestureResponderEvent, StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import {PressableWithFeedback} from './Pressable';
import Text from './Text';
import Tooltip from './Tooltip';
import React, {useEffect} from 'react';
import {useOnyx} from 'react-native-onyx';
import useNetwork from '@hooks/useNetwork';
import * as SearchActions from '@libs/actions/Search';
import * as SearchUtils from '@libs/SearchUtils';
import EmptySearchView from '@pages/Search/EmptySearchView';
import ONYXKEYS from '@src/ONYXKEYS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import TableListItemSkeleton from './Skeletons/TableListItemSkeleton';

// For testing purposes run this code in browser console to insert fake data:
// query is the param from URL, by default it will be "all"
// Onyx.set(`search_${query}`, {
// search: {
// offset: 0,
// type: 'transaction',
// hasMoreResults: false,
// },
// data: {
// transactions_1234: {
// receipt: {source: 'http...'},
// hasEReceipt: false,
// created: '2024-04-11 00:00:00',
// amount: 12500,
// type: 'cash',
// reportID: '1',
// transactionThreadReportID: '2',
// transactionID: '1234',
// },
// transactions_5555: {
// receipt: {source: 'http...'},
// hasEReceipt: false,
// created: '2024-04-11 00:00:00',
// amount: 12500,
// type: 'cash', // not present in live data (data outside of snapshot_)
// reportID: '1',
// transactionThreadReportID: '2',
// transactionID: '5555',
// },
// },
// })

type SearchProps = {
// Callback fired when component is pressed
onPress: (event?: GestureResponderEvent | KeyboardEvent) => void;
query: string;
};

// Text explaining what the user can search for
placeholder?: string;
function Search({query}: SearchProps) {
const {isOffline} = useNetwork();
const [searchResults, searchResultsMeta] = useOnyx(`${ONYXKEYS.COLLECTION.SEARCH}${query}`);

// Text showing up in a tooltip when component is hovered
tooltip?: string;
useEffect(() => {
SearchActions.search(query);
}, [query]);

// Styles to apply on the outer element
style?: StyleProp<ViewStyle>;
const isLoading = !isOffline && isLoadingOnyxValue(searchResultsMeta);
const shouldShowEmptyState = isEmptyObject(searchResults);

/** Styles to apply to the outermost element */
containerStyle?: StyleProp<ViewStyle>;
};
if (isLoading) {
return <TableListItemSkeleton shouldAnimate />;
}

if (shouldShowEmptyState) {
return <EmptySearchView />;
}

function Search({onPress, placeholder, tooltip, style, containerStyle}: SearchProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const ListItem = SearchUtils.getListItem();

return (
<View style={containerStyle}>
<Tooltip text={tooltip ?? translate('common.search')}>
<PressableWithFeedback
accessibilityLabel={tooltip ?? translate('common.search')}
role={CONST.ROLE.BUTTON}
onPress={onPress}
style={styles.searchPressable}
>
{({hovered}) => (
<View style={[styles.searchContainer, hovered && styles.searchContainerHovered, style]}>
<Icon
src={Expensicons.MagnifyingGlass}
width={variables.iconSizeSmall}
height={variables.iconSizeSmall}
fill={theme.icon}
/>
<Text
style={styles.searchInputStyle}
numberOfLines={1}
>
{placeholder ?? translate('common.searchWithThreeDots')}
</Text>
</View>
)}
</PressableWithFeedback>
</Tooltip>
</View>
);
// This will be updated with the proper List component in another PR
return SearchUtils.getTransactionsSections(searchResults.data).map((item) => (
<ListItem
key={item.transactionID}
item={item}
/>
));
}

Search.displayName = 'Search';
Expand Down
203 changes: 203 additions & 0 deletions src/components/SelectionList/TransactionListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import {format} from 'date-fns';
import React, {useCallback} from 'react';
import {View} from 'react-native';
import Avatar from '@components/Avatar';
import Button from '@components/Button';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import MultipleAvatars from '@components/MultipleAvatars';
import {usePersonalDetails} from '@components/OnyxProvider';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Text from '@components/Text';
import TextWithTooltip from '@components/TextWithTooltip';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import CONST from '@src/CONST';
import BaseListItem from './BaseListItem';
import type {ListItem, TransactionListItemProps} from './types';

function TransactionListItem<TItem extends ListItem>({
item,
isFocused,
showTooltip,
isDisabled,
canSelectMultiple,
onSelectRow,
onCheckboxPress,
onDismissError,
shouldPreventDefaultFocusOnSelectRow,
rightHandSideComponent,
onFocus,
shouldSyncFocus,
}: TransactionListItemProps<TItem>) {
const styles = useThemeStyles();
const theme = useTheme();
const StyleUtils = useStyleUtils();
const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT;
const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor;
const hoveredBackgroundColor = styles.sidebarLinkHover?.backgroundColor ? styles.sidebarLinkHover.backgroundColor : theme.sidebar;

const handleCheckboxPress = useCallback(() => {
if (onCheckboxPress) {
onCheckboxPress(item);
} else {
onSelectRow(item);
}
}, [item, onCheckboxPress, onSelectRow]);

console.log('personalDetails', personalDetails);

return (
<BaseListItem
item={item}
pressableStyle={[[styles.selectionListPressableItemWrapper, item.isSelected && styles.activeComponentBG, isFocused && styles.sidebarLinkActive]]}
wrapperStyle={[styles.flexRow, styles.flex1, styles.justifyContentBetween, styles.userSelectNone, styles.alignItemsCenter]}
containerStyle={[styles.mb3]}
isFocused={isFocused}
isDisabled={isDisabled}
showTooltip={showTooltip}
canSelectMultiple={canSelectMultiple}
onSelectRow={onSelectRow}
onDismissError={onDismissError}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
rightHandSideComponent={rightHandSideComponent}
errors={item.errors}
pendingAction={item.pendingAction}
keyForList={item.keyForList}
onFocus={onFocus}
shouldSyncFocus={shouldSyncFocus}
hoverStyle={item.isSelected && styles.activeComponentBG}
>
{(hovered) => (
<>
{canSelectMultiple && (
<PressableWithFeedback
accessibilityLabel={item.text ?? ''}
role={CONST.ROLE.BUTTON}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
disabled={isDisabled || item.isDisabledCheckbox}
onPress={handleCheckboxPress}
style={[styles.cursorUnset, StyleUtils.getCheckboxPressableStyle(), item.isDisabledCheckbox && styles.cursorDisabled, styles.mr3]}
>
<View style={[StyleUtils.getCheckboxContainerStyle(20), StyleUtils.getMultiselectListStyles(!!item.isSelected, !!item.isDisabled)]}>
{item.isSelected && (
<Icon
src={Expensicons.Checkmark}
fill={theme.textLight}
height={14}
width={14}
/>
)}
</View>
</PressableWithFeedback>
)}
{!!item.icons && (
<MultipleAvatars
icons={item.icons ?? []}
shouldShowTooltip={showTooltip}
secondAvatarStyle={[
StyleUtils.getBackgroundAndBorderStyle(theme.sidebar),
isFocused ? StyleUtils.getBackgroundAndBorderStyle(focusedBackgroundColor) : undefined,
hovered && !isFocused ? StyleUtils.getBackgroundAndBorderStyle(hoveredBackgroundColor) : undefined,
]}
/>
)}
<View style={[styles.flexRow, styles.flex1, styles.gap3]}>
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch]}>
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={format(new Date(item.created), 'MMM dd')}
style={[styles.optionDisplayName, styles.textNormalThemeText, styles.pre, styles.justifyContentCenter]}
/>
</View>
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch]}>
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={item.description}
style={[styles.optionDisplayName, styles.textNormalThemeText, styles.pre, styles.justifyContentCenter]}
/>
</View>
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch]}>
<View style={[styles.flexRow, styles.gap3, styles.flex1, styles.alignItemsCenter]}>
<Avatar
imageStyles={[styles.alignSelfCenter]}
size={CONST.AVATAR_SIZE.SMALL}
source={personalDetails[item.managerID]?.avatar}
name={personalDetails[item.managerID]?.displayName}
type={CONST.ICON_TYPE_WORKSPACE}
/>
<Text
numberOfLines={1}
style={[styles.flex1, styles.flexGrow1, styles.textStrong]}
>
{personalDetails[item.managerID]?.displayName}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From should be item.accountID

Suggested change
{personalDetails[item.managerID]?.displayName}
{personalDetails[item.accountID]?.displayName}

</Text>
</View>
</View>
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch]}>
<View style={[styles.flexRow, styles.gap3, styles.flex1, styles.alignItemsCenter]}>
<Avatar
imageStyles={[styles.alignSelfCenter]}
size={CONST.AVATAR_SIZE.SMALL}
source={personalDetails[item.accountID]?.avatar}
name={personalDetails[item.accountID]?.displayName}
type={CONST.ICON_TYPE_WORKSPACE}
/>
<Text
numberOfLines={1}
style={[styles.flex1, styles.flexGrow1, styles.textStrong]}
>
{personalDetails[item.accountID]?.displayName}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To is the managerID

Suggested change
{personalDetails[item.accountID]?.displayName}
{personalDetails[item.managerID]?.displayName}

</Text>
</View>
</View>
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch]}>
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={item.category}
style={[styles.optionDisplayName, styles.textNormalThemeText, styles.pre, styles.justifyContentCenter]}
/>
</View>
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch]}>
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={item.tag}
style={[styles.optionDisplayName, styles.textNormalThemeText, styles.pre, styles.justifyContentCenter]}
/>
</View>
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsEnd]}>
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={`${CurrencyUtils.getLocalizedCurrencySymbol(item.currency)}${item.amount}`}
style={[styles.optionDisplayName, styles.textNewKansasNormal, styles.pre, styles.justifyContentCenter]}
/>
</View>
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch]}>
<Icon
src={Expensicons.CreditCard}
fill={theme.icon}
/>
</View>

<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch]}>
<Button
success
onPress={() => {}}
small
pressOnEnter
text="View"
/>
</View>
</View>
{!!item.rightElement && item.rightElement}
</>
)}
</BaseListItem>
);
}

TransactionListItem.displayName = 'TransactionListItem';

export default TransactionListItem;
6 changes: 5 additions & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import type {ReceiptErrors} from '@src/types/onyx/Transaction';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import type IconAsset from '@src/types/utils/IconAsset';
import type TransactionListItem from './TransactionListItem';
import type InviteMemberListItem from './InviteMemberListItem';
import type RadioListItem from './RadioListItem';
import type TableListItem from './TableListItem';
Expand Down Expand Up @@ -180,7 +181,9 @@ type RadioListItemProps<TItem extends ListItem> = ListItemProps<TItem>;

type TableListItemProps<TItem extends ListItem> = ListItemProps<TItem>;

type ValidListItem = typeof RadioListItem | typeof UserListItem | typeof TableListItem | typeof InviteMemberListItem;
type TransactionListItemProps<TItem extends ListItem> = ListItemProps<TItem>;

type ValidListItem = typeof RadioListItem | typeof UserListItem | typeof TableListItem | typeof InviteMemberListItem | typeof TransactionListItem;

type Section<TItem extends ListItem> = {
/** Title of the section */
Expand Down Expand Up @@ -373,6 +376,7 @@ export type {
RadioListItemProps,
TableListItemProps,
InviteMemberListItemProps,
TransactionListItemProps,
ListItem,
ListItemProps,
FlattenedSectionsReturn,
Expand Down
Loading
Loading