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] Standardize approach to Onyx pendingFields #34799

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3d3aeaa
Create OfflineFeedback type
VickyStash Jan 19, 2024
3a42ec7
Use OfflineFeedback type instead of pendingAction
VickyStash Jan 19, 2024
4a1c14e
Fix lint errors
VickyStash Jan 19, 2024
284d119
Fix lint error in SidebarUtils
VickyStash Jan 19, 2024
3bce79c
Update PendingFields type and add OnyxItemWithOfflineFeedback type
VickyStash Jan 22, 2024
4aaad12
Use OfflineFeedback where possible
VickyStash Jan 23, 2024
abed5f1
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Jan 23, 2024
25552df
Update PolicyReportField import
VickyStash Jan 23, 2024
60fe816
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Jan 25, 2024
809707a
Update OnyxValueWithOfflineFeedback type and reuse it
VickyStash Jan 25, 2024
8682a4d
Remove extra export
VickyStash Jan 25, 2024
66808bf
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Jan 26, 2024
aa6e0e3
Lint fix after conflicts resolution
VickyStash Jan 26, 2024
c028794
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Jan 29, 2024
648e293
Lint fix
VickyStash Jan 29, 2024
a8e53ff
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Jan 30, 2024
5886dcb
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Jan 31, 2024
97bba27
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Feb 1, 2024
98925a5
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Feb 6, 2024
187ffd9
TS fixes after merging main
VickyStash Feb 6, 2024
d559b2e
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Feb 9, 2024
4578ca8
TS fix
VickyStash Feb 9, 2024
f0bb6ed
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Feb 20, 2024
3b5834f
Minor code improvement
VickyStash Feb 21, 2024
939a88c
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Feb 22, 2024
fc6c412
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Feb 23, 2024
8163d2c
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Feb 26, 2024
7d5e4e8
Fix TS error
VickyStash Feb 26, 2024
f52baac
Merge branch 'main' into ts-migration/standardize-pendingFields
VickyStash Feb 26, 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/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function getOptionData({
result.isExpenseRequest = ReportUtils.isExpenseRequest(report);
result.isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
result.shouldShowSubscript = ReportUtils.shouldReportShowSubscript(report);
result.pendingAction = report.pendingFields ? report.pendingFields.addWorkspaceRoom || report.pendingFields.createChat : undefined;
result.pendingAction = report.pendingFields ? report.pendingFields.addWorkspaceRoom ?? report.pendingFields.createChat : undefined;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
result.allReportErrors = OptionsListUtils.getAllReportErrors(report, reportActions) as OnyxCommon.Errors;
result.brickRoadIndicator = hasErrors || hasViolations ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
result.ownerAccountID = report.ownerAccountID;
Expand Down
5 changes: 1 addition & 4 deletions src/types/onyx/BankAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type AdditionalData = {
country?: string;
};

type BankAccount = {
type BankAccount = OnyxCommon.OfflineFeedback & {
/** The bank account type */
accountType?: typeof CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT;

Expand Down Expand Up @@ -40,9 +40,6 @@ type BankAccount = {

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

/** Indicates the type of change made to the bank account that hasn't been synced with the server yet */
pendingAction?: OnyxCommon.PendingAction;
};

type BankAccountList = Record<string, BankAccount>;
Expand Down
3 changes: 1 addition & 2 deletions src/types/onyx/Fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type AccountData = {
bank?: BankName;
};

type Fund = {
type Fund = OnyxCommon.OfflineFeedback & {
accountData?: AccountData;
accountType?: typeof CONST.PAYMENT_METHODS.DEBIT_CARD;
description?: string;
Expand All @@ -34,7 +34,6 @@ type Fund = {
title?: string;
isDefault?: boolean;
errors?: OnyxCommon.Errors;
pendingAction?: OnyxCommon.PendingAction;
};

type FundList = Record<string, Fund>;
Expand Down
9 changes: 4 additions & 5 deletions src/types/onyx/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ type Login = {

/** Field-specific server side errors keyed by microtime */
errorFields?: OnyxCommon.ErrorFields;

/** Field-specific pending states for offline UI status */
pendingFields?: OnyxCommon.PendingFields;
};

type LoginList = Record<string, Login>;
type LoginWithOfflineFeedback = OnyxCommon.OnyxItemWithOfflineFeedback<Login, keyof Login | 'defaultLogin' | 'validateLogin' | 'addedLogin' | 'deletedLogin'>;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved

type LoginList = Record<string, LoginWithOfflineFeedback>;

export default Login;
export default LoginWithOfflineFeedback;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
export type {LoginList};
16 changes: 13 additions & 3 deletions src/types/onyx/OnyxCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ import type {ValueOf} from 'type-fest';
import type {AvatarSource} from '@libs/UserUtils';
import type CONST from '@src/CONST';

type PendingAction = ValueOf<typeof CONST.RED_BRICK_ROAD_PENDING_ACTION>;
type PendingAction = ValueOf<typeof CONST.RED_BRICK_ROAD_PENDING_ACTION> | null;

type PendingFields<TKey extends string = string> = Record<TKey, PendingAction | null | undefined>;
type PendingFields<TKey extends string> = {[key in Exclude<TKey, 'pendingAction' | 'pendingFields'>]?: PendingAction};

type OfflineFeedback<TKey extends string = string> = {
/** The type of action that's pending */
pendingAction?: PendingAction;

/** Field-specific pending states for offline updates */
pendingFields?: PendingFields<TKey>;
};

type OnyxItemWithOfflineFeedback<TOnyx, TKey extends string = string> = TOnyx & OfflineFeedback<TKey>;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved

type ErrorFields<TKey extends string = string> = Record<TKey, Errors | null | undefined>;

Expand All @@ -29,4 +39,4 @@ type Icon = {
fallbackIcon?: AvatarSource;
};

export type {Icon, PendingAction, PendingFields, ErrorFields, Errors, AvatarType};
export type {Icon, PendingAction, ErrorFields, Errors, AvatarType, OfflineFeedback, OnyxItemWithOfflineFeedback};
9 changes: 4 additions & 5 deletions src/types/onyx/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,17 @@ type PersonalDetails = {
/** Field-specific server side errors keyed by microtime */
errorFields?: OnyxCommon.ErrorFields<'avatar'>;

/** Field-specific pending states for offline UI status */
pendingFields?: OnyxCommon.PendingFields<'avatar' | 'originalFileName'>;

/** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */
fallbackIcon?: string;

/** Status of the current user from their personal details */
status?: Status;
};

type PersonalDetailsList = Record<string, PersonalDetails | null>;
type PersonalDetailsWithOfflineFeedback = OnyxCommon.OnyxItemWithOfflineFeedback<PersonalDetails, keyof PersonalDetails>;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved

type PersonalDetailsList = Record<string, PersonalDetailsWithOfflineFeedback | null>;

export default PersonalDetails;
export default PersonalDetailsWithOfflineFeedback;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved

export type {Timezone, Status, SelectedTimezone, PersonalDetailsList};
16 changes: 5 additions & 11 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ import type * as OnyxCommon from './OnyxCommon';

type Unit = 'mi' | 'km';

type Rate = {
type Rate = OnyxCommon.OfflineFeedback & {
name?: string;
rate?: number;
currency?: string;
customUnitRateID?: string;
errors?: OnyxCommon.Errors;
pendingAction?: string;
};

type Attributes = {
unit: Unit;
};

type CustomUnit = {
type CustomUnit = OnyxCommon.OfflineFeedback & {
name: string;
customUnitID: string;
attributes: Attributes;
rates: Record<string, Rate>;
pendingAction?: string;
errors?: OnyxCommon.Errors;
};

Expand Down Expand Up @@ -56,9 +54,6 @@ type Policy = {
/** Error objects keyed by field name containing errors keyed by microtime */
errorFields?: OnyxCommon.ErrorFields;

/** Indicates the type of change made to the policy that hasn't been synced with the server yet */
pendingAction?: OnyxCommon.PendingAction;

/** A list of errors keyed by microtime */
errors?: OnyxCommon.Errors;

Expand Down Expand Up @@ -101,9 +96,6 @@ type Policy = {
/** Whether to leave the calling account as an admin on the policy */
makeMeAdmin?: boolean;

/** Pending fields for the policy */
pendingFields?: Record<string, unknown>;

/** Original file name which is used for the policy avatar */
originalFileName?: string;

Expand All @@ -114,6 +106,8 @@ type Policy = {
primaryLoginsInvited?: Record<string, string>;
};

export default Policy;
type PolicyWithOfflineFeedback = OnyxCommon.OnyxItemWithOfflineFeedback<Policy, keyof Policy | 'generalSettings' | 'addWorkspaceRoom'>;

export default PolicyWithOfflineFeedback;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved

export type {Unit, CustomUnit};
5 changes: 1 addition & 4 deletions src/types/onyx/PolicyMember.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as OnyxCommon from './OnyxCommon';

type PolicyMember = {
type PolicyMember = OnyxCommon.OfflineFeedback & {
/** Role of the user in the policy */
role?: string;

Expand All @@ -9,9 +9,6 @@ type PolicyMember = {
* {<timestamp>: 'error message', <timestamp2>: 'error message 2'}
*/
errors?: OnyxCommon.Errors;

/** Is this action pending? */
pendingAction?: OnyxCommon.PendingAction;
};

type PolicyMembers = Record<string, PolicyMember>;
Expand Down
4 changes: 1 addition & 3 deletions src/types/onyx/ReimbursementAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type ACHData = {
bankAccountID?: number;
};

type ReimbursementAccount = {
type ReimbursementAccount = OnyxCommon.OfflineFeedback & {
/** Whether we are loading the data via the API */
isLoading?: boolean;

Expand All @@ -44,8 +44,6 @@ type ReimbursementAccount = {

/** Draft step of the setup flow from Onyx */
draftStep?: BankAccountStep;

pendingAction?: OnyxCommon.PendingAction;
};

export default ReimbursementAccount;
Expand Down
12 changes: 3 additions & 9 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type * as OnyxCommon from './OnyxCommon';
import type PersonalDetails from './PersonalDetails';
import type PolicyReportField from './PolicyReportField';

type NotificationPreference = ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE>;

type WriteCapability = ValueOf<typeof CONST.REPORT.WRITE_CAPABILITIES>;

type Note = {
type Note = OnyxCommon.OfflineFeedback & {
note: string;
errors?: OnyxCommon.Errors;
pendingAction?: OnyxCommon.PendingAction;
};

type Report = {
type Report = OnyxCommon.OfflineFeedback<PolicyReportField['fieldID']> & {
/** The specific type of chat */
chatType?: ValueOf<typeof CONST.REPORT.CHAT_TYPE>;

Expand Down Expand Up @@ -140,12 +140,6 @@ type Report = {
/** Total amount of money owed for IOU report */
iouReportAmount?: number;

/** Is this action pending? */
pendingAction?: OnyxCommon.PendingAction;

/** Pending fields for the report */
pendingFields?: Record<string, OnyxCommon.PendingAction>;

/** The ID of the preexisting report (it is possible that we optimistically created a Report for which a report already exists) */
preexistingReportID?: string;

Expand Down
4 changes: 1 addition & 3 deletions src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type Person = {
text?: string;
};

type ReportActionBase = {
type ReportActionBase = OnyxCommon.OfflineFeedback & {
/** The ID of the reportAction. It is the string representation of the a 64-bit integer. */
reportActionID: string;

Expand Down Expand Up @@ -173,8 +173,6 @@ type ReportActionBase = {
/** ISO-formatted datetime */
lastModified?: string;

/** Is this action pending? */
pendingAction?: OnyxCommon.PendingAction;
delegateAccountID?: string;

/** Server side errors keyed by microtime */
Expand Down
5 changes: 1 addition & 4 deletions src/types/onyx/ReportActionReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type UserReaction = {

type UsersReactions = Record<string, UserReaction>;

type ReportActionReaction = {
type ReportActionReaction = OnyxCommon.OfflineFeedback & {
/** The time the emoji was added */
createdAt: string;

Expand All @@ -22,9 +22,6 @@ type ReportActionReaction = {

/** All the users who have added this emoji */
users: UsersReactions;

/** Is this action pending? */
pendingAction?: OnyxCommon.PendingAction;
};

type ReportActionReactions = Record<string, ReportActionReaction>;
Expand Down
6 changes: 3 additions & 3 deletions src/types/onyx/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ type Transaction = {
modifiedWaypoints?: WaypointCollection;
// Used during the creation flow before the transaction is saved to the server and helps dictate where the user is navigated to when pressing the back button on the confirmation step
participantsAutoAssigned?: boolean;
pendingAction: OnyxCommon.PendingAction;
receipt?: Receipt;
reportID: string;
routes?: Routes;
transactionID: string;
tag: string;
pendingFields?: Partial<{[K in keyof Transaction | keyof Comment]: ValueOf<typeof CONST.RED_BRICK_ROAD_PENDING_ACTION>}>;

/** Card Transactions */

Expand All @@ -96,5 +94,7 @@ type Transaction = {
originalCurrency?: string;
};

export default Transaction;
type TransactionWithOfflineFeedback = OnyxCommon.OnyxItemWithOfflineFeedback<Transaction, keyof Transaction | keyof Comment>;

export default TransactionWithOfflineFeedback;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
export type {WaypointCollection, Comment, Receipt, Waypoint};
Loading