Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleCon
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {
IntroSelected,
PersonalDetails,
PersonalDetailsList,
Policy,
Expand All @@ -28,7 +27,6 @@ import {formatPhoneNumber as formatPhoneNumberPhoneUtils} from './LocalePhoneNum
import {translateLocal} from './Localize';
// eslint-disable-next-line import/no-cycle
import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage';
import isTrackOnboardingChoice from './OnboardingUtils';
import Parser from './Parser';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
import {getCleanedTagName, isPolicyAdmin, isPolicyFieldListEmpty} from './PolicyUtils';
Expand Down Expand Up @@ -185,6 +183,7 @@ type ComputeReportName = {
// TODO: Make this required when https://github.com/Expensify/App/issues/66411 is done
conciergeReportID?: string;
reportAttributes?: ReportAttributesDerivedValue['reports'];
isTrackIntentUser: boolean | undefined;
};

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Expand All @@ -197,15 +196,6 @@ Onyx.connect({
},
});

let introSelected: OnyxEntry<IntroSelected>;
// eslint-disable-next-line rulesdir/no-onyx-connect -- NextStepUtils is a pure utility called from action files that cannot use hooks
Onyx.connect({
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (value) => {
introSelected = value;
},
});

function generateArchivedReportName(reportName: string): string {
return `${reportName} (${translateLocal('common.archived')}) `;
}
Expand Down Expand Up @@ -436,6 +426,7 @@ function computeReportNameBasedOnReportAction(
parentReport: Report | undefined,
personalDetailsList: OnyxEntry<PersonalDetailsList>,
reportAttributes: ReportAttributesDerivedValue['reports'] | undefined,
isTrackIntentUser: boolean | undefined,
): string | undefined {
if (!parentReportAction) {
return undefined;
Expand All @@ -451,7 +442,7 @@ function computeReportNameBasedOnReportAction(
}
if (
shouldShowMarkAsDone({
isTrackIntentUser: isTrackOnboardingChoice(introSelected?.choice),
isTrackIntentUser,
policy: reportPolicy,
report: parentReport,
})
Expand Down Expand Up @@ -933,6 +924,7 @@ function computeReportName({
allPolicyTags,
conciergeReportID,
reportAttributes,
isTrackIntentUser,
}: ComputeReportName): string {
if (!report?.reportID) {
return '';
Expand All @@ -951,6 +943,7 @@ function computeReportName({
parentReport,
personalDetailsList,
reportAttributes,
isTrackIntentUser,
);

if (parentReportActionBasedName) {
Expand All @@ -976,6 +969,7 @@ function computeReportName({
currentUserLogin,
conciergeReportID,
reportAttributes,
isTrackIntentUser,
});
return getCreatedReportForUnapprovedTransactionsMessage(originalID, reportName, isOriginalReportDeleted(parentReportAction, originalReport), translateLocal);
}
Expand Down
21 changes: 19 additions & 2 deletions src/libs/actions/OnyxDerived/configs/reportAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {getIsOffline} from '@libs/NetworkState';
import isTrackOnboardingChoice from '@libs/OnboardingUtils';
import {getLinkedTransactionID} from '@libs/ReportActionsUtils';
import {computeReportName} from '@libs/ReportNameUtils';
import {generateIsEmptyReport, generateReportAttributes, hasVisibleReportFieldViolations, isArchivedReport, isPolicyAdmin, isPolicyExpenseChat, isValidReport} from '@libs/ReportUtils';
Expand Down Expand Up @@ -90,11 +91,25 @@ export default createOnyxDerivedValueConfig({
ONYXKEYS.COLLECTION.POLICY,
ONYXKEYS.COLLECTION.POLICY_TAGS,
ONYXKEYS.CONCIERGE_REPORT_ID,
ONYXKEYS.NVP_INTRO_SELECTED,
ONYXKEYS.COLLECTION.REPORT_METADATA,
ONYXKEYS.NETWORK,
],
compute: (
[reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, session, policies, policyTags, conciergeReportID],
[
reports,
preferredLocale,
transactionViolations,
reportActions,
reportNameValuePairs,
transactions,
personalDetails,
session,
policies,
policyTags,
conciergeReportID,
introSelected,
],
{currentValue, sourceValues},
) => {
// Read the in-memory offline state directly (NETWORK is a dependency so recompute still fires when it changes).
Expand All @@ -118,7 +133,8 @@ export default createOnyxDerivedValueConfig({
let needsFullRecompute =
(hasKeyTriggeredCompute(ONYXKEYS.NVP_PREFERRED_LOCALE, sourceValues) && preferredLocale !== currentValue?.locale) ||
displayNamesChanged ||
hasKeyTriggeredCompute(ONYXKEYS.CONCIERGE_REPORT_ID, sourceValues);
hasKeyTriggeredCompute(ONYXKEYS.CONCIERGE_REPORT_ID, sourceValues) ||
hasKeyTriggeredCompute(ONYXKEYS.NVP_INTRO_SELECTED, sourceValues);

// if policies are loaded first time, we need to recompute all report attributes to get correct action badge in LHN, such as Approve because it depends on policy's type (see canApproveIOU function)
const policyChangedReportKeys: string[] = [];
Expand Down Expand Up @@ -356,6 +372,7 @@ export default createOnyxDerivedValueConfig({
allPolicyTags: policyTags,
conciergeReportID: conciergeReportID ?? undefined,
reportAttributes: currentValue?.reports,
isTrackIntentUser: isTrackOnboardingChoice(introSelected?.choice),
})
: '',
isEmpty: generateIsEmptyReport(report, isReportArchived),
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/OnyxDerivedTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ describe('OnyxDerived', () => {
const transaction = createRandomTransaction(1);

// When the report attributes are recomputed with both report and transaction updates
reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {});
reportAttributes.compute(
[reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined],
{},
);
const reportAttributesComputedValue = reportAttributes.compute(
[reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined],
[reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined],
{
sourceValues: {
[ONYXKEYS.COLLECTION.REPORT]: {
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/ReportNameUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('ReportNameUtils', () => {
reportActions,
currentUserAccountID: currentUserID,
currentUserLogin,
isTrackIntentUser: false,
});
const participantsPersonalDetails: PersonalDetailsList = [
{
Expand Down Expand Up @@ -556,6 +557,7 @@ describe('ReportNameUtils', () => {
currentUserAccountID,
currentUserLogin: '',
allPolicyTags: policyTagsCollection,
isTrackIntentUser: false,
});

expect(name).toContain('Cost Center');
Expand Down
1 change: 1 addition & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ const computeReportName = (
currentUserAccountID: currentUserID,
currentUserLogin: currentUserEmail,
conciergeReportID,
isTrackIntentUser: false,
});
const participantsPersonalDetails: PersonalDetailsList = {
'1': {
Expand Down
Loading