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

[TS migration] Migrate 'Report' page to TypeScript #35566

Merged
merged 40 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1e2a42d
Migrate FloatingMessageCounter to TypeScript
VickyStash Feb 1, 2024
67774bf
Migrate ReportActionsListItemRenderer and ListBoundaryLoader to TypeS…
VickyStash Feb 1, 2024
0fc1dec
Migrate ReportFooter to TypeScript
VickyStash Feb 1, 2024
eac5523
Migrate ReportActionsList to TypeScript
VickyStash Feb 1, 2024
5e7f24d
Migrate ReportActionsView to TypeScript
VickyStash Feb 2, 2024
a2eba34
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 5, 2024
600aaec
Migrate HeaderView to TypeScript
VickyStash Feb 5, 2024
005e09c
Migrate ReportScreen to TypeScript
VickyStash Feb 6, 2024
12217b7
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 6, 2024
5ebe244
TS updates for the new code
VickyStash Feb 6, 2024
1a38cfd
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 7, 2024
d3fdc72
Use || instead of ?? to prevent regression
VickyStash Feb 7, 2024
174895b
Create pick utils function
VickyStash Feb 7, 2024
1931d0b
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 8, 2024
42c06ba
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 9, 2024
ba7c5fe
TS migration for updated code parts
VickyStash Feb 9, 2024
628a050
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 9, 2024
007400f
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 20, 2024
03695f6
Fix TS issues in the updated code
VickyStash Feb 20, 2024
bc444cf
Minor type improvement
VickyStash Feb 20, 2024
fe6e43f
Update condition, type improvement
VickyStash Feb 20, 2024
443bf0e
Fix perf test
VickyStash Feb 20, 2024
64e4c52
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 22, 2024
398858e
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 23, 2024
4b7c614
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 27, 2024
08629df
Minor code improvement
VickyStash Feb 27, 2024
6356f29
Merge branch 'main' into ts-migration/report-page
VickyStash Feb 29, 2024
723d90d
Fix TS errors in the updated code
VickyStash Feb 29, 2024
12e4023
Merge branch 'main' into ts-migration/report-page
VickyStash Mar 1, 2024
5f0d94f
Merge branch 'main' into ts-migration/report-page
VickyStash Mar 4, 2024
5098f5b
Update new parts of the code
VickyStash Mar 4, 2024
cb2a33d
Merge branch 'main' into ts-migration/report-page
VickyStash Mar 5, 2024
510862b
Merge branch 'main' into ts-migration/report-page
VickyStash Mar 5, 2024
da62731
Fix TS issues in the new parts of the code
VickyStash Mar 6, 2024
e06a768
Minor code improvement
VickyStash Mar 6, 2024
de370da
Merge branch 'main' into ts-migration/report-page
VickyStash Mar 7, 2024
287d736
Merge branch 'main' into ts-migration/report-page
VickyStash Mar 8, 2024
8e0eba8
Remove outdated TODOs
VickyStash Mar 8, 2024
0fe29f1
Merge branch 'main' into ts-migration/report-page
VickyStash Mar 11, 2024
ecb3f58
TS updates for the new code
VickyStash Mar 11, 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
2 changes: 1 addition & 1 deletion src/components/DragAndDrop/Provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type DragAndDropProviderProps = {
isDisabled?: boolean;

/** Indicate that users are dragging file or not */
setIsDraggingOver: (value: boolean) => void;
setIsDraggingOver?: (value: boolean) => void;
};

type SetOnDropHandlerCallback = (event: DragEvent) => void;
Expand Down
6 changes: 3 additions & 3 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type MoneyReportHeaderProps = MoneyReportHeaderOnyxProps & {
report: OnyxTypes.Report;

/** The policy tied to the money request report */
policy: OnyxTypes.Policy;
policy: OnyxEntry<OnyxTypes.Policy>;
};

function MoneyReportHeader({session, policy, chatReport, nextStep, report: moneyRequestReport}: MoneyReportHeaderProps) {
Expand Down Expand Up @@ -100,8 +100,8 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money

// The submit button should be success green colour only if the user is submitter and the policy does not have Scheduled Submit turned on
const isWaitingForSubmissionFromCurrentUser = useMemo(
() => chatReport?.isOwnPolicyExpenseChat && !policy.harvesting?.enabled,
[chatReport?.isOwnPolicyExpenseChat, policy.harvesting?.enabled],
() => chatReport?.isOwnPolicyExpenseChat && !policy?.harvesting?.enabled,
[chatReport?.isOwnPolicyExpenseChat, policy?.harvesting?.enabled],
);

const threeDotsMenuItems = [HeaderUtils.getPinMenuItem(moneyRequestReport)];
Expand Down
16 changes: 11 additions & 5 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ type MoneyRequestHeaderProps = MoneyRequestHeaderOnyxProps & {
report: Report;

/** The policy which the report is tied to */
policy: Policy;
policy: OnyxEntry<Policy>;

/** The report action the transaction is tied to from the parent report */
parentReportAction: ReportAction & OriginalMessageIOU;
parentReportAction: OnyxEntry<ReportAction>;
};

function MoneyRequestHeader({session, parentReport, report, parentReportAction, transaction, shownHoldUseExplanation = false, policy}: MoneyRequestHeaderProps) {
Expand All @@ -72,7 +72,11 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && (session?.accountID ?? null) === moneyRequestReport?.managerID;

const deleteTransaction = useCallback(() => {
IOU.deleteMoneyRequest(parentReportAction?.originalMessage?.IOUTransactionID ?? '', parentReportAction, true);
if (parentReportAction) {
const iouTransactionID = parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '' : '';
IOU.deleteMoneyRequest(iouTransactionID, parentReportAction, true);
}

setIsDeleteModalVisible(false);
}, [parentReportAction, setIsDeleteModalVisible]);

Expand All @@ -91,11 +95,13 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
}

const changeMoneyRequestStatus = () => {
const iouTransactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '' : '';

if (isOnHold) {
IOU.unholdRequest(parentReportAction?.originalMessage?.IOUTransactionID ?? '', report?.reportID);
IOU.unholdRequest(iouTransactionID, report?.reportID);
} else {
const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams());
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type, parentReportAction?.originalMessage?.IOUTransactionID ?? '', report?.reportID, activeRoute));
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? '', iouTransactionID, report?.reportID, activeRoute));
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/ScreenWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import useTackInputFocus from '@hooks/useTackInputFocus';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import type {RootStackParamList} from '@libs/Navigation/types';
import type {CentralPaneNavigatorParamList, RootStackParamList} from '@libs/Navigation/types';
import toggleTestToolsModal from '@userActions/TestTool';
import CONST from '@src/CONST';
import CustomDevMenu from './CustomDevMenu';
Expand Down Expand Up @@ -92,7 +92,7 @@ type ScreenWrapperProps = {
*
* This is required because transitionEnd event doesn't trigger in the testing environment.
*/
navigation?: StackNavigationProp<RootStackParamList>;
navigation?: StackNavigationProp<RootStackParamList> | StackNavigationProp<CentralPaneNavigatorParamList>;
puneetlath marked this conversation as resolved.
Show resolved Hide resolved

/** Whether to show offline indicator on wide screens */
shouldShowOfflineIndicatorInWideScreen?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/components/withViewportOffsetTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ export default function withViewportOffsetTop<TProps extends ViewportOffsetTopPr

return forwardRef(WithViewportOffsetTop);
}

export type {ViewportOffsetTopProps};
1 change: 0 additions & 1 deletion src/libs/Navigation/AppNavigator/ReportScreenWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function ReportScreenWrapper({route, navigation}: ReportScreenWrapperProps) {
return (
<>
<ReportScreen
// @ts-expect-error Error will be resolved after ReportScreen migration to TypeScript
route={route}
navigation={navigation}
/>
Expand Down
11 changes: 8 additions & 3 deletions src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type {OnyxValue} from '@src/ONYXKEYS';
import type {OnyxEntry} from 'react-native-onyx';
import type {Report} from '@src/types/onyx';

export default function reportWithoutHasDraftSelector(report: OnyxValue<'report_'>) {
type ReportWithoutHasDraft = Omit<Report, 'hasDraft'>;

export default function reportWithoutHasDraftSelector(report: OnyxEntry<Report>): OnyxEntry<ReportWithoutHasDraft> {
if (!report) {
return report;
return null;
}
const {hasDraft, ...reportWithoutHasDraft} = report;
return reportWithoutHasDraft;
}

export type {ReportWithoutHasDraft};
4 changes: 2 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function isModifiedExpenseAction(reportAction: OnyxEntry<ReportAction>): boolean
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE;
}

function isWhisperAction(reportAction: OnyxEntry<ReportAction>): boolean {
function isWhisperAction(reportAction: OnyxEntry<ReportAction> | EmptyObject): boolean {
return (reportAction?.whisperedToAccountIDs ?? []).length > 0;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ function isSentMoneyReportAction(reportAction: OnyxEntry<ReportAction | Optimist
* Returns whether the thread is a transaction thread, which is any thread with IOU parent
* report action from requesting money (type - create) or from sending money (type - pay with IOUDetails field)
*/
function isTransactionThread(parentReportAction: OnyxEntry<ReportAction>): boolean {
function isTransactionThread(parentReportAction: OnyxEntry<ReportAction> | EmptyObject): boolean {
return (
parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
(parentReportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ function isMoneyRequest(reportOrID: OnyxEntry<Report> | string): boolean {
/**
* Checks if a report is an IOU or expense report.
*/
function isMoneyRequestReport(reportOrID: OnyxEntry<Report> | string): boolean {
function isMoneyRequestReport(reportOrID: OnyxEntry<Report> | EmptyObject | string): boolean {
const report = typeof reportOrID === 'object' ? reportOrID : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null;
return isIOUReport(report) || isExpenseReport(report);
}
Expand Down Expand Up @@ -2714,8 +2714,8 @@ function getReportDescriptionText(report: Report): string {
return parser.htmlToText(report.description);
}

function getPolicyDescriptionText(policy: Policy): string {
if (!policy.description) {
function getPolicyDescriptionText(policy: OnyxEntry<Policy>): string {
if (!policy?.description) {
return '';
}

Expand Down Expand Up @@ -4476,7 +4476,7 @@ function getAddWorkspaceRoomOrChatReportErrors(report: OnyxEntry<Report>): Error
/**
* Return true if the Money Request report is marked for deletion.
*/
function isMoneyRequestReportPendingDeletion(report: OnyxEntry<Report>): boolean {
function isMoneyRequestReportPendingDeletion(report: OnyxEntry<Report> | EmptyObject): boolean {
if (!isMoneyRequestReport(report)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function signOutAndRedirectToSignIn(shouldReplaceCurrentScreen?: boolean) {
* @returns same callback if the action is allowed, otherwise a function that signs out and redirects to sign in
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function checkIfActionIsAllowed<TCallback extends (...args: any[]) => any>(callback: TCallback, isAnonymousAction = false): TCallback | (() => void) {
function checkIfActionIsAllowed<TCallback extends ((...args: any[]) => any) | void>(callback: TCallback, isAnonymousAction = false): TCallback | (() => void) {
if (isAnonymousUser() && !isAnonymousAction) {
return () => signOutAndRedirectToSignIn();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function createTaskAndNavigate(
assigneeEmail: string,
assigneeAccountID = 0,
assigneeChatReport: OnyxEntry<OnyxTypes.Report> = null,
policyID = CONST.POLICY.OWNER_EMAIL_FAKE,
policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE,
) {
const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserAccountID, assigneeAccountID, parentReportID, title, description, policyID);

Expand Down
Loading
Loading