-
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
Move RBR to workspace chats instead of transaction threads #51893
Changes from 4 commits
4b8f300
f698ec4
d236fdd
025083e
15bc38a
01a8f9f
83df3b7
38dd386
454aef3
f36e9f6
89b545b
cde8f33
40d9f8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6229,49 +6229,29 @@ | |
} | ||
|
||
/** | ||
* Checks to see if a report's parentAction is an expense that contains a violation type of either violation or warning | ||
* Should we display a RBR on the LHN on this report due to violations? | ||
*/ | ||
function doesTransactionThreadHaveViolations( | ||
report: OnyxInputOrEntry<Report>, | ||
transactionViolations: OnyxCollection<TransactionViolation[]>, | ||
parentReportAction: OnyxInputOrEntry<ReportAction>, | ||
): boolean { | ||
if (!ReportActionsUtils.isMoneyRequestAction(parentReportAction)) { | ||
return false; | ||
} | ||
const {IOUTransactionID, IOUReportID} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {}; | ||
if (!IOUTransactionID || !IOUReportID) { | ||
return false; | ||
} | ||
if (!isCurrentUserSubmitter(IOUReportID)) { | ||
return false; | ||
} | ||
if (report?.stateNum !== CONST.REPORT.STATE_NUM.OPEN && report?.stateNum !== CONST.REPORT.STATE_NUM.SUBMITTED) { | ||
function shouldDisplayViolationsRBRInLHN(report: OnyxEntry<Report>, transactionViolations: OnyxCollection<TransactionViolation[]>): boolean { | ||
// We only show the RBR in the highest level, which is the workspace chat | ||
if (!isPolicyExpenseChat(report)) { | ||
return false; | ||
} | ||
return ( | ||
TransactionUtils.hasViolation(IOUTransactionID, transactionViolations) || | ||
TransactionUtils.hasWarningTypeViolation(IOUTransactionID, transactionViolations) || | ||
(isPaidGroupPolicy(report) && TransactionUtils.hasModifiedAmountOrDateViolation(IOUTransactionID, transactionViolations)) | ||
); | ||
} | ||
|
||
/** | ||
* Checks if we should display violation - we display violations when the expense has violation and it is not settled | ||
*/ | ||
function shouldDisplayTransactionThreadViolations( | ||
report: OnyxEntry<Report>, | ||
transactionViolations: OnyxCollection<TransactionViolation[]>, | ||
parentReportAction: OnyxEntry<ReportAction>, | ||
): boolean { | ||
if (!ReportActionsUtils.isMoneyRequestAction(parentReportAction)) { | ||
return false; | ||
} | ||
const {IOUReportID} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {}; | ||
if (isSettled(IOUReportID) || isReportApproved(IOUReportID?.toString())) { | ||
// We only show the RBR to the submitter | ||
if (!isCurrentUserSubmitter(report?.reportID ?? '')) { | ||
return false; | ||
} | ||
return doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); | ||
|
||
// Get all potential reports, which are the ones that are: | ||
// - Owned by the same user | ||
// - Are either open or submitted | ||
// - Belong to the same workspace | ||
// And if any have a violation, then it should have a RBR | ||
const allReports = Object.values(ReportConnection.getAllReports() ?? {}); | ||
const potentialReports = allReports.filter((r: Report) => r?.ownerAccountID === currentUserAccountID && r?.stateNum <= 1 && r?.policyID === report.policyID); | ||
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. error must be for these lines |
||
return potentialReports.some( | ||
(potentialReport) => hasViolations(potentialReport.reportID, transactionViolations) || hasWarningTypeViolations(potentialReport.reportID, transactionViolations), | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -6282,9 +6262,9 @@ | |
return transactions.some((transaction) => TransactionUtils.hasViolation(transaction.transactionID, transactionViolations)); | ||
} | ||
|
||
/** | ||
Check failure on line 6265 in src/libs/ReportUtils.ts
|
||
* Checks to see if a report contains a violation of type `warning` | ||
*/ | ||
Check failure on line 6267 in src/libs/ReportUtils.ts
|
||
function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxCollection<TransactionViolation[]>): boolean { | ||
const transactions = reportsTransactions[reportID] ?? []; | ||
return transactions.some((transaction) => TransactionUtils.hasWarningTypeViolation(transaction.transactionID, transactionViolations)); | ||
|
@@ -6309,23 +6289,6 @@ | |
return true; | ||
} | ||
|
||
/** | ||
* Check whether report has violations | ||
*/ | ||
function shouldShowViolations(report: Report, transactionViolations: OnyxCollection<TransactionViolation[]>) { | ||
const {parentReportID, parentReportActionID} = report ?? {}; | ||
const canGetParentReport = parentReportID && parentReportActionID && allReportActions; | ||
if (!canGetParentReport) { | ||
return false; | ||
} | ||
const parentReportActions = allReportActions ? allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`] ?? {} : {}; | ||
const parentReportAction = parentReportActions[parentReportActionID] ?? null; | ||
if (!parentReportAction) { | ||
return false; | ||
} | ||
return shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction); | ||
} | ||
|
||
type ReportErrorsAndReportActionThatRequiresAttention = { | ||
errors: ErrorFields; | ||
reportAction?: OnyxEntry<ReportAction>; | ||
|
@@ -6406,7 +6369,7 @@ | |
let doesTransactionThreadReportHasViolations = false; | ||
if (oneTransactionThreadReportID) { | ||
const transactionReport = getReport(oneTransactionThreadReportID); | ||
doesTransactionThreadReportHasViolations = !!transactionReport && shouldShowViolations(transactionReport, transactionViolations); | ||
doesTransactionThreadReportHasViolations = !!transactionReport && shouldDisplayViolationsRBRInLHN(transactionReport, transactionViolations); | ||
} | ||
return ( | ||
doesTransactionThreadReportHasViolations || | ||
|
@@ -8387,7 +8350,6 @@ | |
chatIncludesConcierge, | ||
createDraftTransactionAndNavigateToParticipantSelector, | ||
doesReportBelongToWorkspace, | ||
doesTransactionThreadHaveViolations, | ||
findLastAccessedReport, | ||
findSelfDMReportID, | ||
formatReportLastMessageText, | ||
|
@@ -8591,7 +8553,7 @@ | |
shouldDisableRename, | ||
shouldDisableThread, | ||
shouldDisplayThreadReplies, | ||
shouldDisplayTransactionThreadViolations, | ||
shouldDisplayViolationsRBRInLHN, | ||
shouldReportBeInOptionList, | ||
shouldReportShowSubscript, | ||
shouldShowFlagComment, | ||
|
@@ -8638,7 +8600,6 @@ | |
getReasonAndReportActionThatRequiresAttention, | ||
isPolicyRelatedReport, | ||
hasReportErrorsOtherThanFailedReceipt, | ||
shouldShowViolations, | ||
getAllReportErrors, | ||
getAllReportActionsErrorsAndReportActionThatRequiresAttention, | ||
}; | ||
|
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 see this condition was deleted
if (isSettled(IOUReportID) || isReportApproved(IOUReportID?.toString())) {
, but should we be checking for settled/approved reports, and only show RBR on workspace chats if there's an expense report on the same policy of the workspace chat that isn't approved or settled?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.
That's done with
(r.stateNum ?? 0) <= 1
below