-
Notifications
You must be signed in to change notification settings - Fork 3.2k
perf: use requiresAttentionFromCurrentUser from a derived value #61586
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 all commits
b69416d
db637f9
49526e3
81d1056
38e9a46
29b960e
21cef0a
407bd0e
e4a18b1
68688b3
96eb9fd
e201d75
bf3e2b7
7a0fc0e
e3cd75b
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 |
---|---|---|
|
@@ -707,7 +707,6 @@ type OptionData = { | |
alternateText?: string; | ||
allReportErrors?: Errors; | ||
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | '' | null; | ||
shouldShowGreenDot?: boolean; | ||
tooltipText?: string | null; | ||
alternateTextMaxLines?: number; | ||
boldStyle?: boolean; | ||
|
@@ -1059,14 +1058,14 @@ Onyx.connect({ | |
callback: (value) => (activePolicyID = value), | ||
}); | ||
|
||
let reportAttributes: ReportAttributesDerivedValue['reports']; | ||
let reportAttributesDerivedValue: ReportAttributesDerivedValue['reports']; | ||
Onyx.connect({ | ||
key: ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, | ||
callback: (value) => { | ||
if (!value) { | ||
return; | ||
} | ||
reportAttributes = value.reports; | ||
reportAttributesDerivedValue = value.reports; | ||
}, | ||
}); | ||
|
||
|
@@ -4647,11 +4646,11 @@ function getReportName( | |
parentReportActionParam?: OnyxInputOrEntry<ReportAction>, | ||
personalDetails?: Partial<PersonalDetailsList>, | ||
invoiceReceiverPolicy?: OnyxEntry<Policy>, | ||
reportAttributesParam?: ReportAttributesDerivedValue['reports'], | ||
reportAttributes?: ReportAttributesDerivedValue['reports'], | ||
): string { | ||
// Check if we can use report name in derived values - only when we have report but no other params | ||
const canUseDerivedValue = report && policy === undefined && parentReportActionParam === undefined && personalDetails === undefined && invoiceReceiverPolicy === undefined; | ||
const attributes = reportAttributesParam ?? reportAttributes; | ||
const attributes = reportAttributes ?? reportAttributesDerivedValue; | ||
const derivedNameExists = report && !!attributes?.[report.reportID]?.reportName; | ||
if (canUseDerivedValue && derivedNameExists) { | ||
return attributes[report.reportID].reportName; | ||
|
@@ -10754,6 +10753,15 @@ function getReportPersonalDetailsParticipants(report: Report, personalDetailsPar | |
}; | ||
} | ||
|
||
function getReportAttributes(reportID: string | undefined, reportAttributes?: ReportAttributesDerivedValue['reports']) { | ||
const attributes = reportAttributes ?? reportAttributesDerivedValue; | ||
|
||
if (!reportID || !attributes?.[reportID]) { | ||
return; | ||
} | ||
return attributes[reportID]; | ||
} | ||
|
||
Comment on lines
+10756
to
+10764
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 we dont want to create these getters in general and always use the attributes fetched from onyx in the component 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. Addressed this comment here: #62464 |
||
export { | ||
addDomainToShortMention, | ||
completeShortMention, | ||
|
@@ -11130,6 +11138,7 @@ export { | |
getReportPersonalDetailsParticipants, | ||
isAllowedToSubmitDraftExpenseReport, | ||
isWorkspaceEligibleForReportChange, | ||
getReportAttributes, | ||
}; | ||
|
||
export type { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,13 +73,13 @@ export default createOnyxDerivedValueConfig({ | |
dataToIterate = prepareReportKeys(updates); | ||
recentlyUpdated = updates; | ||
} else if (!!transactionsUpdates || !!transactionViolationsUpdates) { | ||
let transactionReportIds: string[] = []; | ||
let transactionReportIDs: string[] = []; | ||
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. Addressing this NAB comment from previous PR #61376 (comment) here cc @mountiny |
||
if (transactionsUpdates) { | ||
transactionReportIds = Object.values(transactionsUpdates).map((transaction) => `${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`); | ||
transactionReportIDs = Object.values(transactionsUpdates).map((transaction) => `${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`); | ||
} | ||
// if transactions are updated, they might not be directly related to the reports yet (e.g. transaction is optimistically created) | ||
// so we use report keys that were updated before to recompute the reports | ||
const recentReportKeys = prepareReportKeys([...recentlyUpdated, ...transactionReportIds]); | ||
const recentReportKeys = prepareReportKeys([...recentlyUpdated, ...transactionReportIDs]); | ||
dataToIterate = recentReportKeys; | ||
} | ||
} | ||
|
@@ -112,6 +112,7 @@ export default createOnyxDerivedValueConfig({ | |
acc[report.reportID] = { | ||
reportName: generateReportName(report), | ||
brickRoadStatus, | ||
requiresAttention, | ||
}; | ||
|
||
return acc; | ||
|
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 believe this is an antipattern now and we should always subscribe to the attributes in the component using useOnyx and pass them to the utils method - this should ensure the component is always re-rendered when the attribute changes and that the utils method remains pure.
@TMisiukiewicz @kacper-mikolajczak what do you think? Could you look into this to refactor its usages?
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 agree that it should be passed to the util methods from
useOnyx
. The only caveat is that in some cases, those values might be used deep within the function logic, not just as top-level arguments. Refactoring might result in passing them through multiple layers of intermediate calls.I'll verify if it'll introduce the additional complexity