Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
adcd8fa
create searchtableheader
luacmartins Apr 30, 2024
736f4e6
fix header style
luacmartins Apr 30, 2024
a54eed4
create receipt element
luacmartins Apr 30, 2024
f061806
update row callback
luacmartins Apr 30, 2024
d96a461
add button translation and styles
luacmartins Apr 30, 2024
8f6fe42
use display amounts
luacmartins Apr 30, 2024
6006e97
refactor tag element
luacmartins Apr 30, 2024
cb97bab
create getSearchTableColumnWidth
luacmartins Apr 30, 2024
eefa1a1
add styles framework
luacmartins Apr 30, 2024
071f4ea
dry user element
luacmartins Apr 30, 2024
1c5016e
style description
luacmartins Apr 30, 2024
e573f9b
dry code
luacmartins Apr 30, 2024
372d09a
dry more code
luacmartins Apr 30, 2024
e14eb1d
rm unused code
luacmartins Apr 30, 2024
b829695
use modified values if present
luacmartins Apr 30, 2024
1de539b
rm getCleanResults
luacmartins Apr 30, 2024
792c3da
inject from/to into listitem
luacmartins Apr 30, 2024
8ae1e53
refactor code
luacmartins Apr 30, 2024
2e8245c
style narrow view
luacmartins Apr 30, 2024
90fa358
style narrow view
luacmartins Apr 30, 2024
2e2fa84
refactor cells
luacmartins May 1, 2024
61acc00
fix lint
luacmartins May 1, 2024
92caa11
fix lint, typecheck
luacmartins May 1, 2024
7950e9d
fix typecheck
luacmartins May 1, 2024
5b7e9a9
fix lint
luacmartins May 1, 2024
eebf75d
fix amounts, use utils methods
luacmartins May 1, 2024
fc66433
fix avatars
luacmartins May 1, 2024
293e030
fix ts
luacmartins May 1, 2024
042e42b
do not show default merchant
luacmartins May 1, 2024
db0c3d6
update logic to show merchant or description
luacmartins May 1, 2024
21dfe1b
rm debug log
luacmartins May 1, 2024
d3aa67d
fix lint
luacmartins May 1, 2024
008cd10
add keyForList
luacmartins May 1, 2024
63ad92e
fix ts
luacmartins May 1, 2024
2bbf7eb
fix lint
luacmartins May 1, 2024
05fc405
fix styles on native
luacmartins May 1, 2024
dd3b869
fix lint
luacmartins May 1, 2024
de81594
fix merchant logic
luacmartins May 2, 2024
07bb641
fix display name overflow
luacmartins May 2, 2024
1014394
fix button padding
luacmartins May 2, 2024
16b8c55
fix lint
luacmartins May 2, 2024
22ea64c
use variables
luacmartins May 2, 2024
3847571
update row vertical padding
luacmartins May 2, 2024
cfd5990
rm button padding
luacmartins May 2, 2024
b475b28
use isLargeScreenWidth
luacmartins May 2, 2024
acf290f
fix avatar colors
luacmartins May 2, 2024
b527a9f
use style utils
luacmartins May 2, 2024
9944b24
rm receipt styles
luacmartins May 2, 2024
4720cd2
fix left aligned items
luacmartins May 2, 2024
4151bce
rename to expenses
luacmartins May 2, 2024
dc4be99
use mw50
luacmartins May 2, 2024
cab3d02
fix crash
luacmartins May 2, 2024
9263ffd
rm button on mobile
luacmartins May 2, 2024
10af037
fix lint
luacmartins May 2, 2024
7599c58
increase gap
luacmartins May 2, 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
14 changes: 9 additions & 5 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,15 @@ const CONST = {
SEARCH_OPTION_LIST_DEBOUNCE_TIME: 300,
RESIZE_DEBOUNCE_TIME: 100,
},
SEARCH_TABLE_COLUMNS: {
DATE: 'date',
MERCHANT: 'merchant',
FROM: 'from',
TO: 'to',
TOTAL: 'total',
TYPE: 'type',
ACTION: 'action',
},
PRIORITY_MODE: {
GSD: 'gsd',
DEFAULT: 'default',
Expand Down Expand Up @@ -3400,11 +3409,6 @@ const CONST = {
},
TAB_SEARCH: {
ALL: 'all',
// @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
69 changes: 6 additions & 63 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
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';
Expand All @@ -16,35 +13,16 @@ import ROUTES from '@src/ROUTES';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import SelectionList from './SelectionList';
import SearchTableHeader from './SelectionList/SearchTableHeader';
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);
Expand All @@ -58,14 +36,8 @@ function Search({query}: SearchProps) {
SearchActions.search(query);
}, [query, isOffline]);

const cleanResults = getCleanSearchResults(searchResults);

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

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

if (isLoading) {
return <TableListItemSkeleton shouldAnimate />;
Expand All @@ -75,33 +47,6 @@ 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;
Expand All @@ -111,19 +56,17 @@ function Search({query}: SearchProps) {
};

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

return (
<SelectionList
canSelectMultiple
customListHeader={getListHeader()}
customListHeader={<SearchTableHeader shouldShowMerchant={shouldShowMerchant} />}
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]}
/>
Expand Down
57 changes: 57 additions & 0 deletions src/components/SelectionList/SearchTableHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import {View} from 'react-native';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import CONST from '@src/CONST';

type SearchTableHeaderProps = {
/** Whether we should show the merchant or description column */
shouldShowMerchant: boolean;
};

function SearchTableHeader({shouldShowMerchant}: SearchTableHeaderProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {isSmallScreenWidth, isMediumScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();
const displayNarrowVersion = isMediumScreenWidth || isSmallScreenWidth;

if (displayNarrowVersion) {
return;
}

return (
<View style={[styles.ph5, styles.pb3]}>
<View style={[styles.flex1, styles.flexRow, styles.gap3, styles.ph4]}>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH_TABLE_COLUMNS.DATE)]}>
<Text style={[styles.mutedNormalTextLabel]}>{translate('common.date')}</Text>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH_TABLE_COLUMNS.MERCHANT)]}>
<Text style={[styles.mutedNormalTextLabel]}>{translate(shouldShowMerchant ? 'common.merchant' : 'common.description')}</Text>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH_TABLE_COLUMNS.FROM)]}>
<Text style={[styles.mutedNormalTextLabel]}>{translate('common.from')}</Text>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH_TABLE_COLUMNS.TO)]}>
<Text style={[styles.mutedNormalTextLabel]}>{translate('common.to')}</Text>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH_TABLE_COLUMNS.TOTAL)]}>
<Text style={[styles.mutedNormalTextLabel]}>{translate('common.total')}</Text>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH_TABLE_COLUMNS.TYPE)]}>
<Text style={[styles.mutedNormalTextLabel]}>{translate('common.type')}</Text>
</View>
<View style={[StyleUtils.getSearchTableColumnStyles(CONST.SEARCH_TABLE_COLUMNS.ACTION)]}>
<Text style={[styles.mutedNormalTextLabel, styles.textAlignCenter]}>{translate('common.action')}</Text>
</View>
</View>
</View>
);
}

SearchTableHeader.displayName = 'SearchTableHeader';

export default SearchTableHeader;
Loading