Skip to content
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

fix: remove getDisplayNameForTypingIndicator #31495

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a57d229
fix: remove getDisplayNameForTypingIndicator
koko57 Nov 17, 2023
9093ff3
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Nov 20, 2023
6358b1e
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Nov 21, 2023
1ff3017
fix: apply requested changes
koko57 Nov 21, 2023
b30cb29
fix: run prettier
koko57 Nov 21, 2023
921a070
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Nov 30, 2023
2ffcec2
fix: destructure props
koko57 Nov 30, 2023
5fec558
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Dec 1, 2023
fe1e320
fix: apply requested changes
koko57 Dec 1, 2023
e7d667c
fix: run prettier
koko57 Dec 1, 2023
8af4811
fix: minor fix
koko57 Dec 1, 2023
9d26c00
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Dec 6, 2023
c0a9c6a
fix: minor fix
koko57 Dec 6, 2023
e6ed623
fix: display name that should be hidden as someone
koko57 Dec 6, 2023
e186fd3
fix: run prettier
koko57 Dec 6, 2023
3ec5e40
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Dec 8, 2023
88cf035
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Dec 11, 2023
31df21e
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Dec 12, 2023
8fb1f2f
fix: resolve conflicts
koko57 Dec 18, 2023
69ba3a0
fix: prettier
koko57 Dec 18, 2023
c1435f4
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Dec 28, 2023
a4e422f
Merge branch 'main' into refactor/31312-consolidate-getdisplayname-me…
koko57 Dec 29, 2023
10f49fa
fix: do not check for login if is present in personalDetails
koko57 Dec 29, 2023
1bab5a9
fix: lint
koko57 Dec 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,6 @@ function getDisplayName(login: string, personalDetail: Pick<PersonalDetails, 'fi
return fullName || userLogin;
}

/**
* @param [defaultDisplayName] display name to use if user details don't exist in Onyx or if
* found details don't include the user's displayName or login
*/
function getDisplayNameForTypingIndicator(userAccountIDOrLogin: string, defaultDisplayName = ''): string {
// Try to convert to a number, which means we have an accountID
const accountID = Number(userAccountIDOrLogin);

// If the user is typing on OldDot, userAccountIDOrLogin will be a string (the user's login),
// so Number(string) is NaN. Search for personalDetails by login to get the display name.
if (Number.isNaN(accountID)) {
const detailsByLogin = Object.entries(allPersonalDetails ?? {}).find(([, value]) => value?.login === userAccountIDOrLogin)?.[1];

// It's possible for displayName to be empty string, so we must use "||" to fallback to userAccountIDOrLogin.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return detailsByLogin?.displayName || userAccountIDOrLogin;
}

const detailsByAccountID = allPersonalDetails?.[accountID];

// It's possible for displayName to be empty string, so we must use "||" to fallback to login or defaultDisplayName.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return detailsByAccountID?.displayName || detailsByAccountID?.login || defaultDisplayName;
}

/**
* Gets the first and last name from the user's personal details.
* If the login is the same as the displayName, then they don't exist,
Expand Down Expand Up @@ -584,7 +559,6 @@ export {
extractFirstAndLastNameFromAvailableDetails,
getCountryISO,
getDisplayName,
getDisplayNameForTypingIndicator,
getPrivatePersonalDetails,
openPersonalDetailsPage,
openPublicProfilePage,
Expand Down
47 changes: 22 additions & 25 deletions src/pages/home/report/ReportTypingIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,39 @@ import PropTypes from 'prop-types';
import React, {useMemo} from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import networkPropTypes from '@components/networkPropTypes';
import {withNetwork} from '@components/OnyxProvider';
import Text from '@components/Text';
import TextWithEllipsis from '@components/TextWithEllipsis';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import compose from '@libs/compose';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import useThemeStyles from '@styles/useThemeStyles';
import * as PersonalDetails from '@userActions/PersonalDetails';
import ONYXKEYS from '@src/ONYXKEYS';

const propTypes = {
/** Key-value pairs of user accountIDs/logins and whether or not they are typing. Keys are accountIDs or logins. */
userTypingStatuses: PropTypes.objectOf(PropTypes.bool),

/** Information about the network */
network: networkPropTypes.isRequired,

...withLocalizePropTypes,
};

const defaultProps = {
userTypingStatuses: {},
};

function ReportTypingIndicator(props) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're touching this component, can we destructure props?

const {translate} = useLocalize();
const {isOffline} = useNetwork();

const styles = useThemeStyles();
const usersTyping = useMemo(() => _.filter(_.keys(props.userTypingStatuses), (loginOrAccountID) => props.userTypingStatuses[loginOrAccountID]), [props.userTypingStatuses]);
// If we are offline, the user typing statuses are not up-to-date so do not show them
if (props.network.isOffline) {
if (isOffline) {
Copy link
Contributor

@situchan situchan Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isOffline) {
if (isOffline || !firstUserTyping) {

return null;
}

const firstUserTyping = usersTyping[0];
const firstUserTypingID = Number.isNaN(firstUserTyping) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the data structure of usersTyping[0]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabioh8010 usersTyping is an array of the ids of the users typing in the report, so the usersTyping[0] is a string or a number

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having some difficult to understand what this line is doing 😅

For example, are you using Number.isNaN(firstUserTyping) for checking if string or number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it was the logic from the removed method that I moved here. But I forgot to wrap the usersTyping[0] in Number as it is supposed to be a string (I will check it for sure)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PersonalDetailsUtils.getAccountIDsByLogins does a traverse on the personalDetails - imo worth memoising this call, could you please try it?

const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false);

const numUsersTyping = _.size(usersTyping);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const numUsersTyping = _.size(usersTyping);

// Decide on the Text element that will hold the display based on the number of users that are typing.
Expand All @@ -44,8 +45,8 @@ function ReportTypingIndicator(props) {
case 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace switch/case with ? :

        return usersTyping.length === 1 ? <TextWithEllipsis /> : <Text />

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the components for this are not one-liners I'd rather do it with an if statement, it'll be more readable

return (
<TextWithEllipsis
leadingText={PersonalDetails.getDisplayNameForTypingIndicator(usersTyping[0], props.translate('common.someone'))}
trailingText={` ${props.translate('reportTypingIndicator.isTyping')}`}
leadingText={firstUserTypingDisplayName || translate('common.someone')}
trailingText={` ${translate('reportTypingIndicator.isTyping')}`}
textStyle={[styles.chatItemComposeSecondaryRowSubText]}
wrapperStyle={[styles.chatItemComposeSecondaryRow, styles.flex1]}
leadingTextParentStyle={styles.chatItemComposeSecondaryRowOffset}
Expand All @@ -58,8 +59,8 @@ function ReportTypingIndicator(props) {
style={[styles.chatItemComposeSecondaryRowSubText, styles.chatItemComposeSecondaryRowOffset]}
numberOfLines={1}
>
{props.translate('reportTypingIndicator.multipleUsers')}
{` ${props.translate('reportTypingIndicator.areTyping')}`}
{translate('reportTypingIndicator.multipleUsers')}
{` ${translate('reportTypingIndicator.areTyping')}`}
</Text>
);
}
Expand All @@ -69,13 +70,9 @@ ReportTypingIndicator.propTypes = propTypes;
ReportTypingIndicator.defaultProps = defaultProps;
ReportTypingIndicator.displayName = 'ReportTypingIndicator';

export default compose(
withLocalize,
withNetwork(),
withOnyx({
userTypingStatuses: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING}${reportID}`,
initialValue: {},
},
}),
)(ReportTypingIndicator);
export default withOnyx({
userTypingStatuses: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING}${reportID}`,
initialValue: {},
},
})(ReportTypingIndicator);
Loading