-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Search v1] Add handling of actions and improve Search list items #41725
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
Merged
luacmartins
merged 25 commits into
Expensify:main
from
software-mansion-labs:search/kicu/39890-action-buttons
Jul 9, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a245b25
Add handling of actions to TransactionListItem
Kicu 619cd3c
Extract ActionCell to a separate component
Kicu 1584ced
Implement action buttons for transactions and reports in Search
Kicu 424ad95
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu dbb2748
Implement small changes in Actions after review
Kicu b573e74
refactor Consts for Search
Kicu 6633b0d
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu 54303a1
Update ActionCell component to correctly handle hold and unhold actions
Kicu b38a8e4
add small fixes to search utils
Kicu 57f39fb
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu 5e3cb31
Add Search hold reason RHP page and handle hold/unhold actions
Kicu 0f870a4
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu 979bd17
Cleanup Search ActionCell and actions
Kicu 7c3e57e
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu 7f68d12
Update Search Item Actions after merging bulk actions
Kicu ef948e3
Cleanup Search params old command leftovers
Kicu 435205f
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu 28b8c3c
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu 87c2866
Add SearchContext and use it for storing current search hash
Kicu 9891377
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu f2d2544
Add small style updates to transaction items
Kicu 0484b99
Add small style fixes to search
Kicu ad49412
Merge branch 'main' into search/kicu/39890-action-buttons
Kicu fbf83af
Fix Search transaction list item highlight colors
Kicu a224fe2
Fix margin on ReportListItem
Kicu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import React, {useCallback, useContext, useMemo, useState} from 'react'; | ||
| import type ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
| import type {SearchContext} from './types'; | ||
|
|
||
| const defaultSearchContext = { | ||
| currentSearchHash: -1, | ||
| selectedTransactionIDs: [], | ||
| setCurrentSearchHash: () => {}, | ||
| setSelectedTransactionIds: () => {}, | ||
| }; | ||
|
|
||
| const Context = React.createContext<SearchContext>(defaultSearchContext); | ||
|
|
||
| function SearchContextProvider({children}: ChildrenProps) { | ||
| const [searchContextData, setSearchContextData] = useState<Pick<SearchContext, 'currentSearchHash' | 'selectedTransactionIDs'>>({ | ||
| currentSearchHash: defaultSearchContext.currentSearchHash, | ||
| selectedTransactionIDs: defaultSearchContext.selectedTransactionIDs, | ||
| }); | ||
|
|
||
| const setCurrentSearchHash = useCallback( | ||
| (searchHash: number) => { | ||
| setSearchContextData({ | ||
| ...searchContextData, | ||
| currentSearchHash: searchHash, | ||
| }); | ||
| }, | ||
| [searchContextData], | ||
| ); | ||
|
|
||
| const setSelectedTransactionIds = useCallback( | ||
| (selectedTransactionIDs: string[]) => { | ||
| setSearchContextData({ | ||
| ...searchContextData, | ||
| selectedTransactionIDs, | ||
| }); | ||
| }, | ||
| [searchContextData], | ||
| ); | ||
|
|
||
| const searchContext = useMemo<SearchContext>( | ||
| () => ({ | ||
| ...searchContextData, | ||
| setCurrentSearchHash, | ||
| setSelectedTransactionIds, | ||
| }), | ||
| [searchContextData, setCurrentSearchHash, setSelectedTransactionIds], | ||
| ); | ||
|
|
||
| return <Context.Provider value={searchContext}>{children}</Context.Provider>; | ||
| } | ||
|
|
||
| function useSearchContext() { | ||
| return useContext(Context); | ||
| } | ||
|
|
||
| SearchContextProvider.displayName = 'SearchContextProvider'; | ||
|
|
||
| export {SearchContextProvider, useSearchContext}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,78 @@ | ||
| import React from 'react'; | ||
| import React, {useCallback} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import Badge from '@components/Badge'; | ||
| import Button from '@components/Button'; | ||
| import * as Expensicons from '@components/Icon/Expensicons'; | ||
| import {useSearchContext} from '@components/Search/SearchContext'; | ||
| 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', | ||
| }; | ||
|
|
||
| type ActionCellProps = { | ||
| onButtonPress: () => void; | ||
| action?: string; | ||
| action?: SearchTransactionAction; | ||
| transactionID?: string; | ||
| isLargeScreenWidth?: boolean; | ||
| isSelected?: boolean; | ||
| goToItem: () => void; | ||
|
Contributor
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
Contributor
Author
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, isLargeScreenWidth = true, isSelected = false, goToItem}: ActionCellProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const theme = useTheme(); | ||
| const styles = useThemeStyles(); | ||
| const StyleUtils = useStyleUtils(); | ||
|
|
||
| const {currentSearchHash} = useSearchContext(); | ||
|
|
||
| const onButtonPress = useCallback(() => { | ||
|
luacmartins marked this conversation as resolved.
|
||
| if (!transactionID) { | ||
| return; | ||
| } | ||
|
|
||
| if (action === CONST.SEARCH.ACTION_TYPES.HOLD) { | ||
| Navigation.navigate(ROUTES.TRANSACTION_HOLD_REASON_RHP.getRoute(CONST.SEARCH.TAB.ALL, transactionID)); | ||
| } else if (action === CONST.SEARCH.ACTION_TYPES.UNHOLD) { | ||
| SearchActions.unholdMoneyRequestOnSearch(currentSearchHash, [transactionID]); | ||
| } | ||
| }, [action, currentSearchHash, transactionID]); | ||
|
|
||
| if (!isLargeScreenWidth) { | ||
| return null; | ||
| } | ||
|
|
||
| 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, | ||
| styles.ph2, | ||
| styles.gap1, | ||
| isLargeScreenWidth ? styles.alignSelfCenter : styles.alignSelfEnd, | ||
| StyleUtils.getBorderColorStyle(theme.border), | ||
| StyleUtils.getHeight(variables.h20), | ||
| StyleUtils.getMinimumHeight(variables.h20), | ||
| isSelected ? StyleUtils.getBorderColorStyle(theme.buttonHoveredBG) : StyleUtils.getBorderColorStyle(theme.border), | ||
| ]} | ||
| textStyles={StyleUtils.getFontSizeStyle(variables.fontSizeExtraSmall)} | ||
| iconStyles={styles.mr0} | ||
|
|
@@ -50,14 +82,29 @@ function ActionCell({onButtonPress, action = CONST.SEARCH.ACTION_TYPES.VIEW, isL | |
| ); | ||
| } | ||
|
|
||
| const buttonInnerStyles = isSelected ? styles.buttonDefaultHovered : {}; | ||
|
|
||
| if (action === CONST.SEARCH.ACTION_TYPES.VIEW || action === CONST.SEARCH.ACTION_TYPES.REVIEW) { | ||
| return ( | ||
| <Button | ||
| text={text} | ||
| onPress={goToItem} | ||
| small | ||
| pressOnEnter | ||
| style={[styles.w100]} | ||
| innerStyles={buttonInnerStyles} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Button | ||
| text={translate('common.view')} | ||
| text={text} | ||
| onPress={onButtonPress} | ||
| small | ||
| pressOnEnter | ||
| style={[styles.w100]} | ||
| innerStyles={isSelected ? styles.buttonDefaultHovered : {}} | ||
| innerStyles={buttonInnerStyles} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.