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 'ReportUtils.js' lib to TypeScript #29012

Merged
merged 101 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
4187fbb
ref: started migrating ReportUtils to TS
kubabutkiewicz Oct 3, 2023
29e9656
Merge branch 'main' into ts-migration/ReportUtils-lib
kubabutkiewicz Oct 3, 2023
acaa8ea
ref: continue to migrate ReportUtils to Ts
kubabutkiewicz Oct 3, 2023
18ad8ea
Merge branch 'main' into ts-migration/ReportUtils-lib
kubabutkiewicz Oct 4, 2023
73d6d6e
ref: ReportUtils continue of migration
kubabutkiewicz Oct 5, 2023
e9ddcbe
ref: keep migrating ReportUtils
kubabutkiewicz Oct 6, 2023
8eb1c13
Merge branch 'main' into ts-migration/ReportUtils-lib
kubabutkiewicz Oct 10, 2023
dfffe5f
fix: merge conflicts, few adjustments
kubabutkiewicz Oct 10, 2023
4ad36b4
fix: ts fixes for ReportUtils
kubabutkiewicz Oct 12, 2023
9e35d4b
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 18, 2023
a36ff94
fix: ts errors
kubabutkiewicz Oct 19, 2023
ba218c5
fix: fixing type issues
kubabutkiewicz Oct 20, 2023
57b42e8
fix: added some return types
kubabutkiewicz Oct 23, 2023
d52f919
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 23, 2023
5aaf3a3
fix: removed usused argument from canCreateRequest and make some ts f…
kubabutkiewicz Oct 23, 2023
af55c9c
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 23, 2023
0ae6b03
fix: resolved few comments from code review
kubabutkiewicz Oct 24, 2023
84c9ae2
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 24, 2023
e894573
fix: fixed ReportUtilsTest
kubabutkiewicz Oct 24, 2023
4d10611
fix: resolving comments
kubabutkiewicz Oct 25, 2023
962b773
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 25, 2023
7f5c557
fix: resolving comments
kubabutkiewicz Oct 25, 2023
557fbc1
fix: adding return types
kubabutkiewicz Oct 26, 2023
2e416d4
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 26, 2023
27ed0e5
fix: fixed last TS issue
kubabutkiewicz Oct 26, 2023
dae2953
fix: fix ts problems
kubabutkiewicz Oct 26, 2023
1c2fcb7
fix: adjusted type comment
kubabutkiewicz Oct 26, 2023
e3eb38d
fix: fixed issue with not displaying displayName for Reports
kubabutkiewicz Oct 26, 2023
a951d65
fix: remove waitForCollectionCallback from Onyx.connect where its not…
kubabutkiewicz Oct 27, 2023
9ce8236
fix: added return types
kubabutkiewicz Oct 27, 2023
0c1af91
fix: adjusted type guard
kubabutkiewicz Oct 27, 2023
492943a
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 27, 2023
e45f401
fix: adjusted types in SidebarUtils
kubabutkiewicz Oct 30, 2023
45eae6e
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 30, 2023
c68dc77
fix: linter
kubabutkiewicz Oct 30, 2023
19a07f6
fix: linter
kubabutkiewicz Oct 30, 2023
e61b8da
fix: linter
kubabutkiewicz Oct 30, 2023
a953f81
fix: removed unnecessary comment
kubabutkiewicz Oct 30, 2023
8b081b2
fix: resolve comments
kubabutkiewicz Oct 31, 2023
acf1897
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Oct 31, 2023
f0ebbde
fix: liner
kubabutkiewicz Oct 31, 2023
859ce75
fix: resolve comments
kubabutkiewicz Oct 31, 2023
2bc2456
fix: prettier
kubabutkiewicz Oct 31, 2023
d0876ae
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 2, 2023
7d308eb
fix: types issues
kubabutkiewicz Nov 2, 2023
223e3c7
fix: last issues from review
kubabutkiewicz Nov 2, 2023
499fb36
ref: rerun test jobs
kubabutkiewicz Nov 2, 2023
257f692
fix: removed log
kubabutkiewicz Nov 2, 2023
34e1104
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 2, 2023
e86a618
fix: removed commented code
kubabutkiewicz Nov 2, 2023
4789679
fix: fixed comments
kubabutkiewicz Nov 2, 2023
e672ccd
fix: fixed types issues
kubabutkiewicz Nov 2, 2023
523cd3c
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 3, 2023
0635502
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 3, 2023
0dc1e13
fix: unit tests
kubabutkiewicz Nov 3, 2023
374a1ba
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 6, 2023
1de9b9b
fix: resolve comments
kubabutkiewicz Nov 6, 2023
e4df9cb
fix: crash when sending money request
kubabutkiewicz Nov 7, 2023
f00e382
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 7, 2023
611dd1a
fix: resolve comments, fixed type and lint issues
kubabutkiewicz Nov 7, 2023
8c0f621
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 7, 2023
2417779
fix: test and typings
kubabutkiewicz Nov 7, 2023
2869a4b
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 8, 2023
74875cc
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 9, 2023
2f20a46
fix: types
kubabutkiewicz Nov 9, 2023
19adf54
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 9, 2023
c940620
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 13, 2023
dd95a3d
fix: resolved comments
kubabutkiewicz Nov 13, 2023
af54ad4
fix: resolve comments
kubabutkiewicz Nov 13, 2023
23cf6e7
fix: resolve comments
kubabutkiewicz Nov 14, 2023
2213d81
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 14, 2023
340061d
fix: resolve comments
kubabutkiewicz Nov 14, 2023
8b3d147
fix: add ts expect error to file which is using not migrated lib yet
kubabutkiewicz Nov 14, 2023
fc89e18
fix: resolved comment
kubabutkiewicz Nov 14, 2023
9e51ef0
fix: removed unecessary check
kubabutkiewicz Nov 14, 2023
c83e4d0
fix: correct type in Permissions lib
kubabutkiewicz Nov 14, 2023
98c73d2
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 15, 2023
306a871
fix: adjusted types
kubabutkiewicz Nov 15, 2023
aa7a703
fix: resolve type issue
kubabutkiewicz Nov 15, 2023
eba55d1
fix: resolve comments
kubabutkiewicz Nov 15, 2023
5477de8
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 15, 2023
0316877
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 16, 2023
b97854f
fix: types issues
kubabutkiewicz Nov 16, 2023
fc8f676
fix: lint
kubabutkiewicz Nov 16, 2023
db3a608
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 17, 2023
a43fd7f
fix: resolve comment
kubabutkiewicz Nov 17, 2023
3dddf7b
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 20, 2023
03f9485
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 20, 2023
0785921
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 21, 2023
41c2d77
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 22, 2023
e7e8498
fix: type issues
kubabutkiewicz Nov 22, 2023
431111b
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 22, 2023
019f9fe
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 23, 2023
f24294e
fix: avatar and footer problem when archived room
kubabutkiewicz Nov 23, 2023
09a3cb3
fix: problem with displaying report name
kubabutkiewicz Nov 23, 2023
314fa0d
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 23, 2023
48c8598
fix: resolved comment
kubabutkiewicz Nov 23, 2023
12c85ba
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 24, 2023
2701fcd
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 27, 2023
7ff0f22
fix: resolve comments
kubabutkiewicz Nov 27, 2023
aac1519
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Nov 27, 2023
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
6 changes: 3 additions & 3 deletions src/languages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ type DidSplitAmountMessageParams = {formattedAmount: string; comment: string};

type AmountEachParams = {amount: number};

type PayerOwesAmountParams = {payer: string; amount: number};
type PayerOwesAmountParams = {payer: string; amount: number | string};

type PayerOwesParams = {payer: string};

type PayerPaidAmountParams = {payer: string; amount: number};
type PayerPaidAmountParams = {payer: string; amount: number | string};

type ManagerApprovedParams = {manager: string};

type PayerPaidParams = {payer: string};

type PayerSettledParams = {amount: number};
type PayerSettledParams = {amount: number | string};

type WaitingOnBankAccountParams = {submitterDisplayName: string};

Expand Down
3 changes: 2 additions & 1 deletion src/libs/GroupChatUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ Onyx.connect({
/**
* Returns the report name if the report is a group chat
*/
function getGroupChatName(report: Report): string {
function getGroupChatName(report: Report): string | undefined {
const participants = report.participantAccountIDs ?? [];
const isMultipleParticipantReport = participants.length > 1;
const participantPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, allPersonalDetails ?? {});
// @ts-expect-error Error will gone when OptionsListUtils will be migrated to Typescript
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(participantPersonalDetails, isMultipleParticipantReport);
return ReportUtils.getDisplayNamesStringFromTooltips(displayNamesWithTooltips);
}
Expand Down
5 changes: 3 additions & 2 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import {Report, Transaction} from '@src/types/onyx';
import * as CurrencyUtils from './CurrencyUtils';
Expand Down Expand Up @@ -35,8 +36,8 @@ function calculateAmount(numberOfParticipants: number, total: number, currency:
*
* @param isDeleting - whether the user is deleting the request
*/
function updateIOUOwnerAndTotal(iouReport: Report, actorAccountID: number, amount: number, currency: string, isDeleting = false): Report {
if (currency !== iouReport.currency) {
function updateIOUOwnerAndTotal(iouReport: OnyxEntry<Report>, actorAccountID: number, amount: number, currency: string, isDeleting = false): OnyxEntry<Report> {
if (currency !== iouReport?.currency) {
return iouReport;
}

Expand Down
25 changes: 13 additions & 12 deletions src/libs/Permissions.ts
kubabutkiewicz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import {OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import Beta from '@src/types/onyx/Beta';

function canUseAllBetas(betas: Beta[]): boolean {
return betas?.includes(CONST.BETAS.ALL);
function canUseAllBetas(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.ALL);
kubabutkiewicz marked this conversation as resolved.
Show resolved Hide resolved
}

function canUseChronos(betas: Beta[]): boolean {
return betas?.includes(CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas);
function canUseChronos(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.CHRONOS_IN_CASH) || canUseAllBetas(betas);
}

function canUseDefaultRooms(betas: Beta[]): boolean {
return betas?.includes(CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas);
function canUseDefaultRooms(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas);
}

function canUseCommentLinking(betas: Beta[]): boolean {
return betas?.includes(CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas);
function canUseCommentLinking(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas);
}

/**
* We're requiring you to be added to the policy rooms beta on dev,
* since contributors have been reporting a number of false issues related to the feature being under development.
* See https://expensify.slack.com/archives/C01GTK53T8Q/p1641921996319400?thread_ts=1641598356.166900&cid=C01GTK53T8Q
*/
function canUsePolicyRooms(betas: Beta[]): boolean {
return betas?.includes(CONST.BETAS.POLICY_ROOMS) || canUseAllBetas(betas);
function canUsePolicyRooms(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.POLICY_ROOMS) || canUseAllBetas(betas);
}

function canUseViolations(betas: Beta[]): boolean {
return betas?.includes(CONST.BETAS.VIOLATIONS) || canUseAllBetas(betas);
function canUseViolations(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.VIOLATIONS) || canUseAllBetas(betas);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Str from 'expensify-common/lib/str';
import {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {PersonalDetails, Policy, PolicyMembers, PolicyTags} from '@src/types/onyx';
import {PersonalDetails, Policy, PolicyMembers, PolicyTag, PolicyTags} from '@src/types/onyx';
import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';

type MemberEmailsToAccountIDs = Record<string, number>;
type PersonalDetailsList = Record<string, PersonalDetails>;
Expand Down Expand Up @@ -157,8 +158,8 @@ function getIneligibleInvitees(policyMembers: OnyxEntry<PolicyMembers>, personal
/**
* Gets the tag from policy tags, defaults to the first if no key is provided.
*/
function getTag(policyTags: OnyxEntry<PolicyTags>, tagKey?: keyof typeof policyTags) {
if (Object.keys(policyTags ?? {})?.length === 0) {
function getTag(policyTags: OnyxEntry<PolicyTags>, tagKey?: keyof typeof policyTags): PolicyTag | undefined | EmptyObject {
if (isEmptyObject(policyTags)) {
return {};
}

Expand Down
8 changes: 7 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import {ActionName} from '@src/types/onyx/OriginalMessage';
import Report from '@src/types/onyx/Report';
import ReportAction, {ReportActions} from '@src/types/onyx/ReportAction';
import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';
import * as CollectionUtils from './CollectionUtils';
import * as Environment from './Environment/Environment';
import isReportMessageAttachment from './isReportMessageAttachment';
Expand Down Expand Up @@ -72,7 +73,10 @@ function isReversedTransaction(reportAction: OnyxEntry<ReportAction>) {
return (reportAction?.message?.[0]?.isReversedTransaction ?? false) && (reportAction?.childVisibleActionCount ?? 0) > 0;
}

function isPendingRemove(reportAction: OnyxEntry<ReportAction>): boolean {
function isPendingRemove(reportAction: OnyxEntry<ReportAction> | EmptyObject): boolean {
if (isEmptyObject(reportAction)) {
return false;
}
return reportAction?.message?.[0]?.moderationDecision?.decision === CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE;
}

Expand Down Expand Up @@ -695,3 +699,5 @@ export {
getFirstVisibleReportActionID,
isChannelLogMemberAction,
};

export type {LastVisibleMessage};
Loading
Loading