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 all 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
15 changes: 11 additions & 4 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3400,10 +3400,11 @@ const CONST = {
},
TAB_SEARCH: {
ALL: 'all',
SHARED: 'shared',
DRAFTS: 'drafts',
WAITING_ON_YOU: 'waitingOnYou',
FINISHED: 'finished',
// @TODO: Uncomment when the queries below are implemented
// SHARED: 'shared',
// DRAFTS: 'drafts',
// WAITING_ON_YOU: 'waitingOnYou',
// FINISHED: 'finished',
},
STATUS_TEXT_MAX_LENGTH: 100,

Expand Down Expand Up @@ -4734,6 +4735,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
104 changes: 95 additions & 9 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,71 @@
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';

/**
* Todo This is a temporary function that will pick search results from under `snapshot_` key
* either api needs to be updated to key by `snapshot_hash` or app code calling search data needs to be refactored
* remove this function once this is properly fixed
*/
function getCleanSearchResults(searchResults: unknown) {
if (!searchResults) {
return {};
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
// eslint-disable-next-line no-underscore-dangle,@typescript-eslint/no-unsafe-return
return searchResults?.data;
}

type SearchProps = {
query: string;
};

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

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

useEffect(() => {
if (isOffline) {
return;
}

SearchActions.search(query);
}, [query]);
}, [query, isOffline]);

const isLoading = !isOffline && isLoadingOnyxValue(searchResultsMeta);
const shouldShowEmptyState = isEmptyObject(searchResults);
const cleanResults = getCleanSearchResults(searchResults);

useEffect(() => {
SearchActions.addPersonalDetailsFromSearch(cleanResults?.personalDetailsList ?? {});
}, [cleanResults]);

const isLoading = (!isOffline && isLoadingOnyxValue(searchResultsMeta)) || cleanResults === undefined;
const shouldShowEmptyState = !isLoading && isEmptyObject(cleanResults);

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

const displayNarrowVersion = isMediumScreenWidth || isSmallScreenWidth;

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

// const showMerchantColumn = ReportUtils.shouldShowMerchantColumn(data);
const showMerchantColumn = displayNarrowVersion && 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.flex2]}>{translate('common.from')}</Text>
<Text style={[styles.searchInputStyle, styles.flex2]}>{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) {
return;
}

Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute(query, reportID));
};

const ListItem = SearchUtils.getListItem();
const data = SearchUtils.getSections(cleanResults ?? {});

// 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, isDisabled: false}]}
onSelectRow={(item) => {
openReport(item.transactionThreadReportID);
}}
onSelectAll={!displayNarrowVersion ? () => {} : 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