Skip to content
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

Remove exported getReport() #40523

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Text from '@components/Text';
import useCurrentReportID from '@hooks/useCurrentReportID';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import {getReport} from '@libs/ReportUtils';
import * as ReportUtils from '@libs/ReportUtils';
import Navigation from '@navigation/Navigation';
import CONST from '@src/CONST';
Expand All @@ -35,7 +34,7 @@ const getMentionDetails = (htmlAttributeReportID: string, currentReport: OnyxEnt

// Get mention details based on reportID from tag attribute
if (!isEmpty(htmlAttributeReportID)) {
const report = getReport(htmlAttributeReportID);
const report = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${htmlAttributeReportID}`];

reportID = report?.reportID ?? undefined;
mentionDisplayText = removeLeadingLTRAndHash(report?.reportName ?? report?.displayName ?? htmlAttributeReportID);
Expand All @@ -61,8 +60,8 @@ function MentionReportRenderer({style, tnode, TDefaultRenderer, reports, ...defa
const StyleUtils = useStyleUtils();
const htmlAttributeReportID = tnode.attributes.reportid;

const currentReportID = useCurrentReportID();
const currentReport = getReport(currentReportID?.currentReportID);
const currentReportIDValue = useCurrentReportID();
const currentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${currentReportIDValue?.currentReportID}`] ?? null;
const isGroupPolicyReport = useMemo(() => (currentReport && !isEmptyObject(currentReport) ? ReportUtils.isGroupPolicy(currentReport) : false), [currentReport]);

const mentionDetails = getMentionDetails(htmlAttributeReportID, currentReport, reports, tnode);
Expand All @@ -72,7 +71,7 @@ function MentionReportRenderer({style, tnode, TDefaultRenderer, reports, ...defa
const {reportID, mentionDisplayText} = mentionDetails;

const navigationRoute = reportID ? ROUTES.REPORT_WITH_ID.getRoute(reportID) : undefined;
const isCurrentRoomMention = reportID === currentReportID?.currentReportID;
const isCurrentRoomMention = reportID === currentReportIDValue?.currentReportID;

const flattenStyle = StyleSheet.flatten(style as TextStyle);
const {color, ...styleWithoutColor} = flattenStyle;
Expand Down
13 changes: 9 additions & 4 deletions src/components/LHNOptionsList/OptionRowLHN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useFocusEffect} from '@react-navigation/native';
import React, {useCallback, useRef, useState} from 'react';
import type {GestureResponderEvent, ViewStyle} from 'react-native';
import {StyleSheet, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import DisplayNames from '@components/DisplayNames';
import Hoverable from '@components/Hoverable';
import Icon from '@components/Icon';
Expand All @@ -25,10 +26,11 @@ import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManag
import * as ReportUtils from '@libs/ReportUtils';
import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {OptionRowLHNProps} from './types';
import type {OptionRowLHNOnyxProps, OptionRowLHNProps} from './types';

function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment}: OptionRowLHNProps) {
function OptionRowLHN({reportID, report, isFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment}: OptionRowLHNProps) {
const theme = useTheme();
const styles = useThemeStyles();
const popoverAnchor = useRef<View>(null);
Expand Down Expand Up @@ -104,7 +106,6 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
const statusClearAfterDate = optionItem.status?.clearAfter ?? '';
const formattedDate = DateUtils.getStatusUntilDate(statusClearAfterDate);
const statusContent = formattedDate ? `${statusText ? `${statusText} ` : ''}(${formattedDate})` : statusText;
const report = ReportUtils.getReport(optionItem.reportID ?? '');
const isStatusVisible = !!emojiCode && ReportUtils.isOneOnOneChat(!isEmptyObject(report) ? report : null);

const isGroupChat = ReportUtils.isGroupChat(optionItem) || ReportUtils.isDeprecatedGroupDM(optionItem);
Expand Down Expand Up @@ -285,4 +286,8 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti

OptionRowLHN.displayName = 'OptionRowLHN';

export default React.memo(OptionRowLHN);
export default withOnyx<OptionRowLHNProps, OptionRowLHNOnyxProps>({
report: {
key: ({optionItem}) => `${ONYXKEYS.COLLECTION.REPORT}${optionItem?.reportID}`,
},
})(React.memo(OptionRowLHN));
gijoe0295 marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 7 additions & 2 deletions src/components/LHNOptionsList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ type OptionRowLHNDataProps = {
onLayout?: (event: LayoutChangeEvent) => void;
};

type OptionRowLHNProps = {
type OptionRowLHNOnyxProps = {
/** Data of the report that the option is for */
report: OnyxEntry<Report>;
};

type OptionRowLHNProps = OptionRowLHNOnyxProps & {
/** The ID of the report that the option is for */
reportID: string;

Expand All @@ -141,4 +146,4 @@ type OptionRowLHNProps = {

type RenderItemProps = {item: string};

export type {LHNOptionsListProps, OptionRowLHNDataProps, OptionRowLHNProps, LHNOptionsListOnyxProps, RenderItemProps};
export type {LHNOptionsListProps, OptionRowLHNDataProps, OptionRowLHNProps, OptionRowLHNOnyxProps, LHNOptionsListOnyxProps, RenderItemProps};
8 changes: 7 additions & 1 deletion src/components/SettlementButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type SettlementButtonOnyxProps = {

/** The policy of the report */
policy: OnyxEntry<Policy>;

/** When the button is opened via an IOU, the chatReport that the IOU is linked to */
chatReport: OnyxEntry<Report>;
};

type SettlementButtonProps = SettlementButtonOnyxProps & {
Expand Down Expand Up @@ -118,6 +121,7 @@ function SettlementButton({
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
},
buttonSize = CONST.DROPDOWN_BUTTON_SIZE.MEDIUM,
chatReport,
chatReportID = '',
currency = CONST.CURRENCY.USD,
enablePaymentsRoute,
Expand Down Expand Up @@ -148,7 +152,6 @@ function SettlementButton({
}, []);

const session = useSession();
const chatReport = ReportUtils.getReport(chatReportID);
const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport);
const shouldShowPaywithExpensifyOption = !isPaidGroupPolicy || (!shouldHidePaymentOptions && ReportUtils.isPayer(session, iouReport as OnyxEntry<Report>));
const shouldShowPayElsewhereOption = !isPaidGroupPolicy || policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL;
Expand Down Expand Up @@ -278,4 +281,7 @@ export default withOnyx<SettlementButtonProps, SettlementButtonOnyxProps>({
policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
},
})(SettlementButton);
13 changes: 11 additions & 2 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {findFocusedRoute} from '@react-navigation/core';
import type {EventArg, NavigationContainerEventMap} from '@react-navigation/native';
import {CommonActions, getPathFromState, StackActions} from '@react-navigation/native';
import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import Log from '@libs/Log';
import * as ReportUtils from '@libs/ReportUtils';
import {getReport} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import type {HybridAppRoute, Route} from '@src/ROUTES';
import ROUTES, {HYBRID_APP_ROUTES} from '@src/ROUTES';
import {PROTECTED_SCREENS} from '@src/SCREENS';
Expand All @@ -30,6 +32,13 @@ let pendingRoute: Route | null = null;

let shouldPopAllStateOnUP = false;

let allReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => (allReports = value),
});

/**
* Inform the navigation that next time user presses UP we should pop all the state back to LHN.
*/
Expand Down Expand Up @@ -57,7 +66,7 @@ const dismissModal = (reportID?: string, ref = navigationRef) => {
originalDismissModal(ref);
return;
}
const report = getReport(reportID);
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? null;
originalDismissModalWithReport({reportID, ...report}, ref);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import applyOnyxUpdatesReliably from '@libs/actions/applyOnyxUpdatesReliably';
import * as ActiveClientManager from '@libs/ActiveClientManager';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils';
import {extractPolicyIDFromPath} from '@libs/PolicyUtils';
import {doesReportBelongToWorkspace, getReport} from '@libs/ReportUtils';
import {doesReportBelongToWorkspace} from '@libs/ReportUtils';
import Visibility from '@libs/Visibility';
import * as Modal from '@userActions/Modal';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {OnyxUpdatesFromServer} from '@src/types/onyx';
import type * as OnyxTypes from '@src/types/onyx';
gijoe0295 marked this conversation as resolved.
Show resolved Hide resolved
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import PushNotification from './index';

Expand All @@ -26,6 +27,13 @@ Onyx.connect({
},
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => (allReports = value),
});

function getLastUpdateIDAppliedToClient(): Promise<number> {
return new Promise((resolve) => {
Onyx.connect({
Expand Down Expand Up @@ -53,7 +61,7 @@ export default function subscribeToReportCommentPushNotifications() {
}

Log.info('[PushNotification] reliable onyx update received', false, {lastUpdateID, previousUpdateID, onyxDataCount: onyxData?.length ?? 0});
const updates: OnyxUpdatesFromServer = {
const updates: OnyxTypes.OnyxUpdatesFromServer = {
type: CONST.ONYX_UPDATE_TYPES.AIRSHIP,
lastUpdateID,
previousUpdateID,
Expand All @@ -80,7 +88,7 @@ export default function subscribeToReportCommentPushNotifications() {
}

const policyID = lastVisitedPath && extractPolicyIDFromPath(lastVisitedPath);
const report = getReport(reportID.toString());
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID.toString()}`] ?? null;
const policyEmployeeAccountIDs = policyID ? getPolicyEmployeeAccountIDs(policyID) : [];

const reportBelongsToWorkspace = policyID && !isEmptyObject(report) && doesReportBelongToWorkspace(report, policyEmployeeAccountIDs, policyID);
Expand Down
13 changes: 10 additions & 3 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ Onyx.connect({
},
});

let allReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => (allReports = value),
});

/**
* @param defaultValues {login: accountID} In workspace invite page, when new user is added we pass available data to opt in
* @returns Returns avatar data for a list of user accountIDs
Expand Down Expand Up @@ -592,7 +599,7 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
const properSchemaForMoneyRequestMessage = ReportUtils.getReportPreviewMessage(report, lastReportAction, true, false, null, true);
lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForMoneyRequestMessage);
} else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) {
const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction));
const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)}`];
const lastIOUMoneyReportAction = allSortedReportActions[iouReport?.reportID ?? '']?.find(
(reportAction, key) =>
ReportActionUtils.shouldReportActionBeVisible(reportAction, key) &&
Expand Down Expand Up @@ -774,7 +781,7 @@ function createOption(
* Get the option for a given report.
*/
function getReportOption(participant: Participant): ReportUtils.OptionData {
const report = ReportUtils.getReport(participant.reportID);
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`];

const option = createOption(
report?.visibleChatMemberAccountIDs ?? [],
Expand Down Expand Up @@ -803,7 +810,7 @@ function getReportOption(participant: Participant): ReportUtils.OptionData {
* Get the option for a policy expense report.
*/
function getPolicyExpenseReportOption(participant: Participant | ReportUtils.OptionData): ReportUtils.OptionData {
const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? ReportUtils.getReport(participant.reportID) : null;
const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`] : null;

const option = createOption(
expenseReport?.visibleChatMemberAccountIDs ?? [],
Expand Down
9 changes: 6 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ type OnyxDataTaskAssigneeChat = {

type Ancestor = {
report: Report;
parentReport: Report;
reportAction: ReportAction;
shouldDisplayNewMarker: boolean;
};
Expand Down Expand Up @@ -1144,7 +1145,8 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry<Report>): boolean
/**
* Whether the provided report is an archived room
*/
function isArchivedRoom(report: OnyxEntry<Report> | EmptyObject): boolean {
function isArchivedRoom(reportOrID: OnyxEntry<Report> | EmptyObject | string): boolean {
const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID;
gijoe0295 marked this conversation as resolved.
Show resolved Hide resolved
return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED;
}

Expand Down Expand Up @@ -4792,7 +4794,8 @@ function getAllPolicyReports(policyID: string): Array<OnyxEntry<Report>> {
/**
* Returns true if Chronos is one of the chat participants (1:1)
*/
function chatIncludesChronos(report: OnyxEntry<Report> | EmptyObject): boolean {
function chatIncludesChronos(reportOrID: OnyxEntry<Report> | EmptyObject | string): boolean {
const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID;
gijoe0295 marked this conversation as resolved.
Show resolved Hide resolved
return Boolean(report?.participantAccountIDs?.includes(CONST.ACCOUNT_ID.CHRONOS));
}

Expand Down Expand Up @@ -5752,6 +5755,7 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto
const isParentReportActionUnread = ReportActionsUtils.isCurrentActionUnread(parentReport, parentReportAction);
allAncestors.push({
report: currentReport,
parentReport,
reportAction: parentReportAction,
shouldDisplayNewMarker: isParentReportActionUnread,
});
Expand Down Expand Up @@ -6101,7 +6105,6 @@ export {
getPolicyType,
getReimbursementDeQueuedActionMessage,
getReimbursementQueuedActionMessage,
getReport,
getReportActionActorAccountID,
getReportDescriptionText,
getReportFieldKey,
Expand Down
Loading
Loading