-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Refactor canActionTask so that it no longer calls getReportNameValuePairs #60869
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
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
c239c53
Add a skeleton test
tgolen 4e54259
Add first assertion
tgolen c68f9de
Refactor test to be DRY and add more assertions
tgolen 7fb5062
More test organizing
tgolen 3343b78
Rename variables and use task reports
tgolen e5034c3
Finish writing tests to cover current logic
tgolen 9faaf6e
fix typo
tgolen df02805
Refactor parameters for parent report and is archived
tgolen 16fc9c6
Add new hook
tgolen 54bd38d
Implement hooks in the tests
tgolen 18ed22e
Remove unnecessary parameters
tgolen 984742d
Add comment
tgolen f85e169
Make second param optional
tgolen d46050f
Implement new method signature
tgolen 7d1a00f
Implement new method signature
tgolen 9925873
Implement new method sig
tgolen e300db9
Revert changes
tgolen d097f82
Revert revert
tgolen 81d5193
Remove unused variable
tgolen dbb51ec
Remove default value
tgolen 8377e3d
Finish implementing
tgolen 4bda56c
Remove unused variables
tgolen 19bde87
Clean up tests
tgolen f147cd0
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen e6286c1
Exit early if no parent report
tgolen 5c829c8
properly filter task reports
JS00001 6f6665a
Fix canModifyTask
tgolen aabb0ca
Refactor report details
tgolen bcef9dd
Refactor task view
tgolen d58ddcd
Refactor FAB
tgolen 8b5f234
Refactor empty search view
tgolen 4676fd6
Rename variables
tgolen 51a3f14
Refactor assignee selector
tgolen 4876708
Refactor task description page
tgolen f140784
Refactor task title page
tgolen 4c386c4
Refactor task header action button
tgolen 521e11f
Refactor task preview
tgolen 4f7ae91
Refactor item row
tgolen 1634e49
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen 735db79
ESLint
tgolen f972b05
Add comments and address review requests
tgolen 52e276a
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen 4270a6b
Style
tgolen 01827bb
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen 61bed2e
debug test
tgolen ecfb4b4
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen cc48c61
Change back to each
tgolen 977f6d1
Remove debug
tgolen 39be9ed
Lint
tgolen 0917b6d
TS
tgolen e1448ce
Jest
tgolen 4f169c6
Remove extra line
tgolen af3572e
Lint
tgolen b24b424
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen d88e2d5
Lint
tgolen cd040b4
Remove an extra mock definition
tgolen 02b87fd
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen c318ae1
Remove unnecessary mock
tgolen 29cac38
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen 515ee08
Merge branch 'main' into tgolen-remove-rnvp-4
tgolen 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Report} from '@src/types/onyx'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| function useParentReport(reportID?: string): OnyxEntry<Report> { | ||
| const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); | ||
|
JS00001 marked this conversation as resolved.
|
||
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true}); | ||
|
JS00001 marked this conversation as resolved.
|
||
| return parentReport; | ||
| } | ||
|
|
||
| export default useParentReport; | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -95,6 +95,18 @@ Onyx.connect({ | |
| callback: (val) => (introSelected = val), | ||
| }); | ||
|
|
||
| let allReportNameValuePair: OnyxCollection<OnyxTypes.ReportNameValuePairs>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
| if (!value) { | ||
| return; | ||
| } | ||
| allReportNameValuePair = value; | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * Clears out the task info from the store | ||
| */ | ||
|
|
@@ -998,6 +1010,7 @@ function getParentReportAction(report: OnyxEntry<OnyxTypes.Report>): OnyxEntry<R | |
| if (!report?.parentReportID || !report.parentReportActionID) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]; | ||
| } | ||
|
|
||
|
|
@@ -1221,7 +1234,11 @@ function getTaskAssigneeAccountID(taskReport: OnyxEntry<OnyxTypes.Report>): numb | |
| /** | ||
| * Check if you're allowed to modify the task - only the author can modify the task | ||
| */ | ||
| function canModifyTask(taskReport: OnyxEntry<OnyxTypes.Report>, sessionAccountID: number, isParentReportArchived = false): boolean { | ||
| function canModifyTask(taskReport: OnyxEntry<OnyxTypes.Report>, sessionAccountID?: number, isParentReportArchived = false): boolean { | ||
| if (!sessionAccountID) { | ||
| return false; | ||
| } | ||
|
|
||
| if (ReportUtils.isCanceledTaskReport(taskReport)) { | ||
| return false; | ||
| } | ||
|
|
@@ -1236,23 +1253,32 @@ function canModifyTask(taskReport: OnyxEntry<OnyxTypes.Report>, sessionAccountID | |
| /** | ||
| * Check if you can change the status of the task (mark complete or incomplete). Only the task owner and task assignee can do this. | ||
| */ | ||
| function canActionTask(taskReport: OnyxEntry<OnyxTypes.Report>, sessionAccountID: number, taskOwnerAccountID?: number, taskAssigneeAccountID?: number): boolean { | ||
| if (ReportUtils.isCanceledTaskReport(taskReport)) { | ||
| function canActionTask(taskReport: OnyxEntry<OnyxTypes.Report>, sessionAccountID?: number, parentReport?: OnyxEntry<OnyxTypes.Report>, isParentReportArchived = false): boolean { | ||
| // Return early if there was no sessionAccountID (this can happen because when connecting to the session key in onyx, the session will be undefined initially) | ||
| if (!sessionAccountID) { | ||
| return false; | ||
| } | ||
|
|
||
| const parentReport = getParentReport(taskReport); | ||
| // When there is no parent report, exit early (this can also happen due to onyx key initialization) | ||
| if (!parentReport) { | ||
| return false; | ||
|
Comment on lines
+1263
to
+1264
Contributor
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. Coming from #65041 checklist: |
||
| } | ||
|
|
||
| // Cancelled task reports cannot be actioned since they are cancelled and users shouldn't be able to do anything with them | ||
| if (ReportUtils.isCanceledTaskReport(taskReport)) { | ||
| return false; | ||
| } | ||
|
|
||
| // This will get removed as part of https://github.com/Expensify/App/issues/59961 | ||
| // eslint-disable-next-line deprecation/deprecation | ||
| const reportNameValuePairs = ReportUtils.getReportNameValuePairs(parentReport?.reportID); | ||
| if (ReportUtils.isArchivedNonExpenseReport(parentReport, reportNameValuePairs)) { | ||
| // If the parent report is a non expense report and it's archived, then the user cannot take actions (similar to cancelled task reports) | ||
| const isParentAnExpenseReport = ReportUtils.isExpenseReport(parentReport); | ||
| const isParentAnExpenseRequest = ReportUtils.isExpenseRequest(parentReport); | ||
| const isParentANonExpenseReport = !(isParentAnExpenseReport || isParentAnExpenseRequest); | ||
| if (isParentANonExpenseReport && isParentReportArchived) { | ||
| return false; | ||
| } | ||
|
|
||
| const ownerAccountID = taskReport?.ownerAccountID ?? taskOwnerAccountID; | ||
| const assigneeAccountID = getTaskAssigneeAccountID(taskReport) ?? taskAssigneeAccountID; | ||
| return sessionAccountID === ownerAccountID || sessionAccountID === assigneeAccountID; | ||
| // The task can only be actioned by the task report owner or the task assignee | ||
| return sessionAccountID === taskReport?.ownerAccountID || sessionAccountID === getTaskAssigneeAccountID(taskReport); | ||
| } | ||
|
|
||
| function clearTaskErrors(reportID: string | undefined) { | ||
|
|
@@ -1279,7 +1305,10 @@ function clearTaskErrors(reportID: string | undefined) { | |
| function getFinishOnboardingTaskOnyxData(taskName: IntroSelectedTask): OnyxData { | ||
| const taskReportID = introSelected?.[taskName]; | ||
| const taskReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`]; | ||
| if (taskReportID && canActionTask(taskReport, currentUserAccountID)) { | ||
| const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${taskReport?.parentReportID}`]; | ||
| const parentReportNameValuePairs = allReportNameValuePair?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${parentReport?.reportID}`]; | ||
| const isParentReportArchived = ReportUtils.isArchivedReport(parentReportNameValuePairs); | ||
| if (taskReportID && canActionTask(taskReport, currentUserAccountID, parentReport, isParentReportArchived)) { | ||
| if (taskReport) { | ||
| if (taskReport.stateNum !== CONST.REPORT.STATE_NUM.APPROVED || taskReport.statusNum !== CONST.REPORT.STATUS_NUM.APPROVED) { | ||
| return completeTask(taskReport); | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.