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 14 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
6 changes: 6 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4713,6 +4713,12 @@ const CONST = {

MAX_TAX_RATE_INTEGER_PLACES: 4,
MAX_TAX_RATE_DECIMAL_PLACES: 4,

SEARCH_TRANSACTION_TYPE: {
CASH: 'cash',
CARD: 'card',
DISTANCE: 'distance',
},
} as const;

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand Down
109 changes: 102 additions & 7 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
import React, {useEffect} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as SearchActions from '@libs/actions/Search';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as SearchUtils from '@libs/SearchUtils';
import Navigation from '@navigation/Navigation';
import EmptySearchView from '@pages/Search/EmptySearchView';
import useCustomBackHandler from '@pages/Search/useCustomBackHandler';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import SelectionList from './SelectionList';
import TableListItemSkeleton from './Skeletons/TableListItemSkeleton';
import Text from './Text';

const mockData = [
{
receipt: {source: 'http...'},
hasEReceipt: false,
created: '2024-04-11 00:00:00',
amount: 12500,
type: 'cash',
reportID: '3632789879960357',
transactionThreadReportID: '2',
transactionID: '1234',
modifiedCreated: '2024-05-06 00:00:00',
description: 'description description description description',
accountID: '8392101',
managerID: '8392101',
currency: 'USD',
modifiedCurrency: '',
category: 'Bananas',
tag: 'Green',
},
{
receipt: {source: 'http...'},
hasEReceipt: false,
created: '2024-04-11 00:00:00',
amount: 12500,
type: 'card', // not present in live data (data outside of snapshot_)
reportID: '5768873634031661',
transactionThreadReportID: '2',
transactionID: '5555',
modifiedCreated: '2024-05-06 00:00:00',
description: 'description',
accountID: '8392101',
managerID: '8392101',
currency: 'USD',
modifiedCurrency: '',
category: 'Bananas',
tag: 'Green',
},
];

type SearchProps = {
query: string;
};

function Search({query}: SearchProps) {
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();
// const [selectedCategories, setSelectedCategories] = useState<Record<string, boolean>>({});
useCustomBackHandler();

const hash = SearchUtils.getQueryHash(query);
const [searchResults, searchResultsMeta] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`);

Expand All @@ -23,7 +78,8 @@ function Search({query}: SearchProps) {
}, [query]);

const isLoading = !isOffline && isLoadingOnyxValue(searchResultsMeta);
const shouldShowEmptyState = isEmptyObject(searchResults);
// Todo remove using mock data once api is done
const shouldShowEmptyState = !isEmptyObject(searchResults) || !mockData;

if (isLoading) {
return <TableListItemSkeleton shouldAnimate />;
Expand All @@ -33,15 +89,54 @@ function Search({query}: SearchProps) {
return <EmptySearchView />;
}

const getListHeader = () => {
if (isSmallScreenWidth) {
return;
}

// const showMerchantColumn = ReportUtils.shouldShowMerchantColumn(data);
const showMerchantColumn = isSmallScreenWidth && true;

return (
<View style={[styles.flex1, styles.flexRow, styles.justifyContentBetween, styles.pl3, styles.gap3]}>
{/* <Text style={styles.searchInputStyle}>{translate('common.receipt')}</Text> */}
<Text style={[styles.searchInputStyle, styles.flex1]}>{translate('common.date')}</Text>
{showMerchantColumn && <Text style={[styles.searchInputStyle]}>{translate('common.merchant')}</Text>}
<Text style={[styles.searchInputStyle, styles.flex1]}>{translate('common.description')}</Text>
<Text style={[styles.searchInputStyle, styles.flex1]}>{translate('common.from')}</Text>
<Text style={[styles.searchInputStyle, styles.flex1]}>{translate('common.to')}</Text>
<Text style={[styles.searchInputStyle, styles.flex1]}>{translate('common.category')}</Text>
<Text style={[styles.searchInputStyle, styles.flex1]}>{translate('common.tag')}</Text>
<Text style={[styles.searchInputStyle, styles.flex1, styles.textAlignRight]}>{translate('common.total')}</Text>
<Text style={[styles.searchInputStyle, styles.flex1]}>{translate('common.type')}</Text>
<Text style={[styles.searchInputStyle, styles.flex1]}>{translate('common.action')}</Text>
</View>
);
};

const openReport = (reportID?: string) => {
if (reportID) {
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute(query, reportID));
}
};

const ListItem = SearchUtils.getListItem();

// This will be updated with the proper List component in another PR
return SearchUtils.getSections(searchResults.data).map((item) => (
<ListItem
key={item.transactionID}
item={item}
return (
<SelectionList
canSelectMultiple
customListHeader={getListHeader()}
ListItem={ListItem}
sections={[{data: mockData, isDisabled: false}]}
onSelectRow={(item) => {
openReport(item.reportID);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
openReport(item.reportID);
openReport(item.transactionThreadReportID);

}}
onSelectAll={!isSmallScreenWidth ? () => {} : undefined}
onCheckboxPress={() => {}}
shouldPreventDefaultFocusOnSelectRow={!DeviceCapabilities.canUseTouchScreen()}
listHeaderWrapperStyle={[styles.ph9, styles.pv3, styles.pb5]}
/>
));
);
}

Search.displayName = 'Search';
Expand Down
18 changes: 0 additions & 18 deletions src/components/SelectionList/TemporaryTransactionListItem.tsx

This file was deleted.

Loading
Loading