-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feat: Build optimistic Edit Task actions #36768
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
aefde12
Build optimistic Edit Task actions
paultsimura ab40861
Merge branch 'main' into fix/36196-edit-task
paultsimura c4dcda1
DRY
paultsimura 2b92139
Merge branch 'main' into fix/36196-edit-task
paultsimura adc314e
No longer hide the TASKEDITED actions
paultsimura 90186b2
Merge branch 'main' into fix/36196-edit-task
paultsimura e76fa93
Merge branch 'main' into fix/36196-edit-task
paultsimura c35a510
Reformat task-related actions
paultsimura 281e4a6
Merge branch 'main' into fix/36196-edit-task
paultsimura d904a6e
Reuse functions to get current user data
paultsimura 014ac7a
Merge branch 'main' into fix/36196-edit-task
paultsimura 0c7362a
Merge branch 'main' into fix/36196-edit-task
paultsimura f89025c
Merge branch 'main' into fix/36196-edit-task
paultsimura a86a2f7
Localize taskEdited messages
paultsimura f3e618e
Revert "Localize taskEdited messages"
paultsimura c1a0fd0
Merge branch 'main' into fix/36196-edit-task
paultsimura e7031e4
Fix TS error
paultsimura 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 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -28,6 +28,7 @@ import type { | |
ReportAction, | ||
ReportMetadata, | ||
Session, | ||
Task, | ||
Transaction, | ||
TransactionViolation, | ||
} from '@src/types/onyx'; | ||
|
@@ -515,6 +516,14 @@ Onyx.connect({ | |
}, | ||
}); | ||
|
||
function getCurrentUserAvatarOrDefault(): UserUtils.AvatarSource { | ||
return currentUserPersonalDetails?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID); | ||
} | ||
|
||
function getCurrentUserDisplayNameOrEmail(): string | undefined { | ||
return currentUserPersonalDetails?.displayName ?? currentUserEmail; | ||
} | ||
|
||
function getChatType(report: OnyxEntry<Report> | Participant | EmptyObject): ValueOf<typeof CONST.REPORT.CHAT_TYPE> | undefined { | ||
return report?.chatType; | ||
} | ||
|
@@ -1834,7 +1843,7 @@ function buildOptimisticCancelPaymentReportAction(expenseReportID: string, amoun | |
person: [ | ||
{ | ||
style: 'strong', | ||
text: currentUserPersonalDetails?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
type: 'TEXT', | ||
}, | ||
], | ||
|
@@ -3171,14 +3180,14 @@ function buildOptimisticIOUReportAction( | |
actionName: CONST.REPORT.ACTIONS.TYPE.IOU, | ||
actorAccountID: currentUserAccountID, | ||
automatic: false, | ||
avatar: currentUserPersonalDetails?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID), | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
isAttachment: false, | ||
originalMessage, | ||
message: getIOUReportActionMessage(iouReportID, type, amount, comment, currency, paymentType, isSettlingUp), | ||
person: [ | ||
{ | ||
style: 'strong', | ||
text: currentUserPersonalDetails?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
type: 'TEXT', | ||
}, | ||
], | ||
|
@@ -3204,14 +3213,14 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e | |
actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, | ||
actorAccountID: currentUserAccountID, | ||
automatic: false, | ||
avatar: currentUserPersonalDetails?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID), | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
isAttachment: false, | ||
originalMessage, | ||
message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.APPROVED, Math.abs(amount), '', currency), | ||
person: [ | ||
{ | ||
style: 'strong', | ||
text: currentUserPersonalDetails?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
type: 'TEXT', | ||
}, | ||
], | ||
|
@@ -3246,14 +3255,14 @@ function buildOptimisticMovedReportAction(fromPolicyID: string, toPolicyID: stri | |
actionName: CONST.REPORT.ACTIONS.TYPE.MOVED, | ||
actorAccountID: currentUserAccountID, | ||
automatic: false, | ||
avatar: currentUserPersonalDetails?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID), | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
isAttachment: false, | ||
originalMessage, | ||
message: movedActionMessage, | ||
person: [ | ||
{ | ||
style: 'strong', | ||
text: currentUserPersonalDetails?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
type: 'TEXT', | ||
}, | ||
], | ||
|
@@ -3279,14 +3288,14 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, | |
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED, | ||
actorAccountID: currentUserAccountID, | ||
automatic: false, | ||
avatar: currentUserPersonalDetails?.avatar ?? UserUtils.getDefaultAvatar(currentUserAccountID), | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
isAttachment: false, | ||
originalMessage, | ||
message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.SUBMITTED, Math.abs(amount), '', currency), | ||
person: [ | ||
{ | ||
style: 'strong', | ||
text: currentUserPersonalDetails?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
type: 'TEXT', | ||
}, | ||
], | ||
|
@@ -3352,7 +3361,7 @@ function buildOptimisticModifiedExpenseReportAction( | |
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE, | ||
actorAccountID: currentUserAccountID, | ||
automatic: false, | ||
avatar: currentUserPersonalDetails?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID), | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
created: DateUtils.getDBTime(), | ||
isAttachment: false, | ||
message: [ | ||
|
@@ -3435,7 +3444,7 @@ function buildOptimisticTaskReportAction(taskReportID: string, actionName: Origi | |
actionName, | ||
actorAccountID: currentUserAccountID, | ||
automatic: false, | ||
avatar: currentUserPersonalDetails?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID), | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
isAttachment: false, | ||
originalMessage, | ||
message: [ | ||
|
@@ -3511,10 +3520,6 @@ function buildOptimisticChatReport( | |
}; | ||
} | ||
|
||
function getCurrentUserAvatarOrDefault(): UserUtils.AvatarSource { | ||
return allPersonalDetails?.[currentUserAccountID ?? '']?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID); | ||
} | ||
|
||
/** | ||
* Returns the necessary reportAction onyx data to indicate that the chat has been created optimistically | ||
* @param [created] - Action created time | ||
|
@@ -3541,7 +3546,7 @@ function buildOptimisticCreatedReportAction(emailCreatingAction: string, created | |
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.TEXT, | ||
style: 'strong', | ||
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
}, | ||
], | ||
automatic: false, | ||
|
@@ -3577,7 +3582,7 @@ function buildOptimisticRenamedRoomReportAction(newName: string, oldName: string | |
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.TEXT, | ||
style: 'strong', | ||
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
}, | ||
], | ||
originalMessage: { | ||
|
@@ -3618,11 +3623,11 @@ function buildOptimisticHoldReportAction(comment: string, created = DateUtils.ge | |
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.TEXT, | ||
style: 'strong', | ||
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
}, | ||
], | ||
automatic: false, | ||
avatar: allPersonalDetails?.[currentUserAccountID ?? '']?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID), | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
created, | ||
shouldShow: true, | ||
}; | ||
|
@@ -3649,42 +3654,79 @@ function buildOptimisticUnHoldReportAction(created = DateUtils.getDBTime()): Opt | |
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.TEXT, | ||
style: 'normal', | ||
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
}, | ||
], | ||
automatic: false, | ||
avatar: allPersonalDetails?.[currentUserAccountID ?? '']?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID), | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
created, | ||
shouldShow: true, | ||
}; | ||
} | ||
|
||
/** | ||
* Returns the necessary reportAction onyx data to indicate that a task report has been edited | ||
*/ | ||
function buildOptimisticEditedTaskReportAction(emailEditingTask: string): OptimisticEditedTaskReportAction { | ||
function buildOptimisticEditedTaskFieldReportAction({title, description}: Task): OptimisticEditedTaskReportAction { | ||
// We do not modify title & description in one request, so we need to create a different optimistic action for each field modification | ||
let field = ''; | ||
let value = ''; | ||
if (title !== undefined) { | ||
field = 'task title'; | ||
value = title; | ||
} else if (description !== undefined) { | ||
field = 'description'; | ||
value = description; | ||
} | ||
|
||
let changelog = 'edited this task'; | ||
if (field && value) { | ||
changelog = `updated the ${field} to ${value}`; | ||
} else if (field) { | ||
changelog = `removed the ${field}`; | ||
} | ||
|
||
return { | ||
reportActionID: NumberUtils.rand64(), | ||
actionName: CONST.REPORT.ACTIONS.TYPE.TASKEDITED, | ||
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
actorAccountID: currentUserAccountID, | ||
message: [ | ||
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.COMMENT, | ||
text: changelog, | ||
html: changelog, | ||
}, | ||
], | ||
person: [ | ||
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.TEXT, | ||
style: 'strong', | ||
text: emailEditingTask, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
}, | ||
], | ||
automatic: false, | ||
avatar: getCurrentUserAvatarOrDefault(), | ||
created: DateUtils.getDBTime(), | ||
shouldShow: false, | ||
}; | ||
} | ||
|
||
function buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID: number): OptimisticEditedTaskReportAction { | ||
return { | ||
reportActionID: NumberUtils.rand64(), | ||
actionName: CONST.REPORT.ACTIONS.TYPE.TASKEDITED, | ||
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
actorAccountID: currentUserAccountID, | ||
message: [ | ||
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.TEXT, | ||
style: 'normal', | ||
text: ' edited this task', | ||
type: CONST.REPORT.MESSAGE.TYPE.COMMENT, | ||
text: `assigned to ${getDisplayNameForParticipant(assigneeAccountID)}`, | ||
html: `assigned to <mention-user accountID=${assigneeAccountID}></mention-user>`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line created a bug where LHN won't show the user. See more details on #45167 |
||
}, | ||
], | ||
person: [ | ||
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.TEXT, | ||
style: 'strong', | ||
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
}, | ||
], | ||
automatic: false, | ||
|
@@ -3727,7 +3769,7 @@ function buildOptimisticClosedReportAction(emailClosingReport: string, policyNam | |
{ | ||
type: CONST.REPORT.MESSAGE.TYPE.TEXT, | ||
style: 'strong', | ||
text: allPersonalDetails?.[currentUserAccountID ?? '']?.displayName ?? currentUserEmail, | ||
text: getCurrentUserDisplayNameOrEmail(), | ||
}, | ||
], | ||
reportActionID: NumberUtils.rand64(), | ||
|
@@ -5183,7 +5225,8 @@ export { | |
buildOptimisticClosedReportAction, | ||
buildOptimisticCreatedReportAction, | ||
buildOptimisticRenamedRoomReportAction, | ||
buildOptimisticEditedTaskReportAction, | ||
buildOptimisticEditedTaskFieldReportAction, | ||
buildOptimisticChangedTaskAssigneeReportAction, | ||
buildOptimisticIOUReport, | ||
buildOptimisticApprovedReportAction, | ||
buildOptimisticMovedReportAction, | ||
|
This file contains 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
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line will introduce the regression #37976, causing the last message text to become multiple lines in the LHN. So I think in the future whenever we develop a feature that relate to text, we should also test the text overflow case.