-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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: task not working in self dm through shortcut #39107
Conversation
@Santhosh-Sellavel Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
src/libs/ReportUtils.ts
Outdated
return ( | ||
Object.values(reports ?? {}).find((report) => { | ||
return report?.reportID === reportID; | ||
}) ?? null |
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.
I am very confused by this... I think it's doing nothing? ie: if it is null then default to null
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.
why not allReports[
${ONYXKEYS.COLLECTION.REPORT}${reportID}]
?
return (
allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]
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.
If it sends null then the existing behaviour create new optimistic report which is expected because there is no report found with that reportID
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.
@ishpaul777 changing it to your suggestion as it returns in O(1) and works as expected also
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.
I am just curious, why do we need a reports
param 🤔
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.
I copied the above function and forgot to remove the reports param 😅
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.
Actually we already have this utility
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.
@ishpaul777 I tested every case where we create task. And in one case the shareToReportID
is empty:
Line 652 in b68937c
function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shareToReportID: string, isCurrentUser = false): OnyxEntry<OnyxTypes.Report> { |
In that case we can use the old existing behaviour. And if shareToReportID
is available we will get report directly by ID using utility function which is the cases we are solving i.e. selfDM
The code:
Line 659 in e542ba7
chatReport = ReportUtils.getChatByParticipants([assigneeAccountID]); |
src/libs/actions/Task.ts
Outdated
@@ -653,7 +653,8 @@ function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shar | |||
let chatReport: OnyxEntry<OnyxTypes.Report> = null; | |||
|
|||
if (!isCurrentUser) { | |||
chatReport = ReportUtils.getChatByParticipants([assigneeAccountID]); | |||
const reportID = shareDestination; |
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.
The param name shareDestination
is a reportID? If so, can we rename this to something like shareToReportID
?
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.
Yes, it's reportID. Changing that to shareToReportID
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.
Looks good but there's a lint error
Testing other task use cases to make sure everything is working as expected. |
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.
Actually now that I am thinking about this more... I think this might be wrong.
Nothing ensures that the report is loaded here, so we should not assume it is.
Also, we already have the report object in the (all?) callers of setAssigneeValue, so instead of what we did here, we should change setAssigneeValue to receive the full report object directly from its callers. No?
src/libs/actions/Task.ts
Outdated
let chatReport: OnyxEntry<OnyxTypes.Report> = null; | ||
|
||
if (!isCurrentUser) { | ||
chatReport = ReportUtils.getChatByParticipants([assigneeAccountID]); | ||
const reportID = shareToReportID; | ||
chatReport = ReportUtils.getChatByReportID(reportID); |
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.
orrr we already load allReports in actions/Task we can just use it here
chatReport = ReportUtils.getChatByReportID(reportID); | |
chatReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] |
@iwiznia I have tested all conditions for task and for some case we have shareToReportID in setAssigneeValue as empty. In that case we can use the existing behaviour and If ![]() |
Actually we don't have report available at some places and we are passing App/src/pages/tasks/TaskAssigneeSelectorModal.tsx Lines 177 to 200 in b68937c
|
Yeah and isn't that a problem? Your code assumes the report will be loaded, but nothing is ensuring that, so the users of this component need to ensure we are loading the needed reports... no? |
@iwiznia I have just updated |
src/libs/actions/Task.ts
Outdated
@@ -652,11 +652,16 @@ function setAssigneeChatReport(chatReport: OnyxTypes.Report) { | |||
* If there is no existing chat, it creates an optimistic chat report | |||
* It also sets the shareDestination as that chat report if a share destination isn't already set | |||
*/ | |||
function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shareDestination: string, isCurrentUser = false): OnyxEntry<OnyxTypes.Report> { | |||
function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shareToReportID: string, isCurrentUser = false, report: OnyxEntry<OnyxTypes.Report>): OnyxEntry<OnyxTypes.Report> { |
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.
function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shareToReportID: string, isCurrentUser = false, report: OnyxEntry<OnyxTypes.Report>): OnyxEntry<OnyxTypes.Report> { | |
function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shareToReportID: string, isCurrentUser = false, chatReport: OnyxEntry<OnyxTypes.Report>): OnyxEntry<OnyxTypes.Report> { |
src/libs/actions/Task.ts
Outdated
chatReport = report; | ||
} | ||
else { | ||
chatReport = ReportUtils.getChatByParticipants([assigneeAccountID]); |
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.
Not sure how I feel about this. Is this correct in any real cases or is this always going to be wrong?
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.
There is one case where report is not available like in this cases:
App/src/pages/tasks/TaskAssigneeSelectorModal.tsx
Lines 177 to 200 in b68937c
if (report) { | |
if (option.accountID !== report.managerID) { | |
const assigneeChatReport = TaskActions.setAssigneeValue( | |
option?.login ?? '', | |
option?.accountID ?? -1, | |
report.reportID, | |
OptionsListUtils.isCurrentUser({...option, accountID: option?.accountID ?? -1, login: option?.login ?? ''}), | |
); | |
// Pass through the selected assignee | |
TaskActions.editTaskAssignee(report, session?.accountID ?? 0, option?.login ?? '', option?.accountID, assigneeChatReport); | |
} | |
Navigation.dismissModal(report.reportID); | |
// If there's no report, we're creating a new task | |
} else if (option.accountID) { | |
TaskActions.setAssigneeValue( | |
option?.login ?? '', | |
option.accountID, | |
task?.shareDestination ?? '', | |
OptionsListUtils.isCurrentUser({...option, accountID: option?.accountID ?? -1, login: option?.login ?? undefined}), | |
); | |
Navigation.goBack(ROUTES.NEW_TASK); | |
} | |
}, |
We are getting the report from route.param and they are null here:
App/src/pages/tasks/TaskAssigneeSelectorModal.tsx
Lines 105 to 115 in b68937c
const report: OnyxEntry<Report> = useMemo(() => { | |
if (!route.params?.reportID) { | |
return null; | |
} | |
if (report && !ReportUtils.isTaskReport(report)) { | |
Navigation.isNavigationReady().then(() => { | |
Navigation.dismissModal(report.reportID); | |
}); | |
} | |
return reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`] ?? null; | |
}, [reports, route]); |
In this example the above else condition is triggered. If we don't have this else condition then, it will assume that no report exists for this participant and it will create new optimistic report, which is wrong.
Closing this PR due to signed commits issue. This will be handled in #39215 |
Details
Fixed Issues
$#39049
PROPOSAL: #39049 (comment)
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
WhatsApp.Video.2024-03-28.at.12.47.03.AM.mp4
Android: mWeb Chrome
WhatsApp.Video.2024-03-28.at.12.47.05.AM.mp4
iOS: Native
ios-3.mp4
iOS: mWeb Safari
ios-3-web.mp4
MacOS: Chrome / Safari
2f93d786-c077-4943-a9b7-00433e040ee6.mp4
MacOS: Desktop
d2854dfd-f72e-407a-b7c0-8a9489909b44.mp4