Skip to content

Commit

Permalink
create a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
nkdengineer committed Jun 20, 2024
1 parent 0c14761 commit 45a3c12
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
33 changes: 27 additions & 6 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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:
*
Expand Down Expand Up @@ -7025,6 +7043,7 @@ export {
canShowReportRecipientLocalTime,
canUserPerformWriteAction,
chatIncludesChronos,
chatIncludesChronosWithID,
chatIncludesConcierge,
createDraftTransactionAndNavigateToParticipantSelector,
doesReportBelongToWorkspace,
Expand Down Expand Up @@ -7130,6 +7149,7 @@ export {
isAllowedToSubmitDraftExpenseReport,
isAnnounceRoom,
isArchivedRoom,
isArchivedRoomWithID,
isClosedReport,
isCanceledTaskReport,
isChatReport,
Expand Down Expand Up @@ -7201,6 +7221,7 @@ export {
isValidReportIDFromPath,
isWaitingForAssigneeToCompleteTask,
isInvoiceRoom,
isInvoiceRoomWithID,
isInvoiceReport,
isOpenInvoiceReport,
canWriteInReport,
Expand Down
7 changes: 1 addition & 6 deletions src/libs/actions/ReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ function BaseReportActionContextMenu({
checkIfContextMenuActive?.();
setShouldKeepOpen(false);
},
ReportUtils.isArchivedRoom(originalReportID),
ReportUtils.chatIncludesChronos(originalReportID),
ReportUtils.isArchivedRoomWithID(originalReportID),
ReportUtils.chatIncludesChronosWithID(originalReportID),
undefined,
undefined,
filteredContextMenuActions,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ function ReportActionItem({
draftMessage ?? '',
() => setIsContextMenuActive(true),
toggleContextMenuFromActiveReportAction,
ReportUtils.isArchivedRoom(originalReportID),
ReportUtils.chatIncludesChronos(originalReportID),
ReportUtils.isArchivedRoomWithID(originalReportID),
ReportUtils.chatIncludesChronosWithID(originalReportID),
false,
false,
[],
Expand Down Expand Up @@ -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}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepParticipants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 45a3c12

Please sign in to comment.