From 0abb380ce52148fba4eea4d2a64f2a3b0e6e0c61 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 29 Oct 2024 10:51:25 +0700 Subject: [PATCH 1/9] fix: Deleted room is displayed in the 'Assign task' --- .../SidebarScreen/FloatingActionButtonAndPopover.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index a49b474b185e..329066b00a99 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -189,9 +189,10 @@ function FloatingActionButtonAndPopover( const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions(); const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection, session?.email), [allPolicies, session?.email]); + const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs)); const quickActionAvatars = useMemo(() => { - if (quickActionReport) { + if (isValidReport) { const avatars = ReportUtils.getIcons(quickActionReport, personalDetails); return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID); } @@ -223,7 +224,7 @@ function FloatingActionButtonAndPopover( }, [quickAction, translate, quickActionAvatars, quickActionReport]); const hideQABSubtitle = useMemo(() => { - if (isEmptyObject(quickActionReport)) { + if (isValidReport) { return true; } if (quickActionAvatars.length === 0) { @@ -231,7 +232,7 @@ function FloatingActionButtonAndPopover( } const displayName = personalDetails?.[quickActionAvatars.at(0)?.id ?? -1]?.firstName ?? ''; return quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && displayName.length === 0; - }, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]); + }, [isValidReport, quickActionAvatars, personalDetails, quickAction?.action]); const navigateToQuickAction = () => { const selectOption = (onSelected: () => void, shouldRestrictAction: boolean) => { @@ -243,7 +244,6 @@ function FloatingActionButtonAndPopover( onSelected(); }; - const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs)); const quickActionReportID = isValidReport ? quickActionReport?.reportID ?? '-1' : ReportUtils.generateReportID(); switch (quickAction?.action) { From 5889c08cc90ef34eb83e6d42b7922db32e4785e4 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 29 Oct 2024 17:29:05 +0700 Subject: [PATCH 2/9] fix eslint --- .../FloatingActionButtonAndPopover.tsx | 86 ++++--------------- 1 file changed, 15 insertions(+), 71 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 329066b00a99..b8b76e5a00eb 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -1,10 +1,10 @@ import {useIsFocused as useIsFocusedOriginal, useNavigationState} from '@react-navigation/native'; import type {ImageContentFit} from 'expo-image'; -import type {ForwardedRef, RefAttributes} from 'react'; +import type {ForwardedRef} from 'react'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; -import {useOnyx, withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {SvgProps} from 'react-native-svg'; import FloatingActionButton from '@components/FloatingActionButton'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -39,6 +39,7 @@ import SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import type {QuickActionName} from '@src/types/onyx/QuickAction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems'; // On small screen we hide the search page from central pane to show the search bottom tab page with bottom tab bar. // We need to take this in consideration when checking if the screen is focused. @@ -51,33 +52,7 @@ const useIsFocused = () => { type PolicySelector = Pick; -type FloatingActionButtonAndPopoverOnyxProps = { - /** The list of policies the user has access to. */ - allPolicies: OnyxCollection; - - /** Whether app is in loading state */ - isLoading: OnyxEntry; - - /** Information on the last taken action to display as Quick Action */ - quickAction: OnyxEntry; - - /** The report data of the quick action */ - quickActionReport: OnyxEntry; - - /** The policy data of the quick action */ - quickActionPolicy: OnyxEntry; - - /** The current session */ - session: OnyxEntry; - - /** Personal details of all the users */ - personalDetails: OnyxEntry; - - /** Has user seen track expense training interstitial */ - hasSeenTrackTraining: OnyxEntry; -}; - -type FloatingActionButtonAndPopoverProps = FloatingActionButtonAndPopoverOnyxProps & { +type FloatingActionButtonAndPopoverProps = { /* Callback function when the menu is shown */ onShowCreateMenu?: () => void; @@ -161,23 +136,18 @@ const getQuickActionTitle = (action: QuickActionName): TranslationPaths => { * Responsible for rendering the {@link PopoverMenu}, and the accompanying * FAB that can open or close the menu. */ -function FloatingActionButtonAndPopover( - { - onHideCreateMenu, - onShowCreateMenu, - isLoading = false, - allPolicies, - quickAction, - quickActionReport, - quickActionPolicy, - session, - personalDetails, - hasSeenTrackTraining, - }: FloatingActionButtonAndPopoverProps, - ref: ForwardedRef, -) { +function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: FloatingActionButtonAndPopoverProps, ref: ForwardedRef) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (c) => mapOnyxCollectionItems(c, policySelector)}); + const [isLoading] = useOnyx(ONYXKEYS.IS_LOADING_APP); + const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE); + const [quickActionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${quickAction?.chatReportID}`); + const [quickActionPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${quickActionReport?.policyID}`); + const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); + const [session] = useOnyx(ONYXKEYS.SESSION); + const [hasSeenTrackTraining] = useOnyx(ONYXKEYS.NVP_HAS_SEEN_TRACK_TRAINING); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${quickActionReport?.reportID ?? -1}`); const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); const fabRef = useRef(null); @@ -510,32 +480,6 @@ function FloatingActionButtonAndPopover( FloatingActionButtonAndPopover.displayName = 'FloatingActionButtonAndPopover'; -export default withOnyx, FloatingActionButtonAndPopoverOnyxProps>({ - allPolicies: { - key: ONYXKEYS.COLLECTION.POLICY, - selector: policySelector, - }, - isLoading: { - key: ONYXKEYS.IS_LOADING_APP, - }, - quickAction: { - key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, - }, - quickActionReport: { - key: ({quickAction}) => `${ONYXKEYS.COLLECTION.REPORT}${quickAction?.chatReportID}`, - }, - quickActionPolicy: { - key: ({quickActionReport}) => `${ONYXKEYS.COLLECTION.POLICY}${quickActionReport?.policyID}`, - }, - personalDetails: { - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - }, - session: { - key: ONYXKEYS.SESSION, - }, - hasSeenTrackTraining: { - key: ONYXKEYS.NVP_HAS_SEEN_TRACK_TRAINING, - }, -})(forwardRef(FloatingActionButtonAndPopover)); +export default forwardRef(FloatingActionButtonAndPopover); export type {PolicySelector}; From 83a70f9ab7c2d40e003be64f86118a92e1302cc5 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 1 Nov 2024 15:07:55 +0700 Subject: [PATCH 3/9] fix show QAB subtitle --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index b8b76e5a00eb..c58b725a6b49 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -194,7 +194,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl }, [quickAction, translate, quickActionAvatars, quickActionReport]); const hideQABSubtitle = useMemo(() => { - if (isValidReport) { + if (!isValidReport) { return true; } if (quickActionAvatars.length === 0) { From 69f180617e63b1435f984e029ef18a8b4dcc99c1 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 7 Nov 2024 16:24:34 +0700 Subject: [PATCH 4/9] fix lint --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index c025d668e9a6..fc63f83f09bc 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -453,7 +453,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl onSelected: () => interceptAnonymousUser(() => { selectOption(() => { - const isValidReport = !(isEmptyObject(policyChatForActivePolicy) || ReportUtils.isArchivedRoom(policyChatForActivePolicy, reportNameValuePairs)); const quickActionReportID = isValidReport ? policyChatForActivePolicy?.reportID ?? '-1' : ReportUtils.generateReportID(); IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true); }, true); @@ -473,14 +472,14 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl styles.quickActionTooltipWrapper, renderQuickActionTooltip, quickAction?.action, - quickAction?.isFirstQuickAction, + quickAction.isFirstQuickAction, policyChatForActivePolicy, quickActionTitle, hideQABSubtitle, quickActionReport, navigateToQuickAction, selectOption, - reportNameValuePairs, + isValidReport, ]); return ( From 4ea4fcdfa95eb998dcd706010c36f6ea09f2a1ac Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 8 Nov 2024 11:16:02 +0700 Subject: [PATCH 5/9] fix lint --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index fc63f83f09bc..90b535729f01 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -281,7 +281,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl break; default: } - }, [quickAction, quickActionReport, reportNameValuePairs, selectOption]); + }, [isValidReport, quickAction?.action, quickAction?.targetAccountID, quickActionReport?.reportID, selectOption]); /** * Check if LHN status changed from active to inactive. @@ -472,7 +472,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl styles.quickActionTooltipWrapper, renderQuickActionTooltip, quickAction?.action, - quickAction.isFirstQuickAction, + quickAction?.isFirstQuickAction, policyChatForActivePolicy, quickActionTitle, hideQABSubtitle, From bbbcce993591d78badf4e19f327054edee20f128 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 12 Nov 2024 16:33:10 +0700 Subject: [PATCH 6/9] fix: add test for QAB --- src/libs/ReportUtils.ts | 25 +++++++++++++++++++++++++ tests/unit/ReportUtilsTest.ts | 16 ++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a104b98175c4..c543e33c795e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7949,6 +7949,30 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct }); } +function getQuickActionDetails( + quickActionReport: Report, + personalDetails: PersonalDetailsList | undefined, + policyChatForActivePolicy: Report | undefined, + reportNameValuePairs: ReportNameValuePairs, +): {quickActionAvatars: Icon[]; hideQABSubtitle: boolean} { + const isValidQuickActionReport = !(isEmptyObject(quickActionReport) || isArchivedRoom(quickActionReport, reportNameValuePairs)); + let hideQABSubtitle = false; + let quickActionAvatars: Icon[] = []; + if (isValidQuickActionReport) { + const avatars = getIcons(quickActionReport, personalDetails); + quickActionAvatars = avatars.length <= 1 || isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== currentUserAccountID); + } else { + hideQABSubtitle = true; + } + if (!isEmptyObject(policyChatForActivePolicy)) { + quickActionAvatars = getIcons(policyChatForActivePolicy, personalDetails); + } + return { + quickActionAvatars, + hideQABSubtitle, + }; +} + function canBeAutoReimbursed(report: OnyxInputOrEntry, policy: OnyxInputOrEntry): boolean { if (isEmptyObject(policy)) { return false; @@ -8565,6 +8589,7 @@ export { getInvoicePayerName, getInvoicesChatName, getPayeeName, + getQuickActionDetails, hasActionsWithErrors, hasAutomatedExpensifyAccountIDs, hasExpensifyGuidesEmails, diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 81101b74f4d7..53acb0ae81a4 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -975,6 +975,22 @@ describe('ReportUtils', () => { }); }); + describe('getQuickActionDetails', () => { + it('if the report is archived, the quick action will hide the subtitle and avatar', () => { + const archivedReport: Report = { + reportID: '1', + private_isArchived: DateUtils.getDBTime(), + }; + const reportNameValuePairs = { + type: 'chat', + private_isArchived: true, + }; + const quickActionDetails = ReportUtils.getQuickActionDetails(archivedReport, undefined, undefined, reportNameValuePairs); + expect(quickActionDetails.quickActionAvatars.length).toEqual(0); + expect(quickActionDetails.hideQABSubtitle).toEqual(true); + }); + }); + describe('getChatByParticipants', () => { const userAccountID = 1; const userAccountID2 = 2; From d3c1b997b0f5f0c32aca3d1ac27fb0e5c2eacaa2 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 14 Nov 2024 15:23:56 +0700 Subject: [PATCH 7/9] add comment context --- tests/unit/ReportUtilsTest.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 53acb0ae81a4..2af8a0777c74 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -977,7 +977,9 @@ describe('ReportUtils', () => { describe('getQuickActionDetails', () => { it('if the report is archived, the quick action will hide the subtitle and avatar', () => { + // Create a fake archived report as quick action report const archivedReport: Report = { + ...LHNTestUtils.getFakeReport(), reportID: '1', private_isArchived: DateUtils.getDBTime(), }; @@ -985,7 +987,11 @@ describe('ReportUtils', () => { type: 'chat', private_isArchived: true, }; + + // Get the quick action detail const quickActionDetails = ReportUtils.getQuickActionDetails(archivedReport, undefined, undefined, reportNameValuePairs); + + // Expect the quickActionAvatars is empty array and hideQABSubtitle is true since the quick action report is archived expect(quickActionDetails.quickActionAvatars.length).toEqual(0); expect(quickActionDetails.hideQABSubtitle).toEqual(true); }); From 784ec89870652c155f494049844243b228056eb9 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 14 Nov 2024 16:00:04 +0700 Subject: [PATCH 8/9] fix test --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6b26e12f59ae..06fa92649a7c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7963,7 +7963,7 @@ function getQuickActionDetails( } return { quickActionAvatars, - hideQABSubtitle, + hideQABSubtitle, }; } From 76ce7c858be35140db04b5fc59d564bf5d63d744 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 14 Nov 2024 16:00:16 +0700 Subject: [PATCH 9/9] fix lint --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 06fa92649a7c..6b26e12f59ae 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7963,7 +7963,7 @@ function getQuickActionDetails( } return { quickActionAvatars, - hideQABSubtitle, + hideQABSubtitle, }; }