Skip to content
20 changes: 20 additions & 0 deletions src/hooks/usePrivateIsArchivedMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type {PrivateIsArchivedMap} from '@selectors/ReportNameValuePairs';
import {privateIsArchivedMapSelector} from '@selectors/ReportNameValuePairs';
import ONYXKEYS from '@src/ONYXKEYS';
import {getEmptyObject} from '@src/types/utils/EmptyObject';
import useDeepCompareRef from './useDeepCompareRef';
import useOnyx from './useOnyx';

/**
* Hook that returns a map of report IDs to their private_isArchived values
*/
function usePrivateIsArchivedMap(): PrivateIsArchivedMap {
const [privateIsArchivedMap = getEmptyObject<PrivateIsArchivedMap>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
canBeMissing: true,
selector: privateIsArchivedMapSelector,
});

return useDeepCompareRef(privateIsArchivedMap) ?? {};
}

export default usePrivateIsArchivedMap;
37 changes: 28 additions & 9 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
*/
let currentUserLogin: string | undefined;
let currentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 196 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserLogin = value?.email;
Expand All @@ -202,13 +202,13 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 205 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => (allPersonalDetails = isEmptyObject(value) ? {} : value),
});

const policies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 211 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (policy, key) => {
if (!policy || !key || !policy.name) {
Expand All @@ -220,14 +220,14 @@
});

let allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 223 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (val) => (allPolicies = val),
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 230 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -235,12 +235,12 @@
},
});

let allReportNameValuePairs: OnyxCollection<ReportNameValuePairs>;
let allReportNameValuePairsOnyxConnect: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({

Check warning on line 239 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
allReportNameValuePairs = value;
allReportNameValuePairsOnyxConnect = value;
},
});

Expand All @@ -248,7 +248,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
const lastVisibleReportActions: ReportActions = {};
Onyx.connect({

Check warning on line 251 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -286,7 +286,7 @@
lastReportActions[reportID] = firstReportAction;
}

const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
const reportNameValuePairs = allReportNameValuePairsOnyxConnect?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
const isReportArchived = !!reportNameValuePairs?.private_isArchived;
const isWriteActionAllowed = canUserPerformWriteAction(report, isReportArchived);
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
Expand All @@ -311,7 +311,7 @@
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 314 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});
Expand Down Expand Up @@ -872,6 +872,7 @@
report: OnyxInputOrEntry<Report>,
config?: PreviewConfig,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
privateIsArchived?: string,
): SearchOptionData {
const {showChatPreviewLine = false, forcePolicyNamePreview = false, showPersonalDetails = false, selected, isSelected, isDisabled} = config ?? {};

Expand Down Expand Up @@ -930,10 +931,10 @@
result.participantsList = personalDetailList;

if (report) {
const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];
const reportNameValuePairsForReport = allReportNameValuePairsOnyxConnect?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];

// Set properties that are used in SearchOption context
result.private_isArchived = reportNameValuePairs?.private_isArchived;
result.private_isArchived = privateIsArchived ?? reportNameValuePairsForReport?.private_isArchived;
result.keyForList = String(report.reportID);

// Type/category flags already set in initialization above, but update brickRoadIndicator
Expand All @@ -954,7 +955,17 @@
: getAlternateText(result, {showChatPreviewLine, forcePolicyNamePreview}, !!result.private_isArchived, lastActorDetails);

const personalDetailsForCompute: PersonalDetailsList | undefined = personalDetails ?? undefined;
const computedReportName = computeReportName(report, allReports, allPolicies, undefined, allReportNameValuePairs, personalDetailsForCompute, allReportActions, currentUserAccountID);
const computedReportName = computeReportName(
report,
allReports,
allPolicies,
undefined,
undefined,
personalDetailsForCompute,
allReportActions,
currentUserAccountID,
result.private_isArchived,
);
reportName = showPersonalDetails
? getDisplayNameForParticipant({accountID: accountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils}) || formatPhoneNumberPhoneUtils(personalDetail?.login ?? '')
: computedReportName;
Expand Down Expand Up @@ -998,6 +1009,7 @@
*/
function getReportOption(
participant: Participant,
privateIsArchived: string | undefined,
policy: OnyxEntry<Policy>,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
reportDrafts?: OnyxCollection<Report>,
Expand All @@ -1014,14 +1026,15 @@
forcePolicyNamePreview: false,
},
reportAttributesDerived,
privateIsArchived,
);

// Update text & alternateText because createOption returns workspace name only if report is owned by the user
if (option.isSelfDM) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
option.alternateText = translateLocal('reportActionsView.yourSpace');
} else if (option.isInvoiceRoom) {
option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined, currentUserAccountID);
option.text = computeReportName(report, undefined, undefined, undefined, undefined, allPersonalDetails, undefined, currentUserAccountID, privateIsArchived);
// eslint-disable-next-line @typescript-eslint/no-deprecated
option.alternateText = translateLocal('workspace.common.invoices');
} else {
Expand Down Expand Up @@ -1050,7 +1063,12 @@
/**
* Get the display option for a given report.
*/
function getReportDisplayOption(report: OnyxEntry<Report>, unknownUserDetails: OnyxEntry<Participant>, reportAttributesDerived?: ReportAttributesDerivedValue['reports']): OptionData {
function getReportDisplayOption(
report: OnyxEntry<Report>,
unknownUserDetails: OnyxEntry<Participant>,
privateIsArchived: string | undefined,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
): OptionData {
const visibleParticipantAccountIDs = getParticipantsAccountIDsForDisplay(report, true);

const option = createOption(
Expand All @@ -1062,14 +1080,15 @@
forcePolicyNamePreview: false,
},
reportAttributesDerived,
privateIsArchived,
);

// Update text & alternateText because createOption returns workspace name only if report is owned by the user
if (option.isSelfDM) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
option.alternateText = translateLocal('reportActionsView.yourSpace');
} else if (option.isInvoiceRoom) {
option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined, currentUserAccountID);
option.text = computeReportName(report, undefined, undefined, undefined, undefined, allPersonalDetails, undefined, currentUserAccountID, privateIsArchived);
// eslint-disable-next-line @typescript-eslint/no-deprecated
option.alternateText = translateLocal('workspace.common.invoices');
} else if (unknownUserDetails) {
Expand Down
11 changes: 6 additions & 5 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;

Onyx.connect({

Check warning on line 124 in src/libs/ReportNameUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value;
Expand Down Expand Up @@ -551,8 +551,8 @@

function computeChatThreadReportName(
translate: LocalizedTranslate,
isArchived: boolean,
report: Report,
reportNameValuePairs: ReportNameValuePairs,
reports: OnyxCollection<Report>,
parentReportAction?: ReportAction,
): string | undefined {
Expand All @@ -564,7 +564,7 @@
}

const parentReportActionMessage = getReportActionMessageFromActionsUtils(parentReportAction);
const isArchivedNonExpense = isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived);
const isArchivedNonExpense = isArchivedNonExpenseReport(report, isArchived);

if (!isEmptyObject(parentReportAction) && isTransactionThread(parentReportAction)) {
let formattedName = getTransactionReportName({reportAction: parentReportAction});
Expand Down Expand Up @@ -642,15 +642,16 @@
personalDetailsList?: PersonalDetailsList,
reportActions?: OnyxCollection<ReportActions>,
currentUserAccountID?: number,
privateIsArchived?: string,
): string {
if (!report || !report.reportID) {
return '';
}

const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];
const privateIsArchivedValue = privateIsArchived ?? allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]?.private_isArchived;
const reportPolicy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];

const isArchivedNonExpense = isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived);
const isArchivedNonExpense = isArchivedNonExpenseReport(report, !!privateIsArchivedValue);

const parentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
const parentReportAction = isThread(report) ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report.parentReportActionID] : undefined;
Expand All @@ -667,7 +668,7 @@
}

// eslint-disable-next-line @typescript-eslint/no-deprecated
const chatThreadReportName = computeChatThreadReportName(translateLocal, report, reportNameValuePairs ?? {}, reports ?? {}, parentReportAction);
const chatThreadReportName = computeChatThreadReportName(translateLocal, !!privateIsArchivedValue, report, reports ?? {}, parentReportAction);
if (chatThreadReportName) {
return chatThreadReportName;
}
Expand Down
8 changes: 7 additions & 1 deletion src/pages/Share/ShareDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useThemeStyles from '@hooks/useThemeStyles';
import {addAttachmentWithComment, addComment, openReport} from '@libs/actions/Report';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
Expand Down Expand Up @@ -61,8 +62,13 @@ function ShareDetailsPage({route}: ShareDetailsPageProps) {
const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);

const report: OnyxEntry<ReportType> = getReportOrDraftReport(reportOrAccountID);
const privateIsArchivedMap = usePrivateIsArchivedMap();
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`];
const ancestors = useAncestors(report);
const displayReport = useMemo(() => getReportDisplayOption(report, unknownUserDetails, reportAttributesDerived), [report, unknownUserDetails, reportAttributesDerived]);
const displayReport = useMemo(
() => getReportDisplayOption(report, unknownUserDetails, privateIsArchived, reportAttributesDerived),
[report, unknownUserDetails, privateIsArchived, reportAttributesDerived],
);

const shouldShowAttachment = !isTextShared;
const fileSource = shouldUsePreValidatedFile ? (validatedFile?.uri ?? '') : (currentAttachment?.content ?? '');
Expand Down
9 changes: 6 additions & 3 deletions src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useThemeStyles from '@hooks/useThemeStyles';
import type {GpsPoint} from '@libs/actions/IOU';
Expand Down Expand Up @@ -56,6 +57,7 @@ function SubmitDetailsPage({
const [lastLocationPermissionPrompt] = useOnyx(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, {canBeMissing: false});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector});
const privateIsArchivedMap = usePrivateIsArchivedMap();
const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true});
const [validFilesToUpload] = useOnyx(ONYXKEYS.VALIDATED_FILE_OBJECT, {canBeMissing: true});
const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${getIOURequestPolicyID(transaction, report)}`, {canBeMissing: true});
Expand Down Expand Up @@ -107,9 +109,10 @@ function SubmitDetailsPage({
}, [reportOrAccountID, policy, personalPolicy, report, parentReport, currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies]);

const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report, currentUserPersonalDetails.accountID);
const participants = selectedParticipants.map((participant) =>
participant?.accountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant, policy, reportAttributesDerived),
);
const participants = selectedParticipants.map((participant) => {
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${participant.reportID}`];
return participant?.accountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant, privateIsArchived, policy, reportAttributesDerived);
});
const trimmedComment = transaction?.comment?.comment?.trim() ?? '';
const transactionAmount = transaction?.amount ?? 0;
const transactionTaxAmount = transaction?.taxAmount ?? 0;
Expand Down
5 changes: 4 additions & 1 deletion src/pages/iou/request/step/IOURequestStepAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
import {setTransactionReport} from '@libs/actions/Transaction';
Expand Down Expand Up @@ -98,6 +99,7 @@ function IOURequestStepAmount({
const personalPolicy = usePersonalPolicy();
const {duplicateTransactions, duplicateTransactionViolations} = useDuplicateTransactionsAndViolations(transactionID ? [transactionID] : []);
const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector});
const privateIsArchivedMap = usePrivateIsArchivedMap();
const isEditing = action === CONST.IOU.ACTION.EDIT;
const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT;
const isCreateAction = action === CONST.IOU.ACTION.CREATE;
Expand Down Expand Up @@ -209,7 +211,8 @@ function IOURequestStepAmount({
const selectedParticipants = getMoneyRequestParticipantsFromReport(report, currentUserPersonalDetails.accountID);
const participants = selectedParticipants.map((participant) => {
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant, policy, reportAttributesDerived);
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${participant.reportID}`];
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant, privateIsArchived, policy, reportAttributesDerived);
});
const backendAmount = convertToBackendAmount(Number.parseFloat(amount));

Expand Down
Loading
Loading