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 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
if (isDisabled) {
return;
}
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs));
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(reportNameValuePairs));

Check failure on line 54 in src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Check failure on line 54 in src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

}}
shouldUseHapticsOnLongPress
accessibilityLabel={displayName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
}

const attachmentLink = tnode.parent?.attributes?.href;
const route = ROUTES.ATTACHMENTS?.getRoute(reportID ?? '-1', type, source, accountID, isAttachmentOrReceipt, fileName, attachmentLink);

Check failure on line 108 in src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Check failure on line 108 in src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Navigation.navigate(route);
}}
onLongPress={(event) => {
Expand All @@ -113,14 +113,7 @@
return;
}
return onShowContextMenu(() =>
showContextMenuForReport(
event,
anchor,
report?.reportID ?? '-1',
action,
checkIfContextMenuActive,
ReportUtils.isArchivedRoom(report, reportNameValuePairs),
),
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(reportNameValuePairs)),

Check failure on line 116 in src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Check failure on line 116 in src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

);
}}
shouldUseHapticsOnLongPress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
return;
}
return onShowContextMenu(() =>
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs)),
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(reportNameValuePairs)),

Check failure on line 95 in src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Check failure on line 95 in src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

);
}}
onPress={(event) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@
if (isDisabled) {
return;
}
return showContextMenuForReport(
event,
anchor,
report?.reportID ?? '-1',
action,
checkIfContextMenuActive,
ReportUtils.isArchivedRoom(report, reportNameValuePairs),
);
return showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(reportNameValuePairs));

Check failure on line 47 in src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Check failure on line 47 in src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

});
}}
shouldUseHapticsOnLongPress
Expand Down
8 changes: 6 additions & 2 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

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

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

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
Expand Up @@ -17,6 +17,7 @@ import type {OptionRowLHNDataProps} from './types';
function OptionRowLHNData({
isFocused = false,
fullReport,
reportNameValuePairs,
reportActions,
personalDetails = {},
preferredLocale = CONST.LOCALES.DEFAULT,
Expand Down Expand Up @@ -45,6 +46,7 @@ function OptionRowLHNData({
// 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 @@ function OptionRowLHNData({
// 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
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
2 changes: 1 addition & 1 deletion src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) {
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || -1}`);
const isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs);
const isArchivedRoom = ReportUtils.isArchivedRoom(reportNameValuePairs);
const isChatRoom = ReportUtils.isChatRoom(report);
const isSelfDM = ReportUtils.isSelfDM(report);
const isInvoiceRoom = ReportUtils.isInvoiceRoom(report);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,7 @@ function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel, isDele
return;
}
onShowContextMenu(() => {
showContextMenuForReport(
event,
anchor,
report?.reportID ?? '-1',
action,
checkIfContextMenuActive,
ReportUtils.isArchivedRoom(report, reportNameValuePairs),
);
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(reportNameValuePairs));
});
}}
shouldUseHapticsOnLongPress
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 @@ -565,7 +565,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
6 changes: 4 additions & 2 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 = lastReportActions[reportID] ?? null;
let lastMessageTextFromReport = '';

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

if (reportNameValuePairs?.private_isArchived) {
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 @@ -669,7 +671,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