Skip to content

Commit

Permalink
Merge pull request #25764 from software-mansion-labs/ts-migration/CONST
Browse files Browse the repository at this point in the history
[No QA][TS migration] Migrate 'CONST.js' constant to TypeScript
  • Loading branch information
robertjchen authored Aug 28, 2023
2 parents d09a1b6 + 1790cfe commit 3948600
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 46 deletions.
63 changes: 32 additions & 31 deletions src/CONST.js → src/CONST.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import lodashGet from 'lodash/get';
/* eslint-disable @typescript-eslint/naming-convention */
import Config from 'react-native-config';
import * as KeyCommand from 'react-native-key-command';
import * as Url from './libs/Url';
import SCREENS from './SCREENS';

const CLOUDFRONT_DOMAIN = 'cloudfront.net';
const CLOUDFRONT_URL = `https://d2k5nsl2zxldvw.${CLOUDFRONT_DOMAIN}`;
const ACTIVE_EXPENSIFY_URL = Url.addTrailingForwardSlash(lodashGet(Config, 'NEW_EXPENSIFY_URL', 'https://new.expensify.com'));
const ACTIVE_EXPENSIFY_URL = Url.addTrailingForwardSlash(Config?.NEW_EXPENSIFY_URL ?? 'https://new.expensify.com');
const USE_EXPENSIFY_URL = 'https://use.expensify.com';
const PLATFORM_OS_MACOS = 'Mac OS';
const PLATFORM_IOS = 'iOS';
const ANDROID_PACKAGE_NAME = 'com.expensify.chat';
const CURRENT_YEAR = new Date().getFullYear();
const PULL_REQUEST_NUMBER = lodashGet(Config, 'PULL_REQUEST_NUMBER', '');

const keyModifierControl = lodashGet(KeyCommand, 'constants.keyModifierControl', 'keyModifierControl');
const keyModifierCommand = lodashGet(KeyCommand, 'constants.keyModifierCommand', 'keyModifierCommand');
const keyModifierShiftControl = lodashGet(KeyCommand, 'constants.keyModifierShiftControl', 'keyModifierShiftControl');
const keyModifierShiftCommand = lodashGet(KeyCommand, 'constants.keyModifierShiftCommand', 'keyModifierShiftCommand');
const keyInputEscape = lodashGet(KeyCommand, 'constants.keyInputEscape', 'keyInputEscape');
const keyInputEnter = lodashGet(KeyCommand, 'constants.keyInputEnter', 'keyInputEnter');
const keyInputUpArrow = lodashGet(KeyCommand, 'constants.keyInputUpArrow', 'keyInputUpArrow');
const keyInputDownArrow = lodashGet(KeyCommand, 'constants.keyInputDownArrow', 'keyInputDownArrow');
const keyInputLeftArrow = lodashGet(KeyCommand, 'constants.keyInputLeftArrow', 'keyInputLeftArrow');
const keyInputRightArrow = lodashGet(KeyCommand, 'constants.keyInputRightArrow', 'keyInputRightArrow');
const PULL_REQUEST_NUMBER = Config?.PULL_REQUEST_NUMBER ?? '';

const keyModifierControl = KeyCommand?.constants?.keyModifierControl ?? 'keyModifierControl';
const keyModifierCommand = KeyCommand?.constants?.keyModifierCommand ?? 'keyModifierCommand';
const keyModifierShiftControl = KeyCommand?.constants?.keyModifierShiftControl ?? 'keyModifierShiftControl';
const keyModifierShiftCommand = KeyCommand?.constants?.keyModifierShiftCommand ?? 'keyModifierShiftCommand';
const keyInputEscape = KeyCommand?.constants?.keyInputEscape ?? 'keyInputEscape';
const keyInputEnter = KeyCommand?.constants?.keyInputEnter ?? 'keyInputEnter';
const keyInputUpArrow = KeyCommand?.constants?.keyInputUpArrow ?? 'keyInputUpArrow';
const keyInputDownArrow = KeyCommand?.constants?.keyInputDownArrow ?? 'keyInputDownArrow';
const keyInputLeftArrow = KeyCommand?.constants?.keyInputLeftArrow ?? 'keyInputLeftArrow';
const keyInputRightArrow = KeyCommand?.constants?.keyInputRightArrow ?? 'keyInputRightArrow';

// describes if a shortcut key can cause navigation
const KEYBOARD_SHORTCUT_NAVIGATION_TYPE = 'NAVIGATION_SHORTCUT';
Expand Down Expand Up @@ -884,22 +884,22 @@ const CONST = {
},

ACCOUNT_ID: {
ACCOUNTING: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_ACCOUNTING', 9645353)),
ADMIN: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_ADMIN', -1)),
BILLS: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_BILLS', 1371)),
CHRONOS: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_CHRONOS', 10027416)),
CONCIERGE: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_CONCIERGE', 8392101)),
CONTRIBUTORS: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_CONTRIBUTORS', 9675014)),
FIRST_RESPONDER: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_FIRST_RESPONDER', 9375152)),
HELP: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_HELP', -1)),
INTEGRATION_TESTING_CREDS: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_INTEGRATION_TESTING_CREDS', -1)),
PAYROLL: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_PAYROLL', 9679724)),
QA: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_QA', 3126513)),
QA_TRAVIS: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_QA_TRAVIS', 8595733)),
RECEIPTS: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_RECEIPTS', -1)),
REWARDS: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_REWARDS', 11023767)), // [email protected]
STUDENT_AMBASSADOR: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_STUDENT_AMBASSADOR', 10476956)),
SVFG: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_SVFG', 2012843)),
ACCOUNTING: Number(Config?.EXPENSIFY_ACCOUNT_ID_ACCOUNTING ?? 9645353),
ADMIN: Number(Config?.EXPENSIFY_ACCOUNT_ID_ADMIN ?? -1),
BILLS: Number(Config?.EXPENSIFY_ACCOUNT_ID_BILLS ?? 1371),
CHRONOS: Number(Config?.EXPENSIFY_ACCOUNT_ID_CHRONOS ?? 10027416),
CONCIERGE: Number(Config?.EXPENSIFY_ACCOUNT_ID_CONCIERGE ?? 8392101),
CONTRIBUTORS: Number(Config?.EXPENSIFY_ACCOUNT_ID_CONTRIBUTORS ?? 9675014),
FIRST_RESPONDER: Number(Config?.EXPENSIFY_ACCOUNT_ID_FIRST_RESPONDER ?? 9375152),
HELP: Number(Config?.EXPENSIFY_ACCOUNT_ID_HELP ?? -1),
INTEGRATION_TESTING_CREDS: Number(Config?.EXPENSIFY_ACCOUNT_ID_INTEGRATION_TESTING_CREDS ?? -1),
PAYROLL: Number(Config?.EXPENSIFY_ACCOUNT_ID_PAYROLL ?? 9679724),
QA: Number(Config?.EXPENSIFY_ACCOUNT_ID_QA ?? 3126513),
QA_TRAVIS: Number(Config?.EXPENSIFY_ACCOUNT_ID_QA_TRAVIS ?? 8595733),
RECEIPTS: Number(Config?.EXPENSIFY_ACCOUNT_ID_RECEIPTS ?? -1),
REWARDS: Number(Config?.EXPENSIFY_ACCOUNT_ID_REWARDS ?? 11023767), // [email protected]
STUDENT_AMBASSADOR: Number(Config?.EXPENSIFY_ACCOUNT_ID_STUDENT_AMBASSADOR ?? 10476956),
SVFG: Number(Config?.EXPENSIFY_ACCOUNT_ID_SVFG ?? 2012843),
},

ENVIRONMENT: {
Expand Down Expand Up @@ -2599,10 +2599,11 @@ const CONST = {
NAVIGATE: 'NAVIGATE',
},
},

DEMO_PAGES: {
SAASTR: 'SaaStrDemoSetup',
SBE: 'SbeDemoSetup',
},
};
} as const;

export default CONST;
13 changes: 2 additions & 11 deletions src/global.d.ts → src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {OnyxKey, OnyxCollectionKey, OnyxValues} from './ONYXKEYS';

declare module '*.png' {
const value: import('react-native').ImageSourcePropType;
export default value;
}

declare module '*.jpg' {
const value: import('react-native').ImageSourcePropType;
export default value;
}

declare module '*.svg' {
import React from 'react';
import {SvgProps} from 'react-native-svg';
Expand All @@ -17,12 +17,3 @@ declare module '*.svg' {
}

declare module 'react-native-device-info/jest/react-native-device-info-mock';

declare module 'react-native-onyx' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface CustomTypeOptions {
keys: OnyxKey;
collectionKeys: OnyxCollectionKey;
values: OnyxValues;
}
}
30 changes: 30 additions & 0 deletions src/types/modules/react-native-key-command.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
declare module 'react-native-key-command' {
declare const constants = {
keyInputDownArrow: 'keyInputDownArrow',
keyInputEscape: 'keyInputEscape',
keyInputLeftArrow: 'keyInputLeftArrow',
keyInputRightArrow: 'keyInputRightArrow',
keyInputUpArrow: 'keyInputUpArrow',
keyInputEnter: 'keyInputEnter',
keyModifierCapsLock: 'keyModifierCapsLock',
keyModifierCommand: 'keyModifierCommand',
keyModifierControl: 'keyModifierControl',
keyModifierControlCommand: 'keyModifierControlCommand',
keyModifierControlOption: 'keyModifierControlOption',
keyModifierControlOptionCommand: 'keyModifierControlOptionCommand',
keyModifierNumericPad: 'keyModifierNumericPad',
keyModifierOption: 'keyModifierOption',
keyModifierOptionCommand: 'keyModifierOptionCommand',
keyModifierShift: 'keyModifierShift',
keyModifierShiftCommand: 'keyModifierShiftCommand',
keyModifierShiftControl: 'keyModifierShiftControl',
keyModifierAlternate: 'keyModifierAlternate',
} as const;

type KeyCommand = {input: string; modifierFlags: string};

declare function addListener(keyCommand: KeyCommand, callback: (keycommandEvent: KeyCommand, event: Event) => void): () => void;

// eslint-disable-next-line import/prefer-default-export
export {constants, addListener};
}
10 changes: 10 additions & 0 deletions src/types/modules/react-native-onyx.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {OnyxKey, OnyxCollectionKey, OnyxValues} from '../../ONYXKEYS';

declare module 'react-native-onyx' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface CustomTypeOptions {
keys: OnyxKey;
collectionKeys: OnyxCollectionKey;
values: OnyxValues;
}
}
2 changes: 0 additions & 2 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: Remove this after CONST.ts is migrated to TS
/* eslint-disable @typescript-eslint/no-duplicate-type-constituents */
import {ValueOf} from 'type-fest';
import CONST from '../../CONST';

Expand Down
2 changes: 0 additions & 2 deletions src/types/onyx/WalletTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ type WalletTransfer = {
selectedAccountType?: string;

/** Type to filter the payment Method list */
// TODO: Remove this after CONST.ts is migrated to TS
// eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
filterPaymentMethodType?: typeof CONST.PAYMENT_METHODS.DEBIT_CARD | typeof CONST.PAYMENT_METHODS.BANK_ACCOUNT;

/** Whether the success screen is shown to user. */
Expand Down

0 comments on commit 3948600

Please sign in to comment.