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 10 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 @@ -43,7 +43,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 @@ -86,8 +86,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 ?? policy.isHarvestingEnabled),
[chatReport?.isOwnPolicyExpenseChat, policy.harvesting?.enabled, policy.isHarvestingEnabled],
() => chatReport?.isOwnPolicyExpenseChat && !(policy?.harvesting?.enabled ?? policy?.isHarvestingEnabled),
[chatReport?.isOwnPolicyExpenseChat, policy?.harvesting?.enabled, policy?.isHarvestingEnabled],
);

const threeDotsMenuItems = [HeaderUtils.getPinMenuItem(moneyRequestReport)];
Expand Down
4 changes: 2 additions & 2 deletions src/components/ScreenWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useNetwork from '@hooks/useNetwork';
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 @@ -85,7 +85,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
9 changes: 7 additions & 2 deletions src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type {OnyxKeyValue} from '@src/ONYXKEYS';
import type {OnyxEntry} from 'react-native-onyx';
import type {Report} from '@src/types/onyx';

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

export default function reportWithoutHasDraftSelector(report: OnyxEntry<Report>): OnyxEntry<ReportWithoutHasDraft> {
if (!report) {
return report;
}
const {hasDraft, ...reportWithoutHasDraft} = report;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -113,7 +113,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 @@ -171,7 +171,7 @@ function isSentMoneyReportAction(reportAction: OnyxEntry<ReportAction>): boolean
* 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
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,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 @@ -4194,7 +4194,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 Expand Up @@ -4572,7 +4572,7 @@ function getRoom(type: ValueOf<typeof CONST.REPORT.CHAT_TYPE>, policyID: string)
/**
* We only want policy members who are members of the report to be able to modify the report description, but not in thread chat.
*/
function canEditReportDescription(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> | undefined): boolean {
function canEditReportDescription(report: OnyxEntry<Report>, policy: OnyxEntry<Partial<Policy>> | undefined): boolean {
return (
!isMoneyRequestReport(report) &&
!isArchivedRoom(report) &&
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 @@ -139,7 +139,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 @@ -83,7 +83,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