-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat: use correct report field title for money request reports #34877
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51c3baf
feat: use correct report title everywhere
allroundexperts 11a74ef
fix: type errors
allroundexperts b43d700
fix: type errors
allroundexperts ca84a64
feat: merge with main
allroundexperts 0f6f93c
fix: create more helper functions for report fields
allroundexperts 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 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ import type { | |
PersonalDetailsList, | ||
Policy, | ||
PolicyReportField, | ||
PolicyReportFields, | ||
Report, | ||
ReportAction, | ||
ReportMetadata, | ||
|
@@ -459,6 +460,19 @@ Onyx.connect({ | |
callback: (value) => (allPolicies = value), | ||
}); | ||
|
||
let allPolicyReportFields: OnyxCollection<PolicyReportFields>; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.POLICY_REPORT_FIELDS, | ||
waitForCollectionCallback: true, | ||
callback: (value) => (allPolicyReportFields = value), | ||
}); | ||
|
||
let allBetas: OnyxEntry<Beta[]>; | ||
Onyx.connect({ | ||
key: ONYXKEYS.BETAS, | ||
callback: (value) => (allBetas = value), | ||
}); | ||
|
||
let loginList: OnyxEntry<Login>; | ||
Onyx.connect({ | ||
key: ONYXKEYS.LOGIN_LIST, | ||
|
@@ -1898,10 +1912,41 @@ function getPolicyExpenseChatName(report: OnyxEntry<Report>, policy: OnyxEntry<P | |
return reportOwnerDisplayName; | ||
} | ||
|
||
/** | ||
* Given a report field and a report, get the title of the field. | ||
* This is specially useful when we have a report field of type formula. | ||
*/ | ||
function getReportFieldTitle(report: OnyxEntry<Report>, reportField: PolicyReportField): string { | ||
const value = report?.reportFields?.[reportField.fieldID] ?? reportField.defaultValue; | ||
|
||
if (reportField.type !== 'formula') { | ||
return value; | ||
} | ||
|
||
return value.replaceAll(CONST.REGEX.REPORT_FIELD_TITLE, (match, property) => { | ||
if (report && property in report) { | ||
return report[property as keyof Report]?.toString() ?? match; | ||
} | ||
return match; | ||
}); | ||
} | ||
|
||
/** | ||
* Given a report field, check if the field is for the report title. | ||
*/ | ||
function isReportFieldOfTypeTitle(reportField: PolicyReportField): boolean { | ||
return reportField.type === 'formula' && reportField.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID; | ||
} | ||
|
||
allroundexperts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Get the title for an IOU or expense chat which will be showing the payer and the amount | ||
*/ | ||
function getMoneyRequestReportName(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> | undefined = undefined): string { | ||
const reportFields = Object.entries(allPolicyReportFields ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY_REPORT_FIELDS, '') === report?.policyID)?.[1]; | ||
const titleReportField = Object.values(reportFields ?? {})?.find((field) => field.type === 'formula'); | ||
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. Could we extract one or two helper functions here? Long chain of invocations, giving it some name could help the readability 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. Done. |
||
if (titleReportField && Permissions.canUseReportFields(allBetas ?? [])) { | ||
return getReportFieldTitle(report, titleReportField); | ||
} | ||
const moneyRequestTotal = getMoneyRequestReimbursableTotal(report); | ||
const formattedAmount = CurrencyUtils.convertToDisplayString(moneyRequestTotal, report?.currency, hasOnlyDistanceRequestTransactions(report?.reportID)); | ||
const payerOrApproverName = isExpenseReport(report) ? getPolicyName(report, false, policy) : getDisplayNameForParticipant(report?.managerID) ?? ''; | ||
|
@@ -4551,32 +4596,6 @@ function navigateToPrivateNotes(report: Report, session: Session) { | |
Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID)); | ||
} | ||
|
||
/** | ||
* Given a report field and a report, get the title of the field. | ||
* This is specially useful when we have a report field of type formula. | ||
*/ | ||
function getReportFieldTitle(report: OnyxEntry<Report>, reportField: PolicyReportField): string { | ||
const value = report?.reportFields?.[reportField.fieldID] ?? reportField.defaultValue; | ||
|
||
if (reportField.type !== 'formula') { | ||
return value; | ||
} | ||
|
||
return value.replaceAll(CONST.REGEX.REPORT_FIELD_TITLE, (match, property) => { | ||
if (report && property in report) { | ||
return report[property as keyof Report]?.toString() ?? match; | ||
} | ||
return match; | ||
}); | ||
} | ||
|
||
/** | ||
* Given a report field, check if the field is for the report title. | ||
*/ | ||
function isReportFieldOfTypeTitle(reportField: PolicyReportField): boolean { | ||
return reportField.type === 'formula' && reportField.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID; | ||
} | ||
|
||
/** | ||
* Checks if thread replies should be displayed | ||
*/ | ||
|
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.
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 hope it's not one of these collections we're nuking and un-nuking all over again...
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.
What do you mean @cubuspl42? This is a new collection that we built specifically for the report fields feature.
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.
There is (or might be?) a pattern that sometimes we add an Onyx-synchronized in-memory collection just to nuke it later for performance reasons. But I don't have any sources handy right now. Likely we'll be fine 🤷♂️
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.
Hm... The only reason why I used it like this was because this function is being used at a lot of places and getting this in all of those places might cause un-needed re-renders. Besides, I see that we're still doing this for
report
andpolicies
.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.
Yeah, it was a general comment, not a change request. This one doesn't need a resolution.