Repository navigation
feat: Integrate report fields with backend #34483
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0f25f75
feat: save the report fields in backend
allroundexperts e089455
fix: revert canUseReportField beta
allroundexperts 04f4296
Merge branch 'main' into feat-34198
allroundexperts 7532fff
fix: lint errors
allroundexperts c91cde9
Merge branch 'main' into feat-34198
allroundexperts 389569d
Merge branch 'main' into feat-34198
allroundexperts b0f6f9b
include the whole reportfield object in the report
allroundexperts 827be79
merge with main
allroundexperts 06b2b16
create new types for the write commands
allroundexperts b58d85b
fix lint issues
allroundexperts 19cafde
fix: typechecks
allroundexperts 72b68c9
fix: remove leftover code
allroundexperts cd576d8
fix: update recently used field implementation
allroundexperts 623d1c2
fix: merge with main
allroundexperts 022efe3
fix: minor refactors to function names
allroundexperts db3738d
fix: lint issues
allroundexperts d0db92f
fix: use ucfirst str lib function and handle more lint issues
allroundexperts a761eb2
merge with main
allroundexperts 0c9939a
fix: include the whole report field object in the set report field call
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| type SetReportFieldParams = { | ||
| reportID: string; | ||
| reportFields: string; | ||
| }; | ||
|
|
||
| export default SetReportFieldParams; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| type SetReportNameParams = { | ||
| reportID: string; | ||
| reportName: string; | ||
| }; | ||
|
|
||
| export default SetReportNameParams; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -14,7 +14,20 @@ import CONST from '@src/CONST'; | |
| import type {ParentNavigationSummaryParams, TranslationPaths} from '@src/languages/types'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type {Beta, PersonalDetails, PersonalDetailsList, Policy, PolicyReportField, Report, ReportAction, ReportMetadata, Session, Transaction, TransactionViolation} from '@src/types/onyx'; | ||
| import type { | ||
| Beta, | ||
| PersonalDetails, | ||
| PersonalDetailsList, | ||
| Policy, | ||
| PolicyReportField, | ||
| PolicyReportFields, | ||
| Report, | ||
| ReportAction, | ||
| ReportMetadata, | ||
| Session, | ||
| Transaction, | ||
| TransactionViolation, | ||
| } from '@src/types/onyx'; | ||
| import type {Participant} from '@src/types/onyx/IOU'; | ||
| import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; | ||
| import type {ChangeLog, IOUMessage, OriginalMessageActionName, OriginalMessageCreated, PaymentMethodType} from '@src/types/onyx/OriginalMessage'; | ||
|
|
@@ -439,8 +452,21 @@ Onyx.connect({ | |
| callback: (value) => (allPolicies = value), | ||
| }); | ||
|
|
||
| let allTransactions: OnyxCollection<Transaction> = {}; | ||
| 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 allTransactions: OnyxCollection<Transaction> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
| waitForCollectionCallback: true, | ||
|
|
@@ -1850,10 +1876,74 @@ function getPolicyExpenseChatName(report: OnyxEntry<Report>, policy: OnyxEntry<P | |
| return reportOwnerDisplayName; | ||
| } | ||
|
|
||
| /** | ||
| * Given a report field, check if the field is for the report title. | ||
| */ | ||
| function isReportFieldOfTypeTitle(reportField: OnyxEntry<PolicyReportField>): boolean { | ||
| return reportField?.type === 'formula' && reportField?.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID; | ||
| } | ||
|
|
||
| /** | ||
| * Given a report field, check if the field can be edited or not. | ||
| * For title fields, its considered disabled if `deletable` prop is `true` (https://github.com/Expensify/App/issues/35043#issuecomment-1911275433) | ||
| * For non title fields, its considered disabled if: | ||
| * 1. The user is not admin of the report | ||
| * 2. Report is settled or it is closed | ||
| */ | ||
| function isReportFieldDisabled(report: OnyxEntry<Report>, reportField: OnyxEntry<PolicyReportField>, policy: OnyxEntry<Policy>): boolean { | ||
| const isReportSettled = isSettled(report?.reportID); | ||
| const isReportClosed = report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED; | ||
| const isTitleField = isReportFieldOfTypeTitle(reportField); | ||
| const isAdmin = isPolicyAdmin(report?.policyID ?? '', {[`${ONYXKEYS.COLLECTION.POLICY}${policy?.id ?? ''}`]: policy}); | ||
| return isTitleField ? !reportField?.deletable : !isAdmin && (isReportSettled || isReportClosed); | ||
| } | ||
|
Comment on lines
+1893
to
+1899
Member
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. For the title field, before checking Also we should have added Coming from #57416 |
||
|
|
||
| /** | ||
| * Given a set of report fields, return the field of type formula | ||
| */ | ||
| function getFormulaTypeReportField(reportFields: PolicyReportFields) { | ||
| return Object.values(reportFields).find((field) => field.type === 'formula'); | ||
| } | ||
|
|
||
| /** | ||
| * Get the report fields attached to the policy given policyID | ||
| */ | ||
| function getReportFieldsByPolicyID(policyID: string) { | ||
| return Object.entries(allPolicyReportFields ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY_REPORT_FIELDS, '') === policyID)?.[1]; | ||
| } | ||
|
|
||
| /** | ||
| * Get the report fields that we should display a MoneyReportView gets opened | ||
| */ | ||
|
|
||
| function getAvailableReportFields(report: Report, policyReportFields: PolicyReportField[]): PolicyReportField[] { | ||
| // Get the report fields that are attached to a report. These will persist even if a field is deleted from the policy. | ||
| const reportFields = Object.values(report.reportFields ?? {}); | ||
| const reportIsSettled = isSettled(report.reportID); | ||
|
|
||
| // If the report is settled, we don't want to show any new field that gets added to the policy. | ||
| if (reportIsSettled) { | ||
| return reportFields; | ||
| } | ||
|
|
||
| // If the report is unsettled, we want to merge the new fields that get added to the policy with the fields that | ||
| // are attached to the report. | ||
| const mergedFieldIds = Array.from(new Set([...policyReportFields.map(({fieldID}) => fieldID), ...reportFields.map(({fieldID}) => fieldID)])); | ||
| return mergedFieldIds.map((id) => report?.reportFields?.[id] ?? policyReportFields.find(({fieldID}) => fieldID === id)) as PolicyReportField[]; | ||
| } | ||
|
|
||
| /** | ||
| * 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 isReportSettled = isSettled(report?.reportID ?? ''); | ||
| const reportFields = isReportSettled ? report?.reportFields : getReportFieldsByPolicyID(report?.policyID ?? ''); | ||
| const titleReportField = getFormulaTypeReportField(reportFields ?? {}); | ||
|
|
||
| if (titleReportField && report?.reportName && Permissions.canUseReportFields(allBetas ?? [])) { | ||
| return report.reportName; | ||
| } | ||
|
|
||
| const moneyRequestTotal = getMoneyRequestSpendBreakdown(report).totalDisplaySpend; | ||
| const formattedAmount = CurrencyUtils.convertToDisplayString(moneyRequestTotal, report?.currency, hasOnlyDistanceRequestTransactions(report?.reportID)); | ||
| const payerOrApproverName = isExpenseReport(report) ? getPolicyName(report, false, policy) : getDisplayNameForParticipant(report?.managerID) ?? ''; | ||
|
|
@@ -4538,32 +4628,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 | ||
| */ | ||
|
|
@@ -4790,14 +4854,15 @@ export { | |
| canEditWriteCapability, | ||
| hasSmartscanError, | ||
| shouldAutoFocusOnKeyPress, | ||
| getReportFieldTitle, | ||
| shouldDisplayThreadReplies, | ||
| shouldDisableThread, | ||
| doesReportBelongToWorkspace, | ||
| getChildReportNotificationPreference, | ||
| isReportParticipant, | ||
| isValidReport, | ||
| isReportFieldOfTypeTitle, | ||
| isReportFieldDisabled, | ||
| getAvailableReportFields, | ||
| }; | ||
|
|
||
| export type { | ||
|
|
||
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.
Should Custom report name field necessarily be a formula?
We have an issue here #49077. The bug here is if we set the custom report name as some text string instead of a formula, backend returns the type of the title field as
text. Then this check fails andTitlefield shows up in the report though it should not show up here as per this codeApp/src/components/ReportActionItem/MoneyReportView.tsx
Lines 108 to 109 in 1354957
Can you please help here?
@thienlnam @allroundexperts @jjcoffee