-
Notifications
You must be signed in to change notification settings - Fork 3.3k
perf: move report brick road statuses to a derived value #60827
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
Changes from 9 commits
90124bb
a6bee45
1775b52
343af25
df967b6
06ea093
3d15809
af3e44e
c969cb0
87e45ea
d4c24b3
bd2cf12
e516106
7d54dd7
e1ed685
a3a142d
9c7f123
08d0342
dcc46ef
d70ac27
dde332f
6f9365e
fd35b7f
dc0d935
5e061eb
de7c06c
6a5198e
b1a9ad7
3d7b148
0acc33e
d49b203
88006b5
2ce18ca
986af36
0dc62bd
d14e306
6d8f93c
05f5968
e606dd9
0146df8
05e66fe
6f29283
339dbf6
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 |
---|---|---|
|
@@ -10464,6 +10464,43 @@ function getChatListItemReportName(action: ReportAction & {reportName?: string}, | |
return action?.reportName ?? ''; | ||
} | ||
|
||
/** | ||
* Generates report attributes for a report | ||
* This function should be called only in reportAttributes.ts | ||
* DO NOT USE THIS FUNCTION ANYWHERE ELSE | ||
*/ | ||
function generateReportAttributes({ | ||
report, | ||
reportActions, | ||
transactionViolations, | ||
}: { | ||
report: OnyxEntry<Report>; | ||
reportActions?: ReportActions; | ||
transactionViolations: OnyxCollection<TransactionViolation[]>; | ||
}) { | ||
const isReportSettled = isSettled(report); | ||
const isCurrentUserReportOwner = isReportOwner(report); | ||
const doesReportHasViolations = hasReportViolations(report?.reportID); | ||
const hasViolationsToDisplayInLHN = shouldDisplayViolationsRBRInLHN(report, transactionViolations); | ||
const hasAnyViolations = hasViolationsToDisplayInLHN || (!isReportSettled && isCurrentUserReportOwner && doesReportHasViolations); | ||
const reportErrors = getAllReportErrors(report, reportActions); | ||
const hasErrors = Object.entries(reportErrors ?? {}).length > 0; | ||
const oneTransactionThreadReportID = getOneTransactionThreadReportID(report?.reportID, reportActions); | ||
const parentReportAction = report?.parentReportActionID ? reportActions?.[report.parentReportActionID] : undefined; | ||
const requiresAttention = requiresAttentionFromCurrentUser(report, parentReportAction); | ||
|
||
return { | ||
doesReportHasViolations, | ||
hasViolationsToDisplayInLHN, | ||
hasAnyViolations, | ||
reportErrors, | ||
hasErrors, | ||
oneTransactionThreadReportID, | ||
parentReportAction, | ||
requiresAttention, | ||
}; | ||
} | ||
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. I created this function to:
|
||
|
||
export { | ||
addDomainToShortMention, | ||
completeShortMention, | ||
|
@@ -10834,6 +10871,7 @@ export { | |
populateOptimisticReportFormula, | ||
getOutstandingReports, | ||
isReportOutstanding, | ||
generateReportAttributes, | ||
}; | ||
|
||
export type { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import type {ValueOf} from 'type-fest'; | |
import type {PartialPolicyForSidebar} from '@hooks/useSidebarOrderedReportIDs'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {PersonalDetails, PersonalDetailsList, ReportActions, ReportNameValuePairs, TransactionViolation} from '@src/types/onyx'; | ||
import type {PersonalDetails, PersonalDetailsList, ReportActions, ReportAttributes, ReportNameValuePairs, TransactionViolation} from '@src/types/onyx'; | ||
import type Beta from '@src/types/onyx/Beta'; | ||
import type Policy from '@src/types/onyx/Policy'; | ||
import type PriorityMode from '@src/types/onyx/PriorityMode'; | ||
|
@@ -163,6 +163,14 @@ Onyx.connect({ | |
}, | ||
}); | ||
|
||
let reportAttributes: OnyxEntry<Record<string, ReportAttributes>>; | ||
Onyx.connect({ | ||
key: ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, | ||
callback: (value) => { | ||
reportAttributes = value; | ||
}, | ||
}); | ||
|
||
function compareStringDates(a: string, b: string): 0 | 1 | -1 { | ||
if (a < b) { | ||
return -1; | ||
|
@@ -340,6 +348,47 @@ type ReasonAndReportActionThatHasRedBrickRoad = { | |
reportAction?: OnyxEntry<ReportAction>; | ||
}; | ||
|
||
function hasAnyErrorsOrViolations(report: Report, reportActions: OnyxEntry<ReportActions>, hasAnyViolations: boolean, hasErrors: boolean, singleTransactionThread?: string) { | ||
const {reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions); | ||
if (isArchivedReportWithID(report.reportID)) { | ||
return false; | ||
} | ||
|
||
if (hasAnyViolations) { | ||
return { | ||
reason: CONST.RBR_REASONS.HAS_TRANSACTION_THREAD_VIOLATIONS, | ||
}; | ||
} | ||
|
||
if (hasErrors) { | ||
return { | ||
reason: CONST.RBR_REASONS.HAS_ERRORS, | ||
reportAction, | ||
}; | ||
} | ||
|
||
if (singleTransactionThread) { | ||
const transactionID = getTransactionID(singleTransactionThread); | ||
const transaction = getTransaction(transactionID); | ||
if (hasReceiptError(transaction)) { | ||
return { | ||
reason: CONST.RBR_REASONS.HAS_ERRORS, | ||
}; | ||
} | ||
} | ||
|
||
const parentReportAction = getReportAction(report?.parentReportID, report?.parentReportActionID); | ||
const transactionID = getTransactionID(report.reportID); | ||
const transaction = getTransaction(transactionID); | ||
if (isTransactionThread(parentReportAction) && hasReceiptError(transaction)) { | ||
return { | ||
reason: CONST.RBR_REASONS.HAS_ERRORS, | ||
}; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
function getReasonAndReportActionThatHasRedBrickRoad( | ||
report: Report, | ||
reportActions: OnyxEntry<ReportActions>, | ||
|
@@ -410,9 +459,7 @@ function getOptionData({ | |
preferredLocale, | ||
policy, | ||
parentReportAction, | ||
hasViolations, | ||
lastMessageTextFromReport: lastMessageTextFromReportProp, | ||
transactionViolations, | ||
invoiceReceiverPolicy, | ||
}: { | ||
report: OnyxEntry<Report>; | ||
|
@@ -423,10 +470,8 @@ function getOptionData({ | |
preferredLocale: DeepValueOf<typeof CONST.LOCALES>; | ||
policy: OnyxEntry<Policy> | undefined; | ||
parentReportAction: OnyxEntry<ReportAction> | undefined; | ||
hasViolations: boolean; | ||
lastMessageTextFromReport?: string; | ||
invoiceReceiverPolicy?: OnyxEntry<Policy>; | ||
transactionViolations?: OnyxCollection<TransactionViolation[]>; | ||
}): OptionData | undefined { | ||
// When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for | ||
// this method to be called after the Onyx data has been cleared out. In that case, it's fine to do | ||
|
@@ -485,7 +530,7 @@ function getOptionData({ | |
result.isMoneyRequestReport = isMoneyRequestReport(report); | ||
result.shouldShowSubscript = shouldReportShowSubscript(report); | ||
result.pendingAction = report.pendingFields?.addWorkspaceRoom ?? report.pendingFields?.createChat; | ||
result.brickRoadIndicator = shouldShowRedBrickRoad(report, reportActions, hasViolations, transactionViolations) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; | ||
result.brickRoadIndicator = reportAttributes?.[report.reportID]?.brickRoadStatus; | ||
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. Is it possible to use 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. I think Screen.Recording.2025-04-30.at.16.17.26.movSo I'll update the PR and remove 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. Ok after double-checking I tried different approach: Instead of passing all report attributes, I am passing only the one related to the item to |
||
result.ownerAccountID = report.ownerAccountID; | ||
result.managerID = report.managerID; | ||
result.reportID = report.reportID; | ||
|
@@ -679,7 +724,6 @@ function getOptionData({ | |
|
||
if (isJoinRequestInAdminRoom(report)) { | ||
result.isUnread = true; | ||
result.brickRoadIndicator = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO; | ||
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. Have we migrated this logic to 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. yes |
||
} | ||
|
||
if (!hasMultipleParticipants) { | ||
|
@@ -824,4 +868,5 @@ export default { | |
getWelcomeMessage, | ||
getReasonAndReportActionThatHasRedBrickRoad, | ||
shouldShowRedBrickRoad, | ||
hasAnyErrorsOrViolations, | ||
}; |
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.
It's incorrect because it should be retrieved in
reportActions
of parent reportApp/src/components/LHNOptionsList/LHNOptionsList.tsx
Lines 138 to 139 in 497cdce
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.
good catch, thanks!