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

Adds new ReportUtils for Violations #31448

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
a917e06
adds violations functions to report utils and implements
cdanwards Nov 16, 2023
3756ef9
Small fix in ReportUtils
cdanwards Nov 16, 2023
3cc2e0f
Fix Onyx Connection for reportActions
cdanwards Nov 16, 2023
4db7207
Fixed merge conflicts
cdanwards Nov 16, 2023
35fd77e
Fixed more merge conflicts
cdanwards Nov 16, 2023
7942b39
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Nov 20, 2023
89997ce
Merge branch 'main' of github.com:Expensify/App into cdanwards/violat…
cdanwards Nov 20, 2023
a98b3a1
Fix Permissions import
cdanwards Nov 21, 2023
f7dc731
Correctly pass down betas
cdanwards Nov 22, 2023
93ea5b7
Update tests
cdanwards Nov 22, 2023
1cfeec0
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Nov 22, 2023
1f9d645
Fixing some beta props
cdanwards Nov 27, 2023
2a03cc9
Fixed merge conflicts
cdanwards Nov 27, 2023
813c856
Fixed merge conflicts
cdanwards Nov 27, 2023
6d47be5
Started TS conversion
cdanwards Nov 27, 2023
6a16af0
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Nov 28, 2023
5849803
Fixed up the Onyx Types for Violations & I think I got the functions …
cdanwards Nov 29, 2023
f7fa4bf
Finally got the tests up and working correctly
cdanwards Nov 29, 2023
9ce9595
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Nov 29, 2023
02fa714
Fixed types and property checks for violations
cdanwards Nov 29, 2023
63ab544
Added some doc comments and also fixed the violation type
cdanwards Nov 30, 2023
bef0d73
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Nov 30, 2023
c6dca6a
Fixed merge conflicts
cdanwards Nov 30, 2023
c69c1df
Fixed perf test
cdanwards Nov 30, 2023
5e122ef
Removed unnecessary export
cdanwards Nov 30, 2023
e53902e
Restore betas in test
cdanwards Nov 30, 2023
c49b03f
Switch to destructuring
cdanwards Nov 30, 2023
375eabb
Update src/libs/ReportUtils.ts
cdanwards Dec 5, 2023
b6c24db
Update src/libs/ReportUtils.ts
cdanwards Dec 5, 2023
8bee286
Fixed merge conflicts
cdanwards Dec 5, 2023
e1ca1ac
Merge branch 'cdanwards/violations/transaction-thread-violations' of …
cdanwards Dec 5, 2023
ccd3eb3
remove unneeded changes
cdanwards Dec 5, 2023
1d2cfa2
Remove duplicate TRANSACTION_VIOLATIONS constant
cdanwards Dec 5, 2023
bcd1ee8
Update src/ONYXKEYS.ts
cdanwards Dec 6, 2023
cae1e0d
Working on removing the onyx connect and using withOnyx
cdanwards Dec 7, 2023
59ba57e
Merge branch 'cdanwards/violations/transaction-thread-violations' of …
cdanwards Dec 11, 2023
90b7138
Starting so swap in the transactionViolations
cdanwards Dec 11, 2023
35de23f
Fixed tests and created new hook mock
cdanwards Dec 12, 2023
bbfd1fa
Switched to just passing down parentReportAction
cdanwards Dec 12, 2023
20a0fc3
Fixed Merge COnflicts
cdanwards Dec 12, 2023
2c52edf
Move the report actions selector to the SidebarUtils file
cdanwards Dec 12, 2023
73971f0
Correct type import
cdanwards Dec 13, 2023
1234b88
Another type correction
cdanwards Dec 13, 2023
9223374
Final fix for the test of the report actions
cdanwards Dec 13, 2023
9e1753b
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Dec 13, 2023
4366d64
Update Comments
cdanwards Dec 13, 2023
5716800
A few fixes
cdanwards Dec 13, 2023
adf1933
Fixed some prop types and also added a beta guard
cdanwards Dec 13, 2023
da8f376
Added usePermissions mock to ReportPreview
cdanwards Dec 13, 2023
cda1aee
Trying this out
cdanwards Dec 13, 2023
cd6586a
Trying this out
cdanwards Dec 13, 2023
03f9d96
Merge branch 'cdanwards/violations/transaction-thread-violations' of …
cdanwards Dec 13, 2023
6478b94
fix for perf test
cdanwards Dec 13, 2023
1736c21
Remove unused type
cdanwards Dec 13, 2023
16a0a9a
Fixing some issues with tests
cdanwards Dec 13, 2023
feb3596
Was accidentally importing named instead of default
cdanwards Dec 13, 2023
c7aa6c4
Fix merge conflicts
cdanwards Dec 13, 2023
69b767b
Update src/libs/ReportUtils.ts
cdanwards Dec 14, 2023
9535a2b
Update src/components/ReportActionItem/ReportPreview.js
cdanwards Dec 14, 2023
99d3c0d
Update src/hooks/__mocks__/usePermissions.ts
cdanwards Dec 14, 2023
0720910
Remove unused import
cdanwards Dec 14, 2023
7faf50b
Fix transactionHasViolation function and
cdanwards Dec 14, 2023
bf401af
Remove unnecessary code in shouldHideReport
cdanwards Dec 14, 2023
f0a360b
Remove unnecessary comment in ReportUtils.ts
cdanwards Dec 14, 2023
4088e8f
Fix betas check to be outside of the function
cdanwards Dec 14, 2023
766d37e
Add comment about using usePermissions hook mock for beta tests
cdanwards Dec 14, 2023
561a4d4
Add default value for transactionViolations
cdanwards Dec 14, 2023
abad008
Make linter happy
cdanwards Dec 14, 2023
563ca7b
Refactor getOrderedReportIDs function to improve
cdanwards Dec 14, 2023
32fb912
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Dec 14, 2023
2e5c39b
feat(Violations): implement types from money-request-preview branch
trevor-coleman Dec 14, 2023
30a77c9
feat(Violations): replace transactionViolationsProp with imported pro…
trevor-coleman Dec 14, 2023
2e3d3e7
feat(Violations): make reportActions mandatory and remove parentRepor…
trevor-coleman Dec 14, 2023
9503748
feat(Violations): remove whitespace
trevor-coleman Dec 14, 2023
2871cd8
feat(Violations): simplify
trevor-coleman Dec 14, 2023
5dd7d01
feat(Violations): update comment
trevor-coleman Dec 14, 2023
d169a43
feat(Violations): simplify
trevor-coleman Dec 14, 2023
aa7822e
feat(Violations): fix type of transactionViolations propType
trevor-coleman Dec 14, 2023
d86616d
feat(Violations): revert simplifications
trevor-coleman Dec 15, 2023
ccb12cc
feat(Violations): add second withOnyx
trevor-coleman Dec 15, 2023
e3d4ae8
feat(Violations): get transactions directly
trevor-coleman Dec 15, 2023
37e0f2e
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Dec 19, 2023
d467853
feat(Violations): fix propsTypes
trevor-coleman Dec 19, 2023
fdab084
feat(Violations): rename
trevor-coleman Dec 19, 2023
bf37bb0
feat(Violations): rename
trevor-coleman Dec 19, 2023
db5fa36
feat(Violations): move ReportUtils.transactionHasViolation to Transac…
trevor-coleman Dec 19, 2023
ba5e940
feat(Violations): restore selector
trevor-coleman Dec 19, 2023
e873fa4
feat(Violations): remove null guard
trevor-coleman Dec 19, 2023
68f933a
feat(Violations): revert line width changes
trevor-coleman Dec 19, 2023
b41a3de
feat(Violations): change signature of shouldReportBeInOptionList
trevor-coleman Dec 19, 2023
2492bf9
feat(Violations): rename resolvedParentReportAction
trevor-coleman Dec 19, 2023
90101f2
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Dec 19, 2023
ea6bf2e
feat(Violations): add whitespace
trevor-coleman Dec 21, 2023
4d4c476
feat(Violations): use imported propType
trevor-coleman Dec 21, 2023
ec2429a
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Dec 21, 2023
04ed595
feat(Violations): revert commment wrapping
trevor-coleman Dec 22, 2023
aa14258
feat(Violations): cast return value to type
trevor-coleman Dec 22, 2023
0214a12
feat(Violations): use correct key
trevor-coleman Dec 22, 2023
a89d888
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 2, 2024
cd4e987
feat(Violations): fix comment wrapping
trevor-coleman Jan 2, 2024
93d08a0
feat(Violations): fix proptypes of allReportActions
trevor-coleman Jan 3, 2024
c24db94
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 3, 2024
b3b367d
feat(Violations): revert change to reportActionsSelector
trevor-coleman Jan 3, 2024
00ce2cf
feat(Violations): restore proptypes
trevor-coleman Jan 3, 2024
a5ecebe
feat(Violations): unwrap comment
trevor-coleman Jan 3, 2024
2f4a14a
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 4, 2024
93a300b
fix types broken by merge
trevor-coleman Jan 4, 2024
289d00f
feat(Violations): remove comment
trevor-coleman Jan 4, 2024
0bba695
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 4, 2024
c2667a8
feat(Violations): remove duplicate violations
trevor-coleman Jan 4, 2024
d1a6ee1
feat(Violations): fix import paths
trevor-coleman Jan 4, 2024
6cabad0
feat(Violations): use reportActions
trevor-coleman Jan 4, 2024
ea487ba
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 5, 2024
c8ebe6f
feat(Violations): remove transaction violations
trevor-coleman Jan 5, 2024
ec7dc4f
feat(Violations): remove transaction violations
trevor-coleman Jan 5, 2024
aacb894
feat(Violations): lint
trevor-coleman Jan 5, 2024
9e57641
feat(Violations): create params object for getOptionData
trevor-coleman Jan 8, 2024
79ac93a
feat(Violations): create params object for shouldReportBeInOptionsList
trevor-coleman Jan 8, 2024
13fe960
feat(Violations): invert control and pass doesTransactionThreadHaveVi…
trevor-coleman Jan 8, 2024
4a26a24
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 8, 2024
66c181e
feat(Violations): fix TransactionViolations export
trevor-coleman Jan 8, 2024
2f75e74
feat(Violations): take parentReportAction as param an update callers
trevor-coleman Jan 8, 2024
e110f14
feat(Violations): fix import
trevor-coleman Jan 8, 2024
00a8bec
feat(Violations): pass proper parentReportAction in to doesTransactio…
trevor-coleman Jan 8, 2024
0512719
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 8, 2024
6968650
feat(Violations): remove unneeded imports and lint
trevor-coleman Jan 8, 2024
ad15ca6
fix type
trevor-coleman Jan 8, 2024
85fa56d
feat(Violations): remove unneeded import
trevor-coleman Jan 8, 2024
2452d31
fix filtering
trevor-coleman Jan 9, 2024
44a96ca
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 9, 2024
192899c
feat(Violations): remove optional param
trevor-coleman Jan 9, 2024
0c41aec
feat(Violations): remove check for undefined report
trevor-coleman Jan 9, 2024
891c3d2
feat(Violations): PR review comments
trevor-coleman Jan 9, 2024
09d08e2
feat(Violations): rename param
trevor-coleman Jan 10, 2024
ae525eb
feat(Violations): use !! instead of Boolean to allow type narrowing
trevor-coleman Jan 10, 2024
4547321
feat(Violations): make all params required
trevor-coleman Jan 10, 2024
3b66eeb
feat(Violations): fix comment
trevor-coleman Jan 10, 2024
da7bf97
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 10, 2024
a5833d0
feat(Violations): use shorthand
trevor-coleman Jan 10, 2024
44ef928
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 11, 2024
587a44c
feat(Violations): use lodash
trevor-coleman Jan 12, 2024
c732ddd
feat(Violations): ensure reportActionCount defaults to 1
trevor-coleman Jan 12, 2024
3eaf3d4
feat(Violations): refactor for readability
trevor-coleman Jan 12, 2024
27e8315
feat(Violations): restore guard
trevor-coleman Jan 12, 2024
96b9ff7
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 12, 2024
de97f71
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 15, 2024
8e0250c
feat(Violations): change STATE_NUM to reflect changes from 54e7f76d9f…
trevor-coleman Jan 15, 2024
00fefc1
prettier
trevor-coleman Jan 15, 2024
9498292
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 15, 2024
e3882e7
Update src/libs/ReportUtils.ts
trevor-coleman Jan 15, 2024
64ab957
feat(Violations): clarify import from TransactionUtils
trevor-coleman Jan 16, 2024
ae91d30
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 18, 2024
7305a48
feat(Violations): fix const/let
trevor-coleman Jan 18, 2024
6e8ebca
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
trevor-coleman Jan 18, 2024
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
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function ReportPreview(props) {
const hasReceipts = transactionsWithReceipts.length > 0;
const hasOnlyDistanceRequests = ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID);
const isScanning = hasReceipts && ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID, props.action);
const hasErrors = hasReceipts && ReportUtils.hasMissingSmartscanFields(props.iouReportID);
const hasErrors = (hasReceipts && ReportUtils.hasMissingSmartscanFields(props.iouReportID)) || ReportUtils.reportHasViolations(props.iouReportID);
const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3);
const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, (transaction) => ReceiptUtils.getThumbnailAndImageURIs(transaction));
const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(props.iouReportID);
Expand Down
92 changes: 90 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as defaultWorkspaceAvatars from '@components/Icon/WorkspaceDefaultAvata
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import * as CollectionUtils from './CollectionUtils';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import isReportMessageAttachment from './isReportMessageAttachment';
Expand Down Expand Up @@ -81,6 +82,31 @@ Onyx.connect({
callback: (val) => (loginList = val),
});

const transactionViolations = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
callback: (violations, key) => {
if (!key || !violations) {
return;
}

const transactionID = CollectionUtils.extractCollectionItemID(key);
transactionViolations[transactionID] = violations;
},
});

const reportActions = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
return;
}

const reportID = CollectionUtils.extractCollectionItemID(key);
reportActions[reportID] = actions;
},
});
let allPolicyTags = {};

Onyx.connect({
Expand Down Expand Up @@ -3316,11 +3342,66 @@ function canAccessReport(report, policies, betas, allReportActions) {
*/
function shouldHideReport(report, currentReportId) {
const parentReport = getParentReport(getReport(currentReportId));
const reportActions = ReportActionsUtils.getAllReportActions(report.reportID);
const isChildReportHasComment = _.some(reportActions, (reportAction) => (reportAction.childVisibleActionCount || 0) > 0);
const allReportActions = ReportActionsUtils.getAllReportActions(report.reportID);
const isChildReportHasComment = _.some(allReportActions, (reportAction) => (reportAction.childVisibleActionCount || 0) > 0);
return parentReport.reportID !== report.reportID && !isChildReportHasComment;
}

/**
* @param {String} transactionID
* @returns {Boolean}
*/

function transactionHasViolation(transactionID) {
const violations = lodashGet(transactionViolations, transactionID, []);
cdanwards marked this conversation as resolved.
Show resolved Hide resolved
return _.some(violations, (violation) => violation.type === 'violation');
}

/**
*
* @param {Object} report
* @returns {Boolean}
*/

function transactionThreadHasViolations(report) {
if (!Permissions.canUseViolations()) {
return false;
}
// eslint-disable-next-line es/no-nullish-coalescing-operators
if (!report.parentReportActionID) {
return false;
}

const parentReportAction = lodashGet(reportActions, `${report.parentReportID}.${report.parentReportActionID}`);
if (!parentReportAction) {
return false;
}
// eslint-disable-next-line es/no-nullish-coalescing-operators
const transactionID = parentReportAction.originalMessage.IOUTransactionID ?? 0;
if (!transactionID) {
return false;
}
// eslint-disable-next-line es/no-nullish-coalescing-operators
const reportID = parentReportAction.originalMessage.IOUReportID ?? 0;
if (!reportID) {
return false;
}
if (!isCurrentUserSubmitter(reportID)) {
return false;
}
return transactionHasViolation(transactionID);
}

/**
* @param {String} reportID
* @returns {Boolean}
*/

function reportHasViolations(reportID) {
const transactions = TransactionUtils.getAllReportTransactions(reportID);
return _.some(transactions, (transaction) => transactionHasViolation(transaction.transactionID));
}

/**
* Takes several pieces of data from Onyx and evaluates if a report should be shown in the option list (either when searching
* for reports or the reports shown in the LHN).
Expand Down Expand Up @@ -3396,6 +3477,11 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, betas,
return true;
}

// Always show IOU reports with violations
if (isExpenseRequest(report) && transactionThreadHasViolations(report)) {
return true;
}

// All unread chats (even archived ones) in GSD mode will be shown. This is because GSD mode is specifically for focusing the user on the most relevant chats, primarily, the unread ones
if (isInGSDMode) {
return isUnread(report);
Expand Down Expand Up @@ -4437,5 +4523,7 @@ export {
getPersonalDetailsForAccountID,
getChannelLogMemberMessage,
getRoom,
transactionThreadHasViolations,
reportHasViolations,
shouldDisableWelcomeMessage,
};
2 changes: 1 addition & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function getOptionData(
result.shouldShowSubscript = ReportUtils.shouldReportShowSubscript(report);
result.pendingAction = report.pendingFields ? report.pendingFields.addWorkspaceRoom || report.pendingFields.createChat : null;
result.allReportErrors = OptionsListUtils.getAllReportErrors(report, reportActions) as OnyxCommon.Errors;
result.brickRoadIndicator = Object.keys(result.allReportErrors ?? {}).length !== 0 ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
result.brickRoadIndicator = Object.keys(result.allReportErrors ?? {}).length !== 0 || ReportUtils.transactionThreadHasViolations(report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
result.ownerAccountID = report.ownerAccountID;
result.managerID = report.managerID;
result.reportID = report.reportID;
Expand Down
Loading