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

translate invite member to room #30927

Merged
merged 41 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e57cfbc
translate invite member to room
namhihi237 Nov 6, 2023
2cf8aef
fix test
namhihi237 Nov 7, 2023
a31bdd1
move translate
namhihi237 Nov 7, 2023
1c51565
merge main
namhihi237 Nov 7, 2023
8c28a44
fix translate key
namhihi237 Nov 7, 2023
5296fa5
fix lint
namhihi237 Nov 7, 2023
1a9fa94
Merge branch 'main' into fix-39987-translate-invite-member
namhihi237 Nov 20, 2023
201e78d
update new change translate
namhihi237 Nov 20, 2023
f7c36f8
fix prettier
namhihi237 Nov 20, 2023
794dd7a
remove space
namhihi237 Nov 20, 2023
5a35607
fix reuse get message
namhihi237 Nov 20, 2023
3a95793
refactor, build link room
namhihi237 Nov 22, 2023
b8326c7
refactor
namhihi237 Nov 22, 2023
9f7ee8d
merge main
namhihi237 Nov 23, 2023
dd0e9c3
add target for link
namhihi237 Nov 23, 2023
a6693d0
fix: some convetion and refactor
namhihi237 Nov 23, 2023
2c2f790
fix: handle comma
namhihi237 Nov 24, 2023
6501526
fix: type and logic mention
namhihi237 Nov 27, 2023
0ef7db8
fix: typo
namhihi237 Nov 27, 2023
1dcc216
fix: name convention
namhihi237 Nov 27, 2023
f1630e1
merge main
namhihi237 Nov 27, 2023
a2e6fe9
update minor
namhihi237 Nov 27, 2023
7013b0a
fix minor
namhihi237 Nov 27, 2023
0019172
fix: update name fuc and remove type
namhihi237 Nov 28, 2023
bce6a22
refactor
namhihi237 Nov 28, 2023
00fb67c
remove comment and keep changelog
namhihi237 Nov 28, 2023
162670f
refactor
namhihi237 Nov 28, 2023
9d6ef34
update translate
namhihi237 Nov 28, 2023
333ce90
fix translate
namhihi237 Nov 28, 2023
c624fe2
fix translate with comma
namhihi237 Nov 29, 2023
5de71d9
merge main
namhihi237 Nov 29, 2023
b6c9c93
Merge branch 'main' into fix-39987-translate-invite-member
namhihi237 Nov 29, 2023
c615c01
refactor
namhihi237 Nov 29, 2023
b8e581e
Implement Localize.formatMessageElementList
cubuspl42 Nov 29, 2023
c216c93
refactor use Intl handle listing
namhihi237 Nov 29, 2023
4d403ab
remove new line
namhihi237 Nov 29, 2023
c00f6a2
Merge branch 'main' into fix-39987-translate-invite-member
namhihi237 Nov 30, 2023
0dea62f
update comment
namhihi237 Nov 30, 2023
9fc39f7
merge main
namhihi237 Dec 1, 2023
bd793d3
merge main
namhihi237 Dec 5, 2023
243f932
fix lint
namhihi237 Dec 5, 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
6 changes: 6 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,12 @@ export default {
invitePeople: 'Invite new members',
genericFailureMessage: 'An error occurred inviting the user to the workspace, please try again.',
pleaseEnterValidLogin: `Please ensure the email or phone number is valid (e.g. ${CONST.EXAMPLE_PHONE_NUMBER}).`,
user: 'user',
users: 'users',
invited: 'invited',
removed: 'removed',
namhihi237 marked this conversation as resolved.
Show resolved Hide resolved
to: 'to',
from: 'from',
},
inviteMessage: {
inviteMessageTitle: 'Add message',
Expand Down
6 changes: 6 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,12 @@ export default {
invitePeople: 'Invitar nuevos miembros',
genericFailureMessage: 'Se produjo un error al invitar al usuario al espacio de trabajo. Vuelva a intentarlo..',
pleaseEnterValidLogin: `Asegúrese de que el correo electrónico o el número de teléfono sean válidos (p. ej. ${CONST.EXAMPLE_PHONE_NUMBER}).`,
user: 'usuario',
users: 'usuarias',
invited: 'invitada',
removed: 'eliminado',
to: 'a',
from: 'de',
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you remind me if these translations were approved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I requested approval here

},
inviteMessage: {
inviteMessageTitle: 'Añadir un mensaje',
Expand Down
179 changes: 175 additions & 4 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,47 @@ import OnyxUtils from 'react-native-onyx/lib/utils';
import {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {ActionName} from '@src/types/onyx/OriginalMessage';
import {ActionName, ChangeLogOriginalMessage} from '@src/types/onyx/OriginalMessage';
import Report from '@src/types/onyx/Report';
import ReportAction, {ReportActions} from '@src/types/onyx/ReportAction';
import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction';
import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';
import * as CollectionUtils from './CollectionUtils';
import * as Environment from './Environment/Environment';
import isReportMessageAttachment from './isReportMessageAttachment';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
import Log from './Log';
import * as PersonalDetailsUtils from './PersonalDetailsUtils';
Copy link
Contributor

Choose a reason for hiding this comment

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

This caused regression of dependency cycle

console

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see en.ts import ReportActionsUtils to use here

App/src/languages/en.ts

Lines 428 to 430 in 2feaac8

editAction: ({action}: EditActionParams) => `Edit ${ReportActionsUtils.isMoneyRequestAction(action) ? 'request' : 'comment'}`,
deleteAction: ({action}: DeleteActionParams) => `Delete ${ReportActionsUtils.isMoneyRequestAction(action) ? 'request' : 'comment'}`,
deleteConfirmation: ({action}: DeleteConfirmationParams) => `Are you sure you want to delete this ${ReportActionsUtils.isMoneyRequestAction(action) ? 'request' : 'comment'}?`,

And in the ReportActionsUtils.ts we import Localize.ts
=> Resolve: we can in en.ts we can remove ReportActionsUtils and use logic check like this

editAction: ({action}: EditActionParams) => `Edit ${action?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? 'request' : 'comment'}`,

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. I also don't like importing any utils in language file


type LastVisibleMessage = {
lastMessageTranslationKey?: string;
lastMessageText: string;
lastMessageHtml?: string;
};

type MemberChangeMessageElementBase = {
readonly kind: string;
readonly content: string;
};

type MemberChangeMessageTextElement = {
readonly kind: 'text';
readonly content: string;
};

type MemberChangeMessageUserMentionElement = {
readonly kind: 'userMention';
readonly accountID: number;
} & MemberChangeMessageElementBase;

type MemberChangeMessageRoomReferenceElement = {
readonly kind: 'roomReference';
readonly roomName: string;
readonly roomID: number;
} & MemberChangeMessageElementBase;

type MemberChangeMessageElement = MemberChangeMessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement;

const allReports: OnyxCollection<Report> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down Expand Up @@ -100,7 +126,7 @@ function isReimbursementQueuedAction(reportAction: OnyxEntry<ReportAction>) {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED;
}

function isChannelLogMemberAction(reportAction: OnyxEntry<ReportAction>) {
function isMemberChangeAction(reportAction: OnyxEntry<ReportAction>) {
return (
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ||
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM ||
Expand All @@ -109,6 +135,10 @@ function isChannelLogMemberAction(reportAction: OnyxEntry<ReportAction>) {
);
}

function isInviteMemberAction(reportAction: OnyxEntry<ReportAction>) {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM;
}

/**
* Returns whether the comment is a thread parent message/the first message in a thread
*/
Expand Down Expand Up @@ -635,6 +665,145 @@ function isNotifiableReportAction(reportAction: OnyxEntry<ReportAction>): boolea
return actions.includes(reportAction.actionName);
}

function getMemberChangeMessageElements(reportAction: OnyxEntry<ReportAction>): MemberChangeMessageElement[] {
Copy link
Contributor

@cubuspl42 cubuspl42 Nov 28, 2023

Choose a reason for hiding this comment

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

I request a review of this pattern.

This function builds a list of "elements", which contain translated parts of a message with some markers, abstracted from how they are presented. This is a kind of a ViewModel.

An example string this message builds looks like this:

invited @alice, @bob, and @charlie to #room2

We present these elements in two different ways:

  • as an HTML fragment (for rendering)
  • as a plain text (for copying to clipboard)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Jules approved the PR; we're good to go

const messageElements: MemberChangeMessageElement[] = [];
const isInviteAction = isInviteMemberAction(reportAction);

const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed');

messageElements.push({
namhihi237 marked this conversation as resolved.
Show resolved Hide resolved
kind: 'text',
content: `${verb} `,
});

const originalMessage = reportAction?.originalMessage as ChangeLogOriginalMessage;
const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? [];
const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0);

const mentions = targetAccountIDs.map((accountID) => {
const personalDetail = personalDetails.find((personal) => personal.accountID === accountID);

if (personalDetail) {
const displayNameOrLogin =
LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || (personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden'));
return {content: `@${displayNameOrLogin}`, accountID};
}
return {content: `@${Localize.translateLocal('common.hidden')}`, accountID};
namhihi237 marked this conversation as resolved.
Show resolved Hide resolved
});

const lastMention = mentions.pop();
if (!lastMention) {
return [];
}

if (mentions.length === 0) {
messageElements.push({
kind: 'userMention',
content: lastMention.content,
accountID: lastMention.accountID,
});
} else if (mentions.length === 1) {
messageElements.push(
{
kind: 'userMention',
content: mentions[0].content,
accountID: mentions[0].accountID,
},
{
kind: 'text',
content: ` ${Localize.translateLocal('common.and')} `,
},
{
kind: 'userMention',
content: lastMention.content,
accountID: lastMention.accountID,
},
);
} else {
mentions.forEach((mention) => {
messageElements.push(
{
kind: 'userMention',
accountID: mention.accountID,
content: `${mention.content}`,
},
{
kind: 'text',
content: `, `,
namhihi237 marked this conversation as resolved.
Show resolved Hide resolved
},
);
});

messageElements.push(
{
kind: 'text',
content: `${Localize.translateLocal('common.and')} `,
},
{
kind: 'userMention',
content: lastMention.content,
accountID: lastMention.accountID,
},
);
}

const roomName = originalMessage?.roomName;
if (roomName) {
const preposition = isInviteAction ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `;

if (originalMessage.reportID) {
messageElements.push(
{
kind: 'text',
content: preposition,
},
{
kind: 'roomReference',
roomName,
roomID: originalMessage.reportID,
content: roomName,
},
);
}
}

return messageElements;
}

function getMemberChangeMessageFragment(reportAction: OnyxEntry<ReportAction>): Message {
const messageElements: MemberChangeMessageElement[] = getMemberChangeMessageElements(reportAction);
const html = messageElements
.map((messageElement) => {
switch (messageElement.kind) {
case 'userMention':
return `<mention-user accountID=${messageElement.accountID}></mention-user>`;
case 'roomReference':
return `<a href="${environmentURL}/r/${messageElement.roomID}" target="_blank">${messageElement.roomName}</a>`;
default:
return messageElement.content;
}
})
.join('');

return {
html: `<muted-text>${html}</muted-text>`,
text: reportAction?.message ? reportAction?.message[0].text : '',
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
};
}

/**
* Return room channel log message
namhihi237 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {Object} reportAction
namhihi237 marked this conversation as resolved.
Show resolved Hide resolved
* @returns {String}
*/

namhihi237 marked this conversation as resolved.
Show resolved Hide resolved
function getMemberChangeMessagePlainText(reportAction: OnyxEntry<ReportAction>): string {
const messageElements = getMemberChangeMessageElements(reportAction);
return messageElements.map((element) => element.content).join('');
}

/**
* Helper method to determine if the provided accountID has made a request on the specified report.
*
Expand Down Expand Up @@ -697,7 +866,9 @@ export {
shouldReportActionBeVisibleAsLastAction,
hasRequestFromCurrentAccount,
getFirstVisibleReportActionID,
isChannelLogMemberAction,
isMemberChangeAction,
getMemberChangeMessageFragment,
getMemberChangeMessagePlainText,
};

export type {LastVisibleMessage};
41 changes: 1 addition & 40 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {Beta, Login, PersonalDetails, Policy, PolicyTags, Report, ReportAction, Transaction} from '@src/types/onyx';
import {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import {ChangeLog, IOUMessage, OriginalMessageActionName} from '@src/types/onyx/OriginalMessage';
import {IOUMessage, OriginalMessageActionName} from '@src/types/onyx/OriginalMessage';
import {Message, ReportActions} from '@src/types/onyx/ReportAction';
import {Receipt, WaypointCollection} from '@src/types/onyx/Transaction';
import DeepValueOf from '@src/types/utils/DeepValueOf';
Expand Down Expand Up @@ -4138,44 +4138,6 @@ function isReportDraft(report: OnyxEntry<Report>): boolean {
return isExpenseReport(report) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS.OPEN;
}

/**
* Return room channel log display message
*/
function getChannelLogMemberMessage(reportAction: OnyxEntry<ReportAction>): string {
const verb =
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM
? 'invited'
: 'removed';

const mentions = (reportAction?.originalMessage as ChangeLog)?.targetAccountIDs?.map(() => {
const personalDetail = allPersonalDetails?.accountID;
const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? '') || (personalDetail?.displayName ?? '') || Localize.translateLocal('common.hidden');
return `@${displayNameOrLogin}`;
});

const lastMention = mentions?.pop();
let message = '';

if (mentions?.length === 0) {
message = `${verb} ${lastMention}`;
} else if (mentions?.length === 1) {
message = `${verb} ${mentions?.[0]} and ${lastMention}`;
} else {
message = `${verb} ${mentions?.join(', ')}, and ${lastMention}`;
}

const roomName = (reportAction?.originalMessage as ChangeLog)?.roomName ?? '';
if (roomName) {
const preposition =
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM
? ' to'
: ' from';
message += `${preposition} ${roomName}`;
}

return message;
}

/**
* Checks if a report is a group chat.
*
Expand Down Expand Up @@ -4377,7 +4339,6 @@ export {
parseReportRouteParams,
getReimbursementQueuedActionMessage,
getPersonalDetailsForAccountID,
getChannelLogMemberMessage,
getRoom,
shouldDisableWelcomeMessage,
canEditWriteCapability,
Expand Down
10 changes: 5 additions & 5 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,17 @@ function getOptionData(
const targetAccountIDs = lastAction?.originalMessage?.targetAccountIDs ?? [];
const verb =
lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM
? 'invited'
: 'removed';
const users = targetAccountIDs.length > 1 ? 'users' : 'user';
? Localize.translate(preferredLocale, 'workspace.invite.invited')
: Localize.translate(preferredLocale, 'workspace.invite.removed');
const users = Localize.translate(preferredLocale, targetAccountIDs.length > 1 ? 'workspace.invite.users' : 'workspace.invite.user');
result.alternateText = `${verb} ${targetAccountIDs.length} ${users}`;

const roomName = lastAction?.originalMessage?.roomName ?? '';
if (roomName) {
const preposition =
lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM
? ' to'
: ' from';
? ` ${Localize.translate(preferredLocale, 'workspace.invite.to')}`
: ` ${Localize.translate(preferredLocale, 'workspace.invite.from')}`;
result.alternateText += `${preposition} ${roomName}`;
}
} else if (lastAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastActorDisplayName && lastMessageTextFromReport) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ export default [
} else if (ReportActionsUtils.isMoneyRequestAction(reportAction)) {
const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction);
Clipboard.setString(displayMessage);
} else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) {
const logMessage = ReportUtils.getChannelLogMemberMessage(reportAction);
} else if (ReportActionsUtils.isMemberChangeAction(reportAction)) {
const logMessage = ReportActionsUtils.getMemberChangeMessagePlainText(reportAction);
Clipboard.setString(logMessage);
} else if (content) {
const parser = new ExpensiMark();
Expand Down
15 changes: 15 additions & 0 deletions src/pages/home/report/ReportActionItemMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import useThemeStyles from '@styles/useThemeStyles';
import CONST from '@src/CONST';
import TextCommentFragment from './comment/TextCommentFragment';
import ReportActionItemFragment from './ReportActionItemFragment';
import reportActionPropTypes from './reportActionPropTypes';

Expand Down Expand Up @@ -40,6 +41,20 @@ function ReportActionItemMessage(props) {
const styles = useThemeStyles();
const fragments = _.compact(props.action.previousMessage || props.action.message);
const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action);
if (ReportActionsUtils.isMemberChangeAction(props.action)) {
const fragment = ReportActionsUtils.getMemberChangeMessageFragment(props.action);

return (
<TextCommentFragment
Copy link
Contributor

Choose a reason for hiding this comment

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

This caused #33305 where long emails were overflowing the screen for the invite message. Wrapping this with a <View> that has the relevant chatItemMessage style fixes it (more details here).

fragment={fragment}
displayAsGroup={props.displayAsGroup}
style={props.style}
source=""
styleAsDeleted={false}
/>
);
}

let iouMessage;
if (isIOUReport) {
const iouReportID = lodashGet(props.action, 'originalMessage.IOUReportID');
Expand Down
Loading
Loading