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

Don't use report for isArchived check #52805

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
85753dd
Don't use report for isArchived check
srikarparsi Nov 20, 2024
0c31b92
update optional
srikarparsi Nov 20, 2024
d1bd791
ReportUtils fix
srikarparsi Nov 20, 2024
139c91d
parentReportNameValuePairs fix
srikarparsi Nov 20, 2024
bd7aa22
child report name value pairs
srikarparsi Nov 20, 2024
37e4804
fix tests
srikarparsi Nov 21, 2024
ecd47fa
type collection
srikarparsi Nov 22, 2024
2d7af61
optimistic and failure for deletePolicy
srikarparsi Nov 23, 2024
32c275b
small fixes
srikarparsi Nov 26, 2024
36ae672
Merge branch 'main' into srikar-dontUseReportInArchived
srikarparsi Dec 9, 2024
5d71aee
fix errors
srikarparsi Dec 9, 2024
8c93e83
unsafe
srikarparsi Dec 9, 2024
cea8821
merge main
srikarparsi Dec 16, 2024
22f1ebd
fix ts errors
srikarparsi Dec 16, 2024
764dd81
typecheck again
srikarparsi Dec 16, 2024
e0d6894
try optionData
srikarparsi Dec 16, 2024
92616dd
more private_isArchived fixes
srikarparsi Dec 16, 2024
c8140e0
remove private_isArchived from report type
srikarparsi Dec 16, 2024
85ec285
fix lint
srikarparsi Dec 16, 2024
a1c089c
add parantheses for lint
srikarparsi Dec 16, 2024
5b43c6f
option data changes
srikarparsi Dec 16, 2024
e30dd02
add deps
srikarparsi Dec 16, 2024
a9f7912
fix perf tests
srikarparsi Dec 16, 2024
340c0ca
listen for changes
srikarparsi Dec 23, 2024
3fbe302
Merge branch 'main' into srikar-dontUseReportInArchived
srikarparsi Dec 23, 2024
521abb1
merge main
srikarparsi Dec 26, 2024
783e8bc
merge
srikarparsi Dec 26, 2024
dfa7dd7
lint and typecheck
srikarparsi Dec 26, 2024
f257065
Merge branch 'main' into srikar-dontUseReportInArchived
srikarparsi Dec 27, 2024
06eb9c7
merge main
srikarparsi Dec 31, 2024
46ed7a8
typecheck
srikarparsi Dec 31, 2024
68b1c89
Merge branch 'main' into srikar-dontUseReportInArchived
srikarparsi Jan 9, 2025
e681f3a
partial SidebarOrder test fix
srikarparsi Jan 9, 2025
5be276c
ReportUtils tests
srikarparsi Jan 9, 2025
31e774a
More fixes to ReportUtilsTest
srikarparsi Jan 9, 2025
7fb76b5
use afterEach
srikarparsi Jan 9, 2025
b3f1726
Merge branch 'main' into srikar-dontUseReportInArchived
srikarparsi Jan 13, 2025
24cdd83
fix SidebarTest.js
srikarparsi Jan 13, 2025
4282eb9
fix jest tests
srikarparsi Jan 13, 2025
16b2bd8
merge conflicts
srikarparsi Jan 14, 2025
d141983
some lint, prettier and test fix
srikarparsi Jan 15, 2025
4753a3e
type errors
srikarparsi Jan 15, 2025
e6d33cf
merge conflicts
srikarparsi Jan 17, 2025
637dce7
fix error
srikarparsi Jan 17, 2025
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
8 changes: 6 additions & 2 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as DraftCommentUtils from '@libs/DraftCommentUtils';

Check failure on line 19 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as OptionsListUtils from '@libs/OptionsListUtils';

Check failure on line 20 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as ReportActionsUtils from '@libs/ReportActionsUtils';

Check failure on line 21 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as ReportUtils from '@libs/ReportUtils';

Check failure on line 22 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -36,6 +36,7 @@
const route = useRoute();

const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS);
const [policy] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
Expand Down Expand Up @@ -117,10 +118,11 @@
const renderItem = useCallback(
({item: reportID}: RenderItemProps): ReactElement => {
const itemFullReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const itemParentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${itemFullReport?.parentReportID ?? '-1'}`];

Check failure on line 121 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const itemReportNameValuePairs = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
const itemReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport?.parentReportID}`];
const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? '-1'];

Check failure on line 125 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check


let invoiceReceiverPolicyID = '-1';
if (itemFullReport?.invoiceReceiver && 'policyID' in itemFullReport.invoiceReceiver) {
Expand All @@ -136,8 +138,8 @@

const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`];
const transactionID = ReportActionsUtils.isMoneyRequestAction(itemParentReportAction)
? ReportActionsUtils.getOriginalMessage(itemParentReportAction)?.IOUTransactionID ?? '-1'

Check failure on line 141 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

: '-1';

Check failure on line 142 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const itemTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
const hasDraftComment = DraftCommentUtils.isValidDraftComment(draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`]);

Expand All @@ -149,7 +151,7 @@
let lastReportActionTransactionID = '';

if (ReportActionsUtils.isMoneyRequestAction(lastReportAction)) {
lastReportActionTransactionID = ReportActionsUtils.getOriginalMessage(lastReportAction)?.IOUTransactionID ?? '-1';

Check failure on line 154 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

}
const lastReportActionTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${lastReportActionTransactionID}`];

Expand All @@ -171,6 +173,7 @@
<OptionRowLHNData
reportID={reportID}
fullReport={itemFullReport}
reportNameValuePairs={itemReportNameValuePairs}
reportActions={itemReportActions}
parentReportAction={itemParentReportAction}
iouReportReportActions={itemIouReportReportActions}
Expand Down Expand Up @@ -200,6 +203,7 @@
preferredLocale,
reportActions,
reports,
reportNameValuePairs,
shouldDisableFocusOptions,
transactions,
transactionViolations,
Expand All @@ -208,8 +212,8 @@
);

const extraData = useMemo(
() => [reportActions, reports, transactionViolations, policy, personalDetails, data.length, draftComments, optionMode, preferredLocale],
[reportActions, reports, transactionViolations, policy, personalDetails, data.length, draftComments, optionMode, preferredLocale],
() => [reportActions, reports, reportNameValuePairs, transactionViolations, policy, personalDetails, data.length, draftComments, optionMode, preferredLocale],
[reportActions, reports, reportNameValuePairs, transactionViolations, policy, personalDetails, data.length, draftComments, optionMode, preferredLocale],
);

const previousOptionMode = usePrevious(optionMode);
Expand Down
3 changes: 3 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {deepEqual} from 'fast-equals';
import React, {useMemo, useRef} from 'react';
import useCurrentReportID from '@hooks/useCurrentReportID';
import * as ReportUtils from '@libs/ReportUtils';

Check failure on line 4 in src/components/LHNOptionsList/OptionRowLHNData.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import SidebarUtils from '@libs/SidebarUtils';
import CONST from '@src/CONST';
import type {OptionData} from '@src/libs/ReportUtils';
Expand All @@ -17,6 +17,7 @@
function OptionRowLHNData({
isFocused = false,
fullReport,
reportNameValuePairs,
reportActions,
personalDetails = {},
preferredLocale = CONST.LOCALES.DEFAULT,
Expand Down Expand Up @@ -45,6 +46,7 @@
// Note: ideally we'd have this as a dependent selector in onyx!
const item = SidebarUtils.getOptionData({
report: fullReport,
reportNameValuePairs,
reportActions,
personalDetails,
preferredLocale: preferredLocale ?? CONST.LOCALES.DEFAULT,
Expand All @@ -70,6 +72,7 @@
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [
fullReport,
reportNameValuePairs,
lastReportActionTransaction,
reportActions,
personalDetails,
Expand Down
5 changes: 4 additions & 1 deletion src/components/LHNOptionsList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type {OptionData} from '@src/libs/ReportUtils';
import type {Locale, PersonalDetailsList, Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation} from '@src/types/onyx';
import type {Locale, PersonalDetailsList, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';

type OptionMode = ValueOf<typeof CONST.OPTION_MODE>;

Expand Down Expand Up @@ -47,6 +47,9 @@ type OptionRowLHNDataProps = {
/** The full data of the report */
fullReport: OnyxEntry<Report>;

/** Array of report name value pairs for this report */
reportNameValuePairs: OnyxEntry<ReportNameValuePairs>;

/** The policy which the user has access to and which the report could be tied to */
policy?: OnyxEntry<Policy>;

Expand Down
2 changes: 1 addition & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const shouldShowBrokenConnectionViolation = TransactionUtils.shouldShowBrokenConnectionViolation(transaction?.transactionID, moneyRequestReport, policy);
const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(moneyRequestReport?.reportID);
const isPayAtEndExpense = TransactionUtils.isPayAtEndExpense(transaction);
const isArchivedReport = ReportUtils.isArchivedReport(moneyRequestReport);
const isArchivedReport = ReportUtils.isArchivedReportWithID(moneyRequestReport?.reportID);
const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID}`, {selector: ReportUtils.getArchiveReason});

const getCanIOUBePaid = useCallback(
Expand Down
3 changes: 2 additions & 1 deletion src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
personalDetails: [],
});
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);

const personalDetails = usePersonalDetails();
const prevPersonalDetails = usePrevious(personalDetails);
Expand All @@ -71,7 +72,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
return newOptions;
});
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [reports]);
}, [reports, reportNameValuePairs]);

/**
* This effect is used to update the options list when personal details change.
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
hasWarningTypeViolations,
isAllowedToApproveExpenseReport,
isAllowedToSubmitDraftExpenseReport,
isArchivedReport,
isArchivedReportWithID,
isInvoiceReport as isInvoiceReportUtils,
isInvoiceRoom as isInvoiceRoomReportUtils,
isOpenExpenseReport as isOpenExpenseReportUtils,
Expand Down Expand Up @@ -242,7 +242,7 @@ function ReportPreview({
formattedMerchant = null;
}

const isArchived = isArchivedReport(iouReport);
const isArchived = isArchivedReportWithID(iouReport?.reportID);
const currentUserAccountID = getCurrentUserAccountID();
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const shouldShowSubmitButton =
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useReportIDs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function ReportIDsContextProvider({
}: ReportIDsContextProviderProps) {
const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {initialValue: CONST.PRIORITY_MODE.DEFAULT});
const [chatReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (c) => mapOnyxCollectionItems(c, policySelector)});
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [reportsDrafts] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
Expand All @@ -73,7 +74,7 @@ function ReportIDsContextProvider({
SidebarUtils.getOrderedReportIDs(currentReportID, chatReports, betas, policies, priorityMode, transactionViolations, activeWorkspaceID, policyMemberAccountIDs),
// we need reports draft in deps array to reload the list when a draft is added or removed
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[chatReports, betas, policies, priorityMode, transactionViolations, activeWorkspaceID, policyMemberAccountIDs, draftAmount],
[chatReports, betas, policies, priorityMode, transactionViolations, activeWorkspaceID, policyMemberAccountIDs, draftAmount, reportNameValuePairs],
);

const orderedReportIDs = useMemo(() => getOrderedReportIDs(), [getOrderedReportIDs]);
Expand Down
8 changes: 4 additions & 4 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {TupleToUnion} from 'type-fest';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Beta, Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation} from '@src/types/onyx';
import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as ReportUtils from './ReportUtils';
import SidebarUtils from './SidebarUtils';
Expand Down Expand Up @@ -60,7 +60,7 @@ type ObjectElement<TOnyx, K extends keyof TOnyx, TCollectionKey extends string |

const OPTIONAL_BOOLEAN_STRINGS = ['true', 'false', 'undefined'];

const REPORT_REQUIRED_PROPERTIES: Array<keyof Report> = ['reportID'] satisfies Array<keyof Report>;
const REPORT_REQUIRED_PROPERTIES: Array<keyof Report | keyof ReportNameValuePairs> = ['reportID'] satisfies Array<keyof Report | keyof ReportNameValuePairs>;

const REPORT_ACTION_REQUIRED_PROPERTIES: Array<keyof ReportAction> = ['reportActionID', 'created', 'actionName'] satisfies Array<keyof ReportAction>;

Expand Down Expand Up @@ -441,7 +441,7 @@ function unionValidation(firstValidation: () => void, secondValidation: () => vo
* @param key - property key
* @param value - value provided by the user
*/
function validateReportDraftProperty(key: keyof Report, value: string) {
function validateReportDraftProperty(key: keyof Report | keyof ReportNameValuePairs, value: string) {
if (REPORT_REQUIRED_PROPERTIES.includes(key) && isEmptyValue(value)) {
throw SyntaxError('debug.missingValue');
}
Expand Down Expand Up @@ -567,7 +567,7 @@ function validateReportDraftProperty(key: keyof Report, value: string) {
case 'pendingAction':
return validateConstantEnum(value, CONST.RED_BRICK_ROAD_PENDING_ACTION);
case 'pendingFields':
return validateObject<ObjectElement<Report, 'pendingFields'>>(value, {
return validateObject<ObjectElement<Report | ReportNameValuePairs, 'pendingFields'>>(value, {
description: CONST.RED_BRICK_ROAD_PENDING_ACTION,
privateNotes: CONST.RED_BRICK_ROAD_PENDING_ACTION,
currency: CONST.RED_BRICK_ROAD_PENDING_ACTION,
Expand Down
8 changes: 5 additions & 3 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
const lastOriginalReportAction = reportID ? lastReportActions[reportID] : undefined;
let lastMessageTextFromReport = '';

if (ReportUtils.isArchivedNonExpenseReport(report)) {
const reportNameValuePairs = ReportUtils.getReportNameValuePairs(reportID);

if (ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs)) {
const archiveReason =
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(ReportActionUtils.isClosedAction(lastOriginalReportAction) && ReportActionUtils.getOriginalMessage(lastOriginalReportAction)?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT;
Expand Down Expand Up @@ -612,7 +614,7 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
}

// we do not want to show report closed in LHN for non archived report so use getReportLastMessage as fallback instead of lastMessageText from report
if (reportID && !report.private_isArchived && report.lastActionType === CONST.REPORT.ACTIONS.TYPE.CLOSED) {
if (reportID && !ReportUtils.isArchivedReport(reportNameValuePairs) && report.lastActionType === CONST.REPORT.ACTIONS.TYPE.CLOSED) {
return lastMessageTextFromReport || (ReportUtils.getReportLastMessage(reportID).lastMessageText ?? '');
}
return lastMessageTextFromReport || (report?.lastMessageText ?? '');
Expand Down Expand Up @@ -679,7 +681,7 @@ function createOption(
result.isChatRoom = ReportUtils.isChatRoom(report);
result.isDefaultRoom = ReportUtils.isDefaultRoom(report);
// eslint-disable-next-line @typescript-eslint/naming-convention
result.private_isArchived = report.private_isArchived;
result.private_isArchived = ReportUtils.getReportNameValuePairs(report.reportID)?.private_isArchived;
result.isExpenseReport = ReportUtils.isExpenseReport(report);
result.isInvoiceRoom = ReportUtils.isInvoiceRoom(report);
result.isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
Expand Down
Loading
Loading