From 1b5ad384161bf7816fe656e6a28dee9bb6971784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Wed, 25 Oct 2023 17:45:34 +0200 Subject: [PATCH 1/8] BaseUserDetailsTooltip --- .../BaseUserDetailsTooltip.web.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/components/UserDetailsTooltip/BaseUserDetailsTooltip.web.js b/src/components/UserDetailsTooltip/BaseUserDetailsTooltip.web.js index 5f124cb2146..a072ef2ba4a 100644 --- a/src/components/UserDetailsTooltip/BaseUserDetailsTooltip.web.js +++ b/src/components/UserDetailsTooltip/BaseUserDetailsTooltip.web.js @@ -1,6 +1,5 @@ import React, {useCallback} from 'react'; import {View, Text} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; import Str from 'expensify-common/lib/str'; import lodashGet from 'lodash/get'; import _ from 'underscore'; @@ -8,16 +7,17 @@ import Avatar from '../Avatar'; import Tooltip from '../Tooltip'; import {propTypes, defaultProps} from './userDetailsTooltipPropTypes'; import styles from '../../styles/styles'; -import ONYXKEYS from '../../ONYXKEYS'; import * as UserUtils from '../../libs/UserUtils'; import CONST from '../../CONST'; import * as LocalePhoneNumber from '../../libs/LocalePhoneNumber'; import useLocalize from '../../hooks/useLocalize'; +import {usePersonalDetails} from '../OnyxProvider'; function BaseUserDetailsTooltip(props) { const {translate} = useLocalize(); + const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT; - const userDetails = lodashGet(props.personalDetailsList, props.accountID, props.fallbackUserDetails); + const userDetails = lodashGet(personalDetails, props.accountID, props.fallbackUserDetails); let userDisplayName = userDetails.displayName ? userDetails.displayName.trim() : ''; let userLogin = (userDetails.login || '').trim() && !_.isEqual(userDetails.login, userDetails.displayName) ? Str.removeSMSDomain(userDetails.login) : ''; let userAvatar = userDetails.avatar; @@ -26,7 +26,7 @@ function BaseUserDetailsTooltip(props) { // We replace the actor's email, name, and avatar with the Copilot manually for now. This will be improved upon when // the Copilot feature is implemented. if (props.delegateAccountID) { - const delegateUserDetails = lodashGet(props.personalDetailsList, props.delegateAccountID, {}); + const delegateUserDetails = lodashGet(personalDetails, props.delegateAccountID, {}); const delegateUserDisplayName = delegateUserDetails.displayName ? delegateUserDetails.displayName.trim() : ''; userDisplayName = `${delegateUserDisplayName} (${translate('reportAction.asCopilot')} ${userDisplayName})`; userLogin = delegateUserDetails.login; @@ -78,8 +78,4 @@ BaseUserDetailsTooltip.propTypes = propTypes; BaseUserDetailsTooltip.defaultProps = defaultProps; BaseUserDetailsTooltip.displayName = 'BaseUserDetailsTooltip'; -export default withOnyx({ - personalDetailsList: { - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - }, -})(BaseUserDetailsTooltip); +export default BaseUserDetailsTooltip; From d8ee1fb0d30488ef92d73f2a0e704b0398a3aed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Wed, 25 Oct 2023 17:45:49 +0200 Subject: [PATCH 2/8] TaskPreview --- src/components/ReportActionItem/TaskPreview.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 3499aee5f68..bbb2df599ba 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -22,14 +22,11 @@ import * as Task from '../../libs/actions/Task'; import * as ReportUtils from '../../libs/ReportUtils'; import RenderHTML from '../RenderHTML'; import PressableWithoutFeedback from '../Pressable/PressableWithoutFeedback'; -import personalDetailsPropType from '../../pages/personalDetailsPropType'; import * as Session from '../../libs/actions/Session'; import * as LocalePhoneNumber from '../../libs/LocalePhoneNumber'; +import {usePersonalDetails} from '../OnyxProvider'; const propTypes = { - /** All personal details asssociated with user */ - personalDetailsList: PropTypes.objectOf(personalDetailsPropType), - /** The ID of the associated taskReport */ taskReportID: PropTypes.string.isRequired, @@ -59,12 +56,12 @@ const propTypes = { const defaultProps = { ...withCurrentUserPersonalDetailsDefaultProps, - personalDetailsList: {}, taskReport: {}, isHovered: false, }; function TaskPreview(props) { + const personalDetails = usePersonalDetails || CONST.EMPTY_OBJECT; // The reportAction might not contain details regarding the taskReport // Only the direct parent reportAction will contain details about the taskReport // Other linked reportActions will only contain the taskReportID and we will grab the details from there @@ -73,8 +70,8 @@ function TaskPreview(props) { : props.action.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.action.childStatusNum === CONST.REPORT.STATUS.APPROVED; const taskTitle = props.taskReport.reportName || props.action.childReportName; const taskAssigneeAccountID = Task.getTaskAssigneeAccountID(props.taskReport) || props.action.childManagerAccountID; - const assigneeLogin = lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'login'], ''); - const assigneeDisplayName = lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'displayName'], ''); + const assigneeLogin = lodashGet(personalDetails, [taskAssigneeAccountID, 'login'], ''); + const assigneeDisplayName = lodashGet(personalDetails, [taskAssigneeAccountID, 'displayName'], ''); const taskAssignee = assigneeDisplayName || LocalePhoneNumber.formatPhoneNumber(assigneeLogin); const htmlForTaskPreview = taskAssignee && taskAssigneeAccountID !== 0 @@ -132,9 +129,5 @@ export default compose( key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, initialValue: {}, }, - personalDetailsList: { - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - initialValue: {}, - }, }), )(TaskPreview); From fe8c19413bcba67a0b78c1c768ea59e88cf80ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Wed, 25 Oct 2023 17:45:58 +0200 Subject: [PATCH 3/8] withCurrentUserPersonalDetails --- src/components/withCurrentUserPersonalDetails.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/withCurrentUserPersonalDetails.tsx b/src/components/withCurrentUserPersonalDetails.tsx index e1472f280f1..f47813f0c4f 100644 --- a/src/components/withCurrentUserPersonalDetails.tsx +++ b/src/components/withCurrentUserPersonalDetails.tsx @@ -4,13 +4,12 @@ import getComponentDisplayName from '../libs/getComponentDisplayName'; import ONYXKEYS from '../ONYXKEYS'; import personalDetailsPropType from '../pages/personalDetailsPropType'; import type {PersonalDetails, Session} from '../types/onyx'; +import {usePersonalDetails} from './OnyxProvider'; +import CONST from '../CONST'; type CurrentUserPersonalDetails = PersonalDetails | Record; type OnyxProps = { - /** Personal details of all the users, including current user */ - personalDetails: OnyxEntry>; - /** Session of the current user */ session: OnyxEntry; }; @@ -34,8 +33,9 @@ export default function ( WrappedComponent: ComponentType>, ): ComponentType & RefAttributes, keyof OnyxProps>> { function WithCurrentUserPersonalDetails(props: Omit, ref: ForwardedRef) { + const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT; const accountID = props.session?.accountID ?? 0; - const accountPersonalDetails = props.personalDetails?.[accountID]; + const accountPersonalDetails = personalDetails?.[accountID]; const currentUserPersonalDetails: CurrentUserPersonalDetails = useMemo( () => (accountPersonalDetails ? {...accountPersonalDetails, accountID} : {}), [accountPersonalDetails, accountID], @@ -55,9 +55,6 @@ export default function ( const withCurrentUserPersonalDetails = React.forwardRef(WithCurrentUserPersonalDetails); return withOnyx & RefAttributes, OnyxProps>({ - personalDetails: { - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - }, session: { key: ONYXKEYS.SESSION, }, From 1945ce6d86390e5d2ce13778d5ab5c2ab3dd9f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 30 Oct 2023 10:49:56 +0100 Subject: [PATCH 4/8] add missing function execution --- src/components/ReportActionItem/TaskPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index bbb2df599ba..fc41f2008e5 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -61,7 +61,7 @@ const defaultProps = { }; function TaskPreview(props) { - const personalDetails = usePersonalDetails || CONST.EMPTY_OBJECT; + const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT; // The reportAction might not contain details regarding the taskReport // Only the direct parent reportAction will contain details about the taskReport // Other linked reportActions will only contain the taskReportID and we will grab the details from there From b4a9f5d0071dadbac08714ed01954058348a2670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 30 Oct 2023 11:04:14 +0100 Subject: [PATCH 5/8] resolve aliases in CurrentUserPersonalDetails --- src/components/withCurrentUserPersonalDetails.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/withCurrentUserPersonalDetails.tsx b/src/components/withCurrentUserPersonalDetails.tsx index a3a1d3035cb..030c71225ea 100644 --- a/src/components/withCurrentUserPersonalDetails.tsx +++ b/src/components/withCurrentUserPersonalDetails.tsx @@ -1,11 +1,11 @@ import React, {ComponentType, ForwardedRef, RefAttributes, useMemo} from 'react'; import {OnyxEntry, withOnyx} from 'react-native-onyx'; -import getComponentDisplayName from '../libs/getComponentDisplayName'; -import ONYXKEYS from '../ONYXKEYS'; -import personalDetailsPropType from '../pages/personalDetailsPropType'; -import type {PersonalDetails, Session} from '../types/onyx'; +import getComponentDisplayName from '@libs/getComponentDisplayName'; +import personalDetailsPropType from '@pages/personalDetailsPropType'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {PersonalDetails, Session} from '@src/types/onyx'; import {usePersonalDetails} from './OnyxProvider'; -import CONST from '../CONST'; type CurrentUserPersonalDetails = PersonalDetails | Record; From 2a77766721fd910ef4ded79bf1a66cd67bd87058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 30 Oct 2023 13:40:06 +0100 Subject: [PATCH 6/8] fix prettier issues --- src/components/ReportActionItem/TaskPreview.js | 2 +- .../UserDetailsTooltip/BaseUserDetailsTooltip.web.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 8ec9cdd5cfe..309a66421f8 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -7,6 +7,7 @@ import _ from 'underscore'; import Checkbox from '@components/Checkbox'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; +import {usePersonalDetails} from '@components/OnyxProvider'; import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback'; import RenderHTML from '@components/RenderHTML'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails'; @@ -24,7 +25,6 @@ import * as Task from '@userActions/Task'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import {usePersonalDetails} from '@components/OnyxProvider'; const propTypes = { /** The ID of the associated taskReport */ diff --git a/src/components/UserDetailsTooltip/BaseUserDetailsTooltip.web.js b/src/components/UserDetailsTooltip/BaseUserDetailsTooltip.web.js index 3a593fe73d1..fc295f16c65 100644 --- a/src/components/UserDetailsTooltip/BaseUserDetailsTooltip.web.js +++ b/src/components/UserDetailsTooltip/BaseUserDetailsTooltip.web.js @@ -1,16 +1,16 @@ -import React, {useCallback} from 'react'; -import {View, Text} from 'react-native'; import Str from 'expensify-common/lib/str'; import lodashGet from 'lodash/get'; +import React, {useCallback} from 'react'; +import {Text, View} from 'react-native'; import _ from 'underscore'; import Avatar from '@components/Avatar'; +import {usePersonalDetails} from '@components/OnyxProvider'; import Tooltip from '@components/Tooltip'; import useLocalize from '@hooks/useLocalize'; import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; import * as UserUtils from '@libs/UserUtils'; import styles from '@styles/styles'; import CONST from '@src/CONST'; -import {usePersonalDetails} from '@components/OnyxProvider'; import {defaultProps, propTypes} from './userDetailsTooltipPropTypes'; function BaseUserDetailsTooltip(props) { From 87916f6117cea9a7ac51f06fe8899286e703b57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Thu, 2 Nov 2023 13:06:51 +0100 Subject: [PATCH 7/8] swap || to ?? --- src/components/withCurrentUserPersonalDetails.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/withCurrentUserPersonalDetails.tsx b/src/components/withCurrentUserPersonalDetails.tsx index 030c71225ea..20e536d9d73 100644 --- a/src/components/withCurrentUserPersonalDetails.tsx +++ b/src/components/withCurrentUserPersonalDetails.tsx @@ -33,7 +33,7 @@ export default function ( WrappedComponent: ComponentType>, ): ComponentType & RefAttributes, keyof OnyxProps>> { function WithCurrentUserPersonalDetails(props: Omit, ref: ForwardedRef) { - const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT; + const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT; const accountID = props.session?.accountID ?? 0; const accountPersonalDetails = personalDetails?.[accountID]; const currentUserPersonalDetails: CurrentUserPersonalDetails = useMemo( From 0543ad1dc2ef55d7608db13edda429ef972e71d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Thu, 2 Nov 2023 14:20:00 +0100 Subject: [PATCH 8/8] add waiter in UnreadIndicatorsTest --- tests/ui/UnreadIndicatorsTest.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js index 54808d2b618..b8f920954a3 100644 --- a/tests/ui/UnreadIndicatorsTest.js +++ b/tests/ui/UnreadIndicatorsTest.js @@ -130,7 +130,8 @@ function signInAndGetAppWithUnreadChat() { // Render the App and sign in as a test user. render(); return waitForBatchedUpdatesWithAct() - .then(() => { + .then(async () => { + await waitForBatchedUpdatesWithAct(); const hintText = Localize.translateLocal('loginForm.loginForm'); const loginForm = screen.queryAllByLabelText(hintText); expect(loginForm).toHaveLength(1);