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

[No QA][TS Migration] Add comments for remaining properties in Onyx types #41956

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5b9433c
docs: add onyx types descriptions
pac-guerreiro May 9, 2024
4dac52f
docs: add missing onyx types descriptions
pac-guerreiro May 13, 2024
ee11f2e
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro May 13, 2024
8631fa8
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro May 15, 2024
13029ae
docs: add missing type descriptions
pac-guerreiro May 15, 2024
3494545
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro May 20, 2024
96f6955
docs: apply pull request suggestions
pac-guerreiro May 20, 2024
65022fb
refactor: apply pull request suggestions
pac-guerreiro May 22, 2024
f3e1c8f
refactor: apply pull request suggestions
pac-guerreiro May 22, 2024
530d6d6
refactor: remove unused property from wallet additional details
pac-guerreiro May 22, 2024
9a50d43
docs: add missing type description
pac-guerreiro May 22, 2024
611266d
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro May 24, 2024
a4d4102
chore: resolve pending descriptions
pac-guerreiro May 24, 2024
8025926
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro May 27, 2024
5599455
docs: apply suggestions
pac-guerreiro May 27, 2024
2d91475
docs: apply suggestions
pac-guerreiro May 27, 2024
da515a8
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro May 31, 2024
530b1ce
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro Jun 1, 2024
68ce115
refactor: apply pull request suggestions
pac-guerreiro Jun 1, 2024
279e50a
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro Jun 5, 2024
9fe6712
chore: apply pull request suggestions and address types with missing …
pac-guerreiro Jun 5, 2024
c46d709
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro Jun 5, 2024
6dabcc0
chore: enable eslint rule that requires comments on onyx types and th…
pac-guerreiro Jun 6, 2024
11090bd
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
pac-guerreiro Jun 7, 2024
453343e
refactor: apply pull request suggestions
pac-guerreiro Jun 7, 2024
98fa483
Merge branch 'main' into pac-guerreiro/refactor/39129-add-comments-to…
fabioh8010 Jun 7, 2024
a354239
Fix lint errors and improve comments
fabioh8010 Jun 7, 2024
199e228
Merge remote-tracking branch 'origin/main' into pac-guerreiro/refacto…
fabioh8010 Jun 7, 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
15 changes: 14 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,21 @@ module.exports = {
],
},

// Remove once no JS files are left
overrides: [
// Enforces every Onyx type and its properties to have a comment explaining its purpose.
{
files: ['src/types/onyx/**/*.ts'],
rules: {
'jsdoc/require-jsdoc': [
'error',
{
contexts: ['TSInterfaceDeclaration', 'TSTypeAliasDeclaration', 'TSPropertySignature'],
},
],
},
},

// Remove once no JS files are left
{
files: ['*.js', '*.jsx'],
rules: {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyTagList, ReportAction} from '@src/types/onyx';
import type {ModifiedExpense} from '@src/types/onyx/OriginalMessage';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import getReportPolicyID from './getReportPolicyID';
import * as Localize from './Localize';
import * as PolicyUtils from './PolicyUtils';
import type {ExpenseOriginalMessage} from './ReportUtils';
import * as TransactionUtils from './TransactionUtils';

let allPolicyTags: OnyxCollection<PolicyTagList> = {};
Expand Down Expand Up @@ -109,7 +109,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE) {
return '';
}
const reportActionOriginalMessage = reportAction?.originalMessage as ExpenseOriginalMessage | undefined;
const reportActionOriginalMessage = reportAction?.originalMessage as ModifiedExpense | undefined;
const policyID = getReportPolicyID(reportID) ?? '';

const removalFragments: string[] = [];
Expand Down
5 changes: 4 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
ActionName,
ChangeLog,
IOUMessage,
JoinWorkspaceResolution,
OriginalMessageActionableMentionWhisper,
OriginalMessageActionableReportMentionWhisper,
OriginalMessageActionableTrackedExpenseWhisper,
Expand Down Expand Up @@ -1205,7 +1206,9 @@ function isActionableJoinRequest(reportAction: OnyxEntry<ReportAction>): reportA
*/
function isActionableJoinRequestPending(reportID: string): boolean {
const sortedReportActions = getSortedReportActions(Object.values(getAllReportActions(reportID)));
const findPendingRequest = sortedReportActions.find((reportActionItem) => isActionableJoinRequest(reportActionItem) && reportActionItem.originalMessage.choice === '');
const findPendingRequest = sortedReportActions.find(
(reportActionItem) => isActionableJoinRequest(reportActionItem) && reportActionItem.originalMessage.choice === ('' as JoinWorkspaceResolution),
);
return !!findPendingRequest;
}

Expand Down
39 changes: 8 additions & 31 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import type {
ChangeLog,
IOUMessage,
ModifiedExpense,
OriginalMessageActionName,
OriginalMessageApproved,
OriginalMessageCreated,
OriginalMessageDismissedViolation,
OriginalMessageReimbursementDequeued,
OriginalMessageRenamed,
OriginalMessageSubmitted,
PaymentMethodType,
ReimbursementDeQueuedMessage,
} from '@src/types/onyx/OriginalMessage';
import type {Status} from '@src/types/onyx/PersonalDetails';
import type {NotificationPreference, Participants, PendingChatMember, Participant as ReportParticipant} from '@src/types/onyx/Report';
Expand Down Expand Up @@ -87,30 +89,6 @@ type AvatarRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string};

type ExpenseOriginalMessage = {
oldComment?: string;
newComment?: string;
comment?: string;
merchant?: string;
oldCreated?: string;
created?: string;
oldMerchant?: string;
oldAmount?: number;
amount?: number;
oldCurrency?: string;
currency?: string;
category?: string;
oldCategory?: string;
tag?: string;
oldTag?: string;
billable?: string;
oldBillable?: string;
oldTaxAmount?: number;
taxAmount?: number;
taxRate?: string;
oldTaxRate?: string;
};

type SpendBreakdown = {
nonReimbursableSpend: number;
reimbursableSpend: number;
Expand Down Expand Up @@ -211,12 +189,12 @@ type ReportOfflinePendingActionAndErrors = {
};

type OptimisticApprovedReportAction = Pick<
ReportAction,
ReportAction & OriginalMessageApproved,
'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction'
>;

type OptimisticSubmittedReportAction = Pick<
ReportAction,
ReportAction & OriginalMessageSubmitted,
| 'actionName'
| 'actorAccountID'
| 'adminAccountID'
Expand Down Expand Up @@ -2208,7 +2186,7 @@ function getReimbursementDeQueuedActionMessage(
report: OnyxEntry<Report> | EmptyObject,
isLHNPreview = false,
): string {
const originalMessage = reportAction?.originalMessage as ReimbursementDeQueuedMessage | undefined;
const originalMessage = reportAction?.originalMessage;
const amount = originalMessage?.amount;
const currency = originalMessage?.currency;
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency);
Expand Down Expand Up @@ -3024,8 +3002,8 @@ function getModifiedExpenseOriginalMessage(
transactionChanges: TransactionChanges,
isFromExpenseReport: boolean,
policy: OnyxEntry<Policy>,
): ExpenseOriginalMessage {
const originalMessage: ExpenseOriginalMessage = {};
): ModifiedExpense {
const originalMessage: ModifiedExpense = {};
// Remark: Comment field is the only one which has new/old prefixes for the keys (newComment/ oldComment),
// all others have old/- pattern such as oldCreated/created
if ('comment' in transactionChanges) {
Expand Down Expand Up @@ -7151,7 +7129,6 @@ export {
export type {
Ancestor,
DisplayNameWithTooltips,
ExpenseOriginalMessage,
OptimisticAddCommentReportAction,
OptimisticChatReport,
OptimisticClosedReportAction,
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {ActivatePhysicalExpensifyCardParams, ReportVirtualExpensifyCardFrau
import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Response} from '@src/types/onyx';
import type {ExpensifyCardDetails} from '@src/types/onyx/Card';

type ReplacementReason = 'damaged' | 'stolen';

Expand Down Expand Up @@ -158,7 +158,7 @@ function clearCardListErrors(cardID: number) {
*
* @returns promise with card details object
*/
function revealVirtualCardDetails(cardID: number): Promise<Response> {
function revealVirtualCardDetails(cardID: number): Promise<ExpensifyCardDetails> {
return new Promise((resolve, reject) => {
const parameters: RevealExpensifyCardDetailsParams = {cardID};

Expand All @@ -170,7 +170,7 @@ function revealVirtualCardDetails(cardID: number): Promise<Response> {
reject('cardPage.cardDetailsLoadingFailure');
return;
}
resolve(response);
resolve(response as ExpensifyCardDetails);
})
// eslint-disable-next-line prefer-promise-reject-errors
.catch(() => reject('cardPage.cardDetailsLoadingFailure'));
Expand Down
5 changes: 0 additions & 5 deletions src/libs/actions/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ function setAdditionalDetailsErrors(errorFields: OnyxCommon.ErrorFields) {
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {errorFields});
}

function setAdditionalDetailsErrorMessage(additionalErrorMessage: string) {
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {additionalErrorMessage});
}

/**
* Save the source that triggered the KYC wall and optionally the chat report ID associated with the IOU
*/
Expand Down Expand Up @@ -304,7 +300,6 @@ export {
openInitialSettingsPage,
openEnablePaymentsPage,
setAdditionalDetailsErrors,
setAdditionalDetailsErrorMessage,
setAdditionalDetailsQuestions,
updateCurrentStep,
answerQuestionsForWallet,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/models/BankAccount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Str} from 'expensify-common';
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import type {AdditionalData} from '@src/types/onyx/BankAccount';
import type {BankAccountAdditionalData} from '@src/types/onyx/BankAccount';
import type BankAccountJSON from '@src/types/onyx/BankAccount';

type State = ValueOf<typeof BankAccount.STATE>;
Expand Down Expand Up @@ -194,7 +194,7 @@ class BankAccount {
/**
* Get the additional data of a bankAccount
*/
getAdditionalData(): Partial<AdditionalData> {
getAdditionalData(): Partial<BankAccountAdditionalData> {
return this.json.accountData?.additionalData ?? {};
}

Expand Down
1 change: 1 addition & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type ReportScreenOnyxProps = {
/** An array containing all report actions related to this report, sorted based on a date criterion */
sortedAllReportActions: OnyxTypes.ReportAction[];

/** Additional report details */
reportNameValuePairs: OnyxEntry<OnyxTypes.ReportNameValuePairs>;

/** The report metadata loading states */
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';
import {RestrictedReadOnlyContextMenuActions} from './ContextMenu/ContextMenuActions';
Expand Down Expand Up @@ -398,7 +399,7 @@ function ReportActionItem({
const attachmentContextValue = useMemo(() => ({reportID: report.reportID, type: CONST.ATTACHMENT_TYPE.REPORT}), [report.reportID]);

const actionableItemButtons: ActionableItem[] = useMemo(() => {
if (!isActionableWhisper && (!ReportActionsUtils.isActionableJoinRequest(action) || action.originalMessage.choice !== '')) {
if (!isActionableWhisper && (!ReportActionsUtils.isActionableJoinRequest(action) || action.originalMessage.choice !== ('' as JoinWorkspaceResolution))) {
return [];
}

Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/report/ReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ type ReportFooterProps = ReportFooterOnyxProps & {
/** Report object for the current report */
report?: OnyxTypes.Report;

/** Report metadata */
reportMetadata?: OnyxEntry<OnyxTypes.ReportMetadata>;

/** Additional report details */
reportNameValuePairs?: OnyxEntry<OnyxTypes.ReportNameValuePairs>;

/** The policy of the report */
Expand Down
6 changes: 3 additions & 3 deletions src/pages/settings/Wallet/ExpensifyCardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {GetPhysicalCardForm} from '@src/types/form';
import type {LoginList, Card as OnyxCard, PrivatePersonalDetails} from '@src/types/onyx';
import type {TCardDetails} from '@src/types/onyx/Card';
import type {ExpensifyCardDetails} from '@src/types/onyx/Card';
import RedDotCardSection from './RedDotCardSection';
import CardDetails from './WalletPage/CardDetails';

Expand Down Expand Up @@ -101,7 +101,7 @@ function ExpensifyCardPage({

const virtualCards = useMemo(() => cardsToShow?.filter((card) => card?.nameValuePairs?.isVirtual), [cardsToShow]);
const physicalCards = useMemo(() => cardsToShow?.filter((card) => !card?.nameValuePairs?.isVirtual), [cardsToShow]);
const [cardsDetails, setCardsDetails] = useState<Record<number, TCardDetails | null>>({});
const [cardsDetails, setCardsDetails] = useState<Record<number, ExpensifyCardDetails | null>>({});
const [isCardDetailsLoading, setIsCardDetailsLoading] = useState<Record<number, boolean>>({});
const [cardsDetailsErrors, setCardsDetailsErrors] = useState<Record<number, string>>({});

Expand All @@ -116,7 +116,7 @@ function ExpensifyCardPage({
// eslint-disable-next-line rulesdir/no-thenable-actions-in-views
Card.revealVirtualCardDetails(revealedCardID)
.then((value) => {
setCardsDetails((prevState: Record<number, TCardDetails | null>) => ({...prevState, [revealedCardID]: value as TCardDetails}));
setCardsDetails((prevState: Record<number, ExpensifyCardDetails | null>) => ({...prevState, [revealedCardID]: value}));
setCardsDetailsErrors((prevState) => ({
...prevState,
[revealedCardID]: '',
Expand Down
11 changes: 11 additions & 0 deletions src/types/onyx/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import type DismissedReferralBanners from './DismissedReferralBanners';
import type * as OnyxCommon from './OnyxCommon';
import type {TravelSettings} from './TravelSettings';

/** Two factor authentication steps */
type TwoFactorAuthStep = ValueOf<typeof CONST.TWO_FACTOR_AUTH_STEPS> | '';

/** Model of user account */
type Account = {
/** Whether SAML is enabled for the current account */
isSAMLEnabled?: boolean;
Expand Down Expand Up @@ -55,10 +57,19 @@ type Account = {
/** Whether a sign is loading */
isLoading?: boolean;

/** Authentication failure errors */
errors?: OnyxCommon.Errors | null;

/** Authentication success message */
success?: string;

/** Whether the two factor authentication codes were copied */
codesAreCopied?: boolean;

/** Current two factor authentication step */
twoFactorAuthStep?: TwoFactorAuthStep;

/** Referral banners that the user dismissed */
dismissedReferralBanners?: DismissedReferralBanners;

/** Object containing all account information necessary to connect with Spontana */
Expand Down
16 changes: 5 additions & 11 deletions src/types/onyx/AccountData.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import type {BankName} from './Bank';
import type {BankAccountAdditionalData} from './BankAccount';
import type * as OnyxCommon from './OnyxCommon';

type AdditionalData = {
isP2PDebitCard?: boolean;
beneficialOwners?: string[];
currency?: string;
bankName?: BankName;
fieldsType?: string;
country?: string;
};

/** Model of bank account data */
type AccountData = {
/** The masked bank account number */
accountNumber?: string;
Expand Down Expand Up @@ -38,20 +30,22 @@ type AccountData = {
/** All user emails that have access to this bank account */
sharees?: string[];

/** Institution that processes the account payments */
processor?: string;

/** The bankAccountID in the bankAccounts db */
bankAccountID?: number;

/** All data related to the bank account */
additionalData?: AdditionalData;
additionalData?: BankAccountAdditionalData;

/** The bank account type */
type?: string;

/** Any error message to show */
errors?: OnyxCommon.Errors;

/** The debit card ID */
fundID?: number;
};

Expand Down
13 changes: 13 additions & 0 deletions src/types/onyx/Bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type IconAsset from '@src/types/utils/IconAsset';

/** Bank icon configurations */
type BankIcon = {
/** Source of the icon, can be a component or an image */
icon: IconAsset;

/** Size of the icon */
iconSize?: number;

/** Height of the icon */
iconHeight?: number;

/** Width of the icon */
iconWidth?: number;

/** Icon wrapper styles */
iconStyles?: ViewStyle[];
};

/** Bank names */
type BankName = ValueOf<typeof CONST.BANK_NAMES>;

/** Bank name keys */
type BankNameKey = keyof typeof CONST.BANK_NAMES;

export type {BankIcon, BankName, BankNameKey};
Loading
Loading