-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Added "Create" button on Reports page #83541
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
Open
mukhrr
wants to merge
7
commits into
Expensify:main
Choose a base branch
from
mukhrr:fix/83430
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,030
−731
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9cbc366
Add create button with menu to search filters bar on desktop
mukhrr 5055df1
Fix create menu popover positioning and simplify money request calls
mukhrr cedb4a4
Fix import order and remove unnecessary useMemo for reportID generation
mukhrr 3a76995
Refactor search filters bar to use flexbox layout on desktop instead …
mukhrr 4574584
Extract SearchFiltersBarCreateButton into separate component and cond…
mukhrr c0bb8bd
Merge remote-tracking branch 'origin' into fix/83430
mukhrr b8b3c49
Extract DatePickerFilterPopup and MultiSelectFilterPopup into separat…
mukhrr 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
119 changes: 119 additions & 0 deletions
119
src/components/Search/SearchPageHeader/SearchFiltersBarCreateButton.tsx
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,119 @@ | ||
| import {emailSelector} from '@selectors/Session'; | ||
| import React, {useCallback, useMemo, useRef, useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
| import Button from '@components/Button'; | ||
| import type {PopoverMenuItem} from '@components/PopoverMenu'; | ||
| import PopoverMenu from '@components/PopoverMenu'; | ||
| import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import usePopoverPosition from '@hooks/usePopoverPosition'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {startDistanceRequest, startMoneyRequest} from '@libs/actions/IOU'; | ||
| import getIconForAction from '@libs/getIconForAction'; | ||
| import interceptAnonymousUser from '@libs/interceptAnonymousUser'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {areAllGroupPoliciesExpenseChatDisabled} from '@libs/PolicyUtils'; | ||
| import {generateReportID} from '@libs/ReportUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import {groupPaidPoliciesWithExpenseChatEnabledSelector} from '@src/selectors/Policy'; | ||
| import type * as OnyxTypes from '@src/types/onyx'; | ||
|
|
||
| function SearchFiltersBarCreateButton() { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const expensifyIcons = useMemoizedLazyExpensifyIcons(['Plus', 'Location', 'Document', 'Receipt', 'Coins', 'Cash', 'Transfer', 'MoneyCircle']); | ||
|
|
||
| const createButtonRef = useRef<View>(null); | ||
| const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); | ||
| const [createMenuPosition, setCreateMenuPosition] = useState<{horizontal: number; vertical: number}>({horizontal: 0, vertical: 0}); | ||
| const {calculatePopoverPosition} = usePopoverPosition(); | ||
|
|
||
| const [email] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector}); | ||
| const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); | ||
|
|
||
| const groupPaidPoliciesWithChatEnabledSelector = useCallback((policies: OnyxCollection<OnyxTypes.Policy>) => groupPaidPoliciesWithExpenseChatEnabledSelector(policies, email), [email]); | ||
| const [groupPoliciesWithChatEnabled = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: groupPaidPoliciesWithChatEnabledSelector}, [email]); | ||
| const shouldRedirectToExpensifyClassic = useMemo(() => areAllGroupPoliciesExpenseChatDisabled(allPolicies ?? {}), [allPolicies]); | ||
mukhrr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const shouldShowCreateReportOption = shouldRedirectToExpensifyClassic || groupPoliciesWithChatEnabled.length > 0; | ||
|
|
||
| const hideCreateMenu = useCallback(() => setIsCreateMenuActive(false), []); | ||
| const showCreateMenu = useCallback(() => { | ||
| if (!createButtonRef.current) { | ||
| return; | ||
| } | ||
| calculatePopoverPosition(createButtonRef, { | ||
| horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, | ||
| vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, | ||
| }).then((position) => { | ||
| setCreateMenuPosition(position); | ||
| setIsCreateMenuActive(true); | ||
| }); | ||
| }, [calculatePopoverPosition]); | ||
|
|
||
| const createMenuItems = useMemo( | ||
| (): PopoverMenuItem[] => [ | ||
| { | ||
| icon: getIconForAction(CONST.IOU.TYPE.CREATE, expensifyIcons), | ||
| text: translate('iou.createExpense'), | ||
| onSelected: () => | ||
| interceptAnonymousUser(() => { | ||
| startMoneyRequest(CONST.IOU.TYPE.CREATE, generateReportID()); | ||
| }), | ||
| }, | ||
| { | ||
| icon: expensifyIcons.Location, | ||
| text: translate('iou.trackDistance'), | ||
| onSelected: () => | ||
| interceptAnonymousUser(() => { | ||
| startDistanceRequest(CONST.IOU.TYPE.CREATE, generateReportID()); | ||
| }), | ||
| }, | ||
| ...(shouldShowCreateReportOption | ||
| ? [ | ||
| { | ||
| icon: expensifyIcons.Document, | ||
| text: translate('report.newReport.createReport'), | ||
| onSelected: () => | ||
| interceptAnonymousUser(() => { | ||
| Navigation.navigate(ROUTES.NEW_REPORT_WORKSPACE_SELECTION.getRoute()); | ||
| }), | ||
| }, | ||
| ] | ||
| : []), | ||
| ], | ||
| [translate, expensifyIcons, shouldShowCreateReportOption], | ||
| ); | ||
|
|
||
| return ( | ||
| <View style={[styles.pr5, styles.searchFiltersBarCreateButton]}> | ||
| <PopoverMenu | ||
| onClose={hideCreateMenu} | ||
| isVisible={isCreateMenuActive} | ||
| menuItems={createMenuItems} | ||
| onItemSelected={hideCreateMenu} | ||
| anchorRef={createButtonRef} | ||
| anchorPosition={createMenuPosition} | ||
| anchorAlignment={{ | ||
| horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, | ||
| vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, | ||
| }} | ||
| /> | ||
| <Button | ||
| ref={createButtonRef} | ||
| success | ||
| small | ||
| icon={expensifyIcons.Plus} | ||
| text={translate('common.create')} | ||
| onPress={showCreateMenu} | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| SearchFiltersBarCreateButton.displayName = 'SearchFiltersBarCreateButton'; | ||
|
|
||
| export default SearchFiltersBarCreateButton; | ||
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.