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 ReportConnection and ReportActionsConnection files #53385

Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0a4a8cd
Remove ReportConnection util
VickyStash Dec 2, 2024
bed2343
Fix import
VickyStash Dec 2, 2024
02bdc4b
Merge branch 'refs/heads/main' into VickyStash/feature/53141-remove-r…
VickyStash Dec 2, 2024
d1399ea
Fix after merging main
VickyStash Dec 2, 2024
30ae430
Merge branch 'refs/heads/main' into VickyStash/feature/53141-remove-r…
VickyStash Dec 4, 2024
f729c68
Updates after merging main
VickyStash Dec 4, 2024
d98bf23
Remove ReportActionsConnection
VickyStash Dec 4, 2024
85d6e92
Minor code improvement
VickyStash Dec 4, 2024
a41c6bc
Merge branch 'refs/heads/main' into VickyStash/feature/53141-remove-r…
VickyStash Dec 5, 2024
808d09a
Fixes after merging main
VickyStash Dec 5, 2024
edd4537
Use ReportUtils.getReport
VickyStash Dec 5, 2024
c623446
Code improvements
VickyStash Dec 5, 2024
88a6349
Remove unnecessary changes
VickyStash Dec 5, 2024
cd0a31e
Code improvements
VickyStash Dec 5, 2024
fd08b48
Code improvements
VickyStash Dec 9, 2024
d01ac8d
Get rid of outdated code
VickyStash Dec 10, 2024
fe555fd
Merge branch 'refs/heads/main' into VickyStash/feature/53141-remove-r…
VickyStash Dec 10, 2024
81a912b
Revert "Use ReportUtils.getReport"
VickyStash Dec 11, 2024
ae50129
Remove ReportUtils.getReport usage
VickyStash Dec 11, 2024
666b576
Merge branch 'refs/heads/main' into VickyStash/feature/53141-remove-r…
VickyStash Dec 11, 2024
c5dfcbc
Remove ReportUtils.getReport usage and fix lint error after merging main
VickyStash Dec 11, 2024
815b4ed
Clean up
VickyStash Dec 11, 2024
6aa985e
Lint fix
VickyStash Dec 11, 2024
b0d3624
Re-run checks
VickyStash Dec 11, 2024
4382c45
Merge branch 'refs/heads/main' into VickyStash/feature/53141-remove-r…
VickyStash Dec 12, 2024
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
6 changes: 2 additions & 4 deletions src/libs/DistanceRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type Policy from '@src/types/onyx/Policy';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import * as CurrencyUtils from './CurrencyUtils';
import * as PolicyUtils from './PolicyUtils';
import * as ReportConnection from './ReportConnection';
import * as ReportUtils from './ReportUtils';
import * as TransactionUtils from './TransactionUtils';

Expand Down Expand Up @@ -282,9 +281,8 @@ function convertToDistanceInMeters(distance: number, unit: Unit): number {
* Returns custom unit rate ID for the distance transaction
*/
function getCustomUnitRateID(reportID: string) {
const allReports = ReportConnection.getAllReports();
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
const report = ReportUtils.getReport(reportID);
const parentReport = report?.parentReportID ? ReportUtils.getReport(report.parentReportID) : undefined;
const policy = PolicyUtils.getPolicy(report?.policyID ?? parentReport?.policyID ?? '-1');
let customUnitRateID: string = CONST.CUSTOM_UNITS.FAKE_P2P_ID;

Expand Down
16 changes: 14 additions & 2 deletions src/libs/Firebase/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import {getAllTransactions, getAllTransactionViolationsLength} from '@libs/actions/Transaction';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import {getActivePolicy, getAllPoliciesLength} from '@libs/PolicyUtils';
import {getReportActionsLength} from '@libs/ReportActionsUtils';
import * as ReportConnection from '@libs/ReportConnection';
import * as SessionUtils from '@libs/SessionUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
import type {PerfAttributes} from './types';

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

function getAttributes<T extends keyof PerfAttributes>(attributes?: T[]): Pick<PerfAttributes, T> {
const session = SessionUtils.getSession();
const policy = getActivePolicy();

const allAttributes: PerfAttributes = {
accountId: session?.accountID?.toString() ?? 'N/A',
reportsLength: ReportConnection.getAllReportsLength().toString(),
reportsLength: Object.keys(allReports ?? {}).length.toString(),
reportActionsLength: getReportActionsLength().toString(),
personalDetailsLength: PersonalDetailsUtils.getPersonalDetailsLength().toString(),
transactionViolationsLength: getAllTransactionViolationsLength().toString(),
Expand Down
14 changes: 11 additions & 3 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import Onyx from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyTagLists, ReportAction} from '@src/types/onyx';
import type {PolicyTagLists, Report, ReportAction} from '@src/types/onyx';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import * as Localize from './Localize';
import Log from './Log';
import * as PolicyUtils from './PolicyUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as ReportConnection from './ReportConnection';
import * as TransactionUtils from './TransactionUtils';

let allPolicyTags: OnyxCollection<PolicyTagLists> = {};
Expand All @@ -25,6 +24,15 @@ Onyx.connect({
},
});

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

/**
* Utility to get message based on boolean literal value.
*/
Expand Down Expand Up @@ -137,7 +145,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
return '';
}
const reportActionOriginalMessage = ReportActionsUtils.getOriginalMessage(reportAction);
const policyID = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.policyID ?? '-1';
const policyID = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.policyID ?? '-1';

const removalFragments: string[] = [];
const setFragments: string[] = [];
Expand Down
4 changes: 1 addition & 3 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {CommonActions, getPathFromState, StackActions} from '@react-navigation/n
import type {OnyxEntry} from 'react-native-onyx';
import Log from '@libs/Log';
import {isCentralPaneName, removePolicyIDParamFromState} from '@libs/NavigationUtils';
import * as ReportConnection from '@libs/ReportConnection';
import * as ReportUtils 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 Down Expand Up @@ -66,7 +64,7 @@ const dismissModal = (reportID?: string, ref = navigationRef) => {
originalDismissModal(ref);
return;
}
const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const report = ReportUtils.getReport(reportID);
originalDismissModalWithReport({reportID, ...report}, ref);
};
// Re-exporting the closeRHPFlow here to fill in default value for navigationRef. The closeRHPFlow isn't defined in this file to avoid cyclic dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import getIsNarrowLayout from '@libs/getIsNarrowLayout';
import type {BottomTabName, CentralPaneName, FullScreenName, NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types';
import {isCentralPaneName} from '@libs/NavigationUtils';
import {extractPolicyIDFromPath, getPathWithoutPolicyID} from '@libs/PolicyUtils';
import * as ReportConnection from '@libs/ReportConnection';
import * as ReportUtils from '@libs/ReportUtils';
import extractPolicyIDFromQuery from '@navigation/extractPolicyIDFromQuery';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Screen} from '@src/SCREENS';
import SCREENS from '@src/SCREENS';
import CENTRAL_PANE_TO_RHP_MAPPING from './CENTRAL_PANE_TO_RHP_MAPPING';
Expand Down Expand Up @@ -160,7 +159,7 @@ function getMatchingRootRouteForRHPRoute(route: NavigationPartialRoute): Navigat
// check for valid reportID in the route params
// if the reportID is valid, we should navigate back to screen report in CPN
const reportID = (route.params as Record<string, string | undefined>)?.reportID;
if (ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportID) {
if (reportID && ReportUtils.getReport(reportID)?.reportID) {
return {name: SCREENS.REPORT, params: {reportID}};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Navigation from '@libs/Navigation/Navigation';
import type {ReportActionPushNotificationData} from '@libs/Notification/PushNotification/NotificationType';
import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils';
import {extractPolicyIDFromPath} from '@libs/PolicyUtils';
import * as ReportConnection from '@libs/ReportConnection';
import {doesReportBelongToWorkspace} from '@libs/ReportUtils';
import * as ReportUtils from '@libs/ReportUtils';
import Visibility from '@libs/Visibility';
import {updateLastVisitedPath} from '@userActions/App';
import * as Modal from '@userActions/Modal';
Expand Down Expand Up @@ -77,7 +77,7 @@ function navigateToReport({reportID, reportActionID}: ReportActionPushNotificati
Log.info('[PushNotification] Navigating to report', false, {reportID, reportActionID});

const policyID = lastVisitedPath && extractPolicyIDFromPath(lastVisitedPath);
const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const report = ReportUtils.getReport(reportID.toString());
const policyEmployeeAccountIDs = policyID ? getPolicyEmployeeAccountIDs(policyID) : [];
const reportBelongsToWorkspace = policyID && !isEmptyObject(report) && doesReportBelongToWorkspace(report, policyEmployeeAccountIDs, policyID);

Expand Down
23 changes: 20 additions & 3 deletions src/libs/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ import {ExpensiMark} from 'expensify-common';
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import Log from './Log';
import * as ReportConnection from './ReportConnection';

const accountIDToNameMap: Record<string, string> = {};

const reportIDToNameMap: Record<string, string> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
return;
}

Object.values(value).forEach((report) => {
if (!report) {
return;
}
reportIDToNameMap[report.reportID] = report.reportName ?? report.reportID;
});
},
});

Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (personalDetailsList) => {
Expand All @@ -30,15 +47,15 @@ type Extras = {
class ExpensiMarkWithContext extends ExpensiMark {
htmlToMarkdown(htmlString: string, extras?: Extras): string {
return super.htmlToMarkdown(htmlString, {
reportIDToName: extras?.reportIDToName ?? ReportConnection.getAllReportsNameMap(),
reportIDToName: extras?.reportIDToName ?? reportIDToNameMap,
accountIDToName: extras?.accountIDToName ?? accountIDToNameMap,
cacheVideoAttributes: extras?.cacheVideoAttributes,
});
}

htmlToText(htmlString: string, extras?: Extras): string {
return super.htmlToText(htmlString, {
reportIDToName: extras?.reportIDToName ?? ReportConnection.getAllReportsNameMap(),
reportIDToName: extras?.reportIDToName ?? reportIDToNameMap,
accountIDToName: extras?.accountIDToName ?? accountIDToNameMap,
cacheVideoAttributes: extras?.cacheVideoAttributes,
});
Expand Down
25 changes: 0 additions & 25 deletions src/libs/ReportActionsConnection.ts

This file was deleted.

18 changes: 13 additions & 5 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import type {MessageElementBase, MessageTextElement} from './MessageElement';
import Parser from './Parser';
import * as PersonalDetailsUtils from './PersonalDetailsUtils';
import * as PolicyUtils from './PolicyUtils';
import * as ReportConnection from './ReportConnection';
import type {OptimisticIOUReportAction, PartialReportAction} from './ReportUtils';
import StringUtils from './StringUtils';
// eslint-disable-next-line import/no-cycle
Expand Down Expand Up @@ -63,6 +62,15 @@ Onyx.connect({
},
});

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

let isNetworkOffline = false;
Onyx.connect({
key: ONYXKEYS.NETWORK,
Expand Down Expand Up @@ -441,7 +449,7 @@ function getCombinedReportActions(
filteredParentReportActions = reportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);
}

const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM;
// Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports
const filteredReportActions = [...filteredParentReportActions, ...filteredTransactionThreadReportActions].filter((action) => {
Expand Down Expand Up @@ -951,7 +959,7 @@ function getMostRecentReportActionLastModified(): string {

// We might not have actions so we also look at the report objects to see if any have a lastVisibleActionLastModified that is more recent. We don't need to get
// any reports that have been updated before either a recently updated report or reportAction as we should be up to date on these
Object.values(ReportConnection.getAllReports() ?? {}).forEach((report) => {
Object.values(allReports ?? {}).forEach((report) => {
const reportLastVisibleActionLastModified = report?.lastVisibleActionLastModified ?? report?.lastVisibleActionCreated;
if (!reportLastVisibleActionLastModified || reportLastVisibleActionLastModified < mostRecentReportActionLastModified) {
return;
Expand Down Expand Up @@ -1044,7 +1052,7 @@ const iouRequestTypes = new Set<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>>([
*/
function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[], isOffline: boolean | undefined = undefined): string | undefined {
// If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report.
const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) {
return;
}
Expand Down Expand Up @@ -1571,7 +1579,7 @@ function wasActionTakenByCurrentUser(reportAction: OnyxInputOrEntry<ReportAction
* Get IOU action for a reportID and transactionID
*/
function getIOUActionForReportID(reportID: string, transactionID: string): OnyxEntry<ReportAction> {
const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const reportActions = getAllReportActions(report?.reportID ?? '');
const action = Object.values(reportActions ?? {})?.find((reportAction) => {
const IOUTransactionID = isMoneyRequestAction(reportAction) ? getOriginalMessage(reportAction)?.IOUTransactionID : -1;
Expand Down
71 changes: 0 additions & 71 deletions src/libs/ReportConnection.ts

This file was deleted.

Loading
Loading