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 export ReportUtil.getReport function #43632

Merged
merged 22 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
create a separate method
nkdengineer committed Jun 20, 2024
commit 45a3c12b3ab8bc50ab666162ea1d81ede2a84663
33 changes: 27 additions & 6 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
@@ -886,11 +886,16 @@ function isPolicyExpenseChat(report: OnyxInputOrEntry<Report> | Participant | Em
return getChatType(report) === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT || (report?.isPolicyExpenseChat ?? false);
}

function isInvoiceRoom(reportOrID: OnyxEntry<Report> | EmptyObject | string): boolean {
const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] : reportOrID;
function isInvoiceRoom(report: OnyxEntry<Report> | EmptyObject): boolean {
return getChatType(report) === CONST.REPORT.CHAT_TYPE.INVOICE;
}

function isInvoiceRoomWithID(reportID?: string): boolean {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID || -1}`];
return isInvoiceRoom(report);
}

/**
* Checks if a report is a completed task report.
*/
@@ -1232,15 +1237,23 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry<Report>): boolean
/**
* Whether the provided report is an archived room
*/
function isArchivedRoom(reportOrID: OnyxInputOrEntry<Report> | EmptyObject | string, reportNameValuePairs?: OnyxInputOrEntry<ReportNameValuePairs> | EmptyObject): boolean {
const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] : reportOrID;
function isArchivedRoom(report: OnyxInputOrEntry<Report> | EmptyObject, reportNameValuePairs?: OnyxInputOrEntry<ReportNameValuePairs> | EmptyObject): boolean {
if (reportNameValuePairs) {
return reportNameValuePairs.isArchived;
}

return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED;
}

/**
* Whether the report with the provided reportID is an archived room
*/
function isArchivedRoomWithID(reportID?: string) {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID || -1}`];
return isArchivedRoom(report);
}

/**
* Whether the provided report is a closed report
*/
@@ -5526,12 +5539,17 @@ function getAllPolicyReports(policyID: string): Array<OnyxEntry<Report>> {
/**
* Returns true if Chronos is one of the chat participants (1:1)
*/
function chatIncludesChronos(reportOrID: OnyxInputOrEntry<Report> | EmptyObject | string): boolean {
const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] : reportOrID;
function chatIncludesChronos(report: OnyxInputOrEntry<Report> | EmptyObject): boolean {
const participantAccountIDs = Object.keys(report?.participants ?? {}).map(Number);
return participantAccountIDs.includes(CONST.ACCOUNT_ID.CHRONOS);
}

function chatIncludesChronosWithID(reportID?: string): boolean {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID || -1}`];
return chatIncludesChronos(report);
}

/**
* Can only flag if:
*
@@ -7025,6 +7043,7 @@ export {
canShowReportRecipientLocalTime,
canUserPerformWriteAction,
chatIncludesChronos,
chatIncludesChronosWithID,
chatIncludesConcierge,
createDraftTransactionAndNavigateToParticipantSelector,
doesReportBelongToWorkspace,
@@ -7130,6 +7149,7 @@ export {
isAllowedToSubmitDraftExpenseReport,
isAnnounceRoom,
isArchivedRoom,
isArchivedRoomWithID,
isClosedReport,
isCanceledTaskReport,
isChatReport,
@@ -7201,6 +7221,7 @@ export {
isValidReportIDFromPath,
isWaitingForAssigneeToCompleteTask,
isInvoiceRoom,
isInvoiceRoomWithID,
isInvoiceReport,
isOpenInvoiceReport,
canWriteInReport,
7 changes: 1 addition & 6 deletions src/libs/actions/ReportActions.ts
Original file line number Diff line number Diff line change
@@ -14,12 +14,7 @@ let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
if (!actions) {
return;
}
allReportActions = actions;
},
callback: (value) => (allReportActions = value),
});

let allReports: OnyxCollection<OnyxReportType>;
Original file line number Diff line number Diff line change
@@ -218,8 +218,8 @@ function BaseReportActionContextMenu({
checkIfContextMenuActive?.();
setShouldKeepOpen(false);
},
ReportUtils.isArchivedRoom(originalReportID),
ReportUtils.chatIncludesChronos(originalReportID),
ReportUtils.isArchivedRoomWithID(originalReportID),
ReportUtils.chatIncludesChronosWithID(originalReportID),
undefined,
undefined,
filteredContextMenuActions,
6 changes: 3 additions & 3 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
@@ -342,8 +342,8 @@ function ReportActionItem({
draftMessage ?? '',
() => setIsContextMenuActive(true),
toggleContextMenuFromActiveReportAction,
ReportUtils.isArchivedRoom(originalReportID),
ReportUtils.chatIncludesChronos(originalReportID),
ReportUtils.isArchivedRoomWithID(originalReportID),
ReportUtils.chatIncludesChronosWithID(originalReportID),
false,
false,
[],
@@ -868,7 +868,7 @@ function ReportActionItem({
disabledActions={!ReportUtils.canWriteInReport(report) ? RestrictedReadOnlyContextMenuActions : []}
isVisible={hovered && draftMessage === undefined && !hasErrors}
draftMessage={draftMessage}
isChronosReport={ReportUtils.chatIncludesChronos(originalReportID)}
isChronosReport={ReportUtils.chatIncludesChronosWithID(originalReportID)}
checkIfContextMenuActive={toggleContextMenuFromActiveReportAction}
setIsEmojiPickerActive={setIsEmojiPickerActive}
/>
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ function IOURequestStepParticipants({

const firstParticipantReportID = val[0]?.reportID ?? '';
const rateID = DistanceRequestUtils.getCustomUnitRateID(firstParticipantReportID);
const isInvoice = iouType === CONST.IOU.TYPE.INVOICE && ReportUtils.isInvoiceRoom(firstParticipantReportID);
const isInvoice = iouType === CONST.IOU.TYPE.INVOICE && ReportUtils.isInvoiceRoomWithID(firstParticipantReportID);
numberOfParticipants.current = val.length;

IOU.setMoneyRequestParticipants(transactionID, val);