Skip to content

[No QA] remove getReportAttributes function #62464

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

Closed
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
4 changes: 2 additions & 2 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import getPlatform from '@libs/getPlatform';
import Log from '@libs/Log';
import {getIOUReportIDOfLastAction, getLastMessageTextForReport, hasReportErrors} from '@libs/OptionsListUtils';
import {getOneTransactionThreadReportID, getOriginalMessage, getSortedReportActionsForDisplay, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {canUserPerformWriteAction, getReportAttributes} from '@libs/ReportUtils';
import {canUserPerformWriteAction} from '@libs/ReportUtils';
import isProductTrainingElementDismissed from '@libs/TooltipUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -76,7 +76,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
if (hasReportErrors(report, itemReportActions)) {
return true;
}
const hasGBR = getReportAttributes(report.reportID, reportAttributes)?.requiresAttention;
const hasGBR = reportAttributes?.[report.reportID]?.requiresAttention;
return hasGBR;
});

Expand Down
10 changes: 0 additions & 10 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10769,15 +10769,6 @@ function getReportPersonalDetailsParticipants(report: Report, personalDetailsPar
};
}

function getReportAttributes(reportID: string | undefined, reportAttributes?: ReportAttributesDerivedValue['reports']) {
const attributes = reportAttributes ?? reportAttributesDerivedValue;

if (!reportID || !attributes?.[reportID]) {
return;
}
return attributes[reportID];
}

export {
addDomainToShortMention,
completeShortMention,
Expand Down Expand Up @@ -11155,7 +11146,6 @@ export {
getReportPersonalDetailsParticipants,
isAllowedToSubmitDraftExpenseReport,
isWorkspaceEligibleForReportChange,
getReportAttributes,
};

export type {
Expand Down
25 changes: 18 additions & 7 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {ValueOf} from 'type-fest';
import type {PartialPolicyForSidebar} from '@hooks/useSidebarOrderedReports';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, PersonalDetailsList, ReportActions, ReportAttributesDerivedValue, ReportNameValuePairs, TransactionViolation} from '@src/types/onyx';
import type {PersonalDetails, PersonalDetailsList, ReportActions, ReportAttributesDerivedValue, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
import type Beta from '@src/types/onyx/Beta';
import type {ReportAttributes} from '@src/types/onyx/DerivedValues';
import type Policy from '@src/types/onyx/Policy';
Expand Down Expand Up @@ -76,7 +76,6 @@ import {
getIcons,
getParticipantsAccountIDsForDisplay,
getPolicyName,
getReportAttributes,
getReportDescription,
getReportName,
getReportNameValuePairs,
Expand Down Expand Up @@ -117,7 +116,7 @@ import {
shouldReportShowSubscript,
} from './ReportUtils';
import {getTaskReportActionMessage} from './TaskUtils';
import {getTransaction, getTransactionID} from './TransactionUtils';
import {getTransactionID} from './TransactionUtils';

type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string; phrase3?: string; phrase4?: string; messageText?: string; messageHtml?: string};

Expand Down Expand Up @@ -165,6 +164,18 @@ Onyx.connect({
},
});

let allTransactions: OnyxCollection<Transaction> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
return;
}
allTransactions = Object.fromEntries(Object.entries(value).filter(([, transaction]) => !!transaction));
},
});

function compareStringDates(a: string, b: string): 0 | 1 | -1 {
if (a < b) {
return -1;
Expand Down Expand Up @@ -245,7 +256,7 @@ function getOrderedReportIDs(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
report.isPinned ||
(!isInFocusMode && isArchivedReport(reportNameValuePairs)) ||
getReportAttributes(report.reportID, reportAttributes)?.requiresAttention;
reportAttributes?.[report.reportID]?.requiresAttention;
if (isHidden && !shouldOverrideHidden) {
return;
}
Expand Down Expand Up @@ -294,7 +305,7 @@ function getOrderedReportIDs(

const isPinned = report?.isPinned ?? false;
const rNVPs = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`];
if (isPinned || getReportAttributes(report?.reportID, reportAttributes)?.requiresAttention) {
if (isPinned || reportAttributes?.[report.reportID]?.requiresAttention) {
pinnedAndGBRReports.push(miniReport);
} else if (report?.hasErrorsOtherThanFailedReceipt) {
errorReports.push(miniReport);
Expand Down Expand Up @@ -379,15 +390,15 @@ function getReasonAndReportActionThatHasRedBrickRoad(
const transactionThreadReportID = getOneTransactionThreadReportID(report.reportID, reportActions ?? []);
if (transactionThreadReportID) {
const transactionID = getTransactionID(transactionThreadReportID);
const transaction = getTransaction(transactionID);
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly to report attributes, I think we should get rid of the allTransactions and similar from the utils files as if the transaction changes the component would not re-render

if (hasReceiptError(transaction)) {
return {
reason: CONST.RBR_REASONS.HAS_ERRORS,
};
}
}
const transactionID = getTransactionID(report.reportID);
const transaction = getTransaction(transactionID);
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
if (isTransactionThread(parentReportAction) && hasReceiptError(transaction)) {
return {
reason: CONST.RBR_REASONS.HAS_ERRORS,
Expand Down
Loading