-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[Search v1] Add handling of actions and improve Search list items #41725
Changes from 15 commits
a245b25
619cd3c
1584ced
424ad95
dbb2748
b573e74
6633b0d
54303a1
b38a8e4
57f39fb
5e3cb31
0f870a4
979bd17
7c3e57e
7f68d12
ef948e3
435205f
28b8c3c
87c2866
9891377
f2d2544
0484b99
ad49412
fbf83af
a224fe2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react'; | ||
import React, {useCallback} from 'react'; | ||
import {View} from 'react-native'; | ||
import Badge from '@components/Badge'; | ||
import Button from '@components/Button'; | ||
|
@@ -7,28 +7,57 @@ import useLocalize from '@hooks/useLocalize'; | |
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import Navigation from '@navigation/Navigation'; | ||
import variables from '@styles/variables'; | ||
import * as SearchActions from '@userActions/Search'; | ||
import CONST from '@src/CONST'; | ||
import type {TranslationPaths} from '@src/languages/types'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {SearchTransactionAction} from '@src/types/onyx/SearchResults'; | ||
|
||
const actionTranslationsMap: Record<SearchTransactionAction, TranslationPaths> = { | ||
view: 'common.view', | ||
review: 'common.review', | ||
done: 'common.done', | ||
paid: 'iou.settledExpensify', | ||
hold: 'iou.hold', | ||
unhold: 'iou.unhold', | ||
}; | ||
Kicu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
type ActionCellProps = { | ||
onButtonPress: () => void; | ||
action?: string; | ||
action?: SearchTransactionAction; | ||
transactionID?: string; | ||
searchHash: number; | ||
isLargeScreenWidth?: boolean; | ||
isSelected?: boolean; | ||
goToItem: () => void; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'd prefer not to rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? |
||
|
||
function ActionCell({onButtonPress, action = CONST.SEARCH.ACTION_TYPES.VIEW, isLargeScreenWidth = true, isSelected = false}: ActionCellProps) { | ||
function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, transactionID, searchHash, isLargeScreenWidth = true, isSelected = false, goToItem}: ActionCellProps) { | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const theme = useTheme(); | ||
const styles = useThemeStyles(); | ||
const StyleUtils = useStyleUtils(); | ||
|
||
const onButtonPress = useCallback(() => { | ||
if (!transactionID) { | ||
luacmartins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
if (action === CONST.SEARCH.ACTION_TYPES.HOLD) { | ||
Navigation.navigate(ROUTES.TRANSACTION_HOLD_REASON_RHP.getRoute(CONST.SEARCH.TAB.ALL, transactionID, searchHash)); | ||
} else if (action === CONST.SEARCH.ACTION_TYPES.UNHOLD) { | ||
SearchActions.unholdMoneyRequestOnSearch(searchHash, [transactionID]); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe instead of passing the hash as an argument here, we could just compute it from the route within |
||
}, [action, searchHash, transactionID]); | ||
|
||
const text = translate(actionTranslationsMap[action]); | ||
|
||
if (action === CONST.SEARCH.ACTION_TYPES.PAID || action === CONST.SEARCH.ACTION_TYPES.DONE) { | ||
const buttonTextKey = action === CONST.SEARCH.ACTION_TYPES.PAID ? 'iou.settledExpensify' : 'common.done'; | ||
return ( | ||
<View style={[StyleUtils.getHeight(variables.h28), styles.justifyContentCenter]}> | ||
<Badge | ||
text={translate(buttonTextKey)} | ||
text={text} | ||
icon={Expensicons.Checkmark} | ||
badgeStyles={[ | ||
styles.ml0, | ||
|
@@ -47,9 +76,21 @@ function ActionCell({onButtonPress, action = CONST.SEARCH.ACTION_TYPES.VIEW, isL | |
); | ||
} | ||
|
||
if (action === CONST.SEARCH.ACTION_TYPES.VIEW || action === CONST.SEARCH.ACTION_TYPES.REVIEW) { | ||
return ( | ||
<Button | ||
text={text} | ||
onPress={goToItem} | ||
small | ||
pressOnEnter | ||
style={[styles.w100]} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Button | ||
text={translate('common.view')} | ||
text={text} | ||
onPress={onButtonPress} | ||
small | ||
pressOnEnter | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type HoldRequestOnSearchParams = { | ||
searchHash: number; | ||
transactionIDList: string[]; | ||
comment?: string; | ||
luacmartins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export default HoldRequestOnSearchParams; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type UnholdRequestOnSearchParams = { | ||
searchHash: number; | ||
transactionIDList: string[]; | ||
}; | ||
|
||
export default UnholdRequestOnSearchParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about this, why do we need the hash in the URL? The hash is derived from the query which is already in the URL. Can we just remove the hash entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also was thinking about this. Currently hash is generated like this:
getQueryHash(query, policyIDs, sortBy, sortOrder)
so it requires 4 params. I decided it makes more sense to add 1 hash param to this/hold
route, than to add all 4 Search query params.It is messy I know :/