From 18760dd91dd4dccb3fa29c08c3487c59aabc9c15 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 15 Jun 2023 15:15:27 +0530 Subject: [PATCH 1/5] environment url implementation --- src/components/withEnvironment.js | 8 ++++++++ src/libs/Environment/Environment.js | 8 +++++++- src/pages/ShareCodePage.js | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/withEnvironment.js b/src/components/withEnvironment.js index f91dd4b533d2..51da36c46b70 100644 --- a/src/components/withEnvironment.js +++ b/src/components/withEnvironment.js @@ -7,6 +7,9 @@ import getComponentDisplayName from '../libs/getComponentDisplayName'; const environmentPropTypes = { /** The string value representing the current environment */ environment: PropTypes.string.isRequired, + + /** The string value representing the URL of the current environment */ + environmentURL: PropTypes.string.isRequired, }; export default function (WrappedComponent) { @@ -16,6 +19,7 @@ export default function (WrappedComponent) { this.state = { environment: CONST.ENVIRONMENT.PRODUCTION, + environmentURL: CONST.NEW_EXPENSIFY_URL, }; } @@ -23,6 +27,9 @@ export default function (WrappedComponent) { Environment.getEnvironment().then((environment) => { this.setState({environment}); }); + Environment.getEnvironmentURL().then((environmentURL) => { + this.setState({environmentURL}) + }); } render() { @@ -32,6 +39,7 @@ export default function (WrappedComponent) { {...this.props} ref={this.props.forwardedRef} environment={this.state.environment} + environmentURL={this.state.environmentURL} /> ); } diff --git a/src/libs/Environment/Environment.js b/src/libs/Environment/Environment.js index c039b49d33aa..6c90d39369b8 100644 --- a/src/libs/Environment/Environment.js +++ b/src/libs/Environment/Environment.js @@ -3,6 +3,7 @@ import lodashGet from 'lodash/get'; import CONST from '../../CONST'; import getEnvironment from './getEnvironment'; import CONFIG from '../../CONFIG'; +import * as Url from '../Url'; const ENVIRONMENT_URLS = { [CONST.ENVIRONMENT.DEV]: CONST.DEV_NEW_EXPENSIFY_URL + CONFIG.DEV_PORT, @@ -43,7 +44,12 @@ function isInternalTestBuild() { */ function getEnvironmentURL() { return new Promise((resolve) => { - getEnvironment().then((environment) => resolve(ENVIRONMENT_URLS[environment])); + getEnvironment().then((environment) => + { + // Our approach is to use staging url only for staging environment and use production url for all other environments. + const environmentURL = (environment === CONST.ENVIRONMENT.STAGING) ? Url.addTrailingForwardSlash(CONST.STAGING_NEW_EXPENSIFY_URL) : CONST.NEW_EXPENSIFY_URL; + resolve(environmentURL); + }); }); } diff --git a/src/pages/ShareCodePage.js b/src/pages/ShareCodePage.js index 456fbe78d6db..b06db9e7a4c6 100644 --- a/src/pages/ShareCodePage.js +++ b/src/pages/ShareCodePage.js @@ -19,6 +19,7 @@ import CONST from '../CONST'; import ContextMenuItem from '../components/ContextMenuItem'; import * as UserUtils from '../libs/UserUtils'; import ROUTES from '../ROUTES'; +import withEnvironment, {environmentPropTypes} from '../components/withEnvironment'; const propTypes = { /** The report currently being looked at */ @@ -26,6 +27,7 @@ const propTypes = { ...withLocalizePropTypes, ...withCurrentUserPersonalDetailsPropTypes, + ...environmentPropTypes, }; const defaultProps = { @@ -41,7 +43,7 @@ class ShareCodePage extends React.Component { const isReport = this.props.report != null && this.props.report.reportID != null; const subtitle = ReportUtils.getChatRoomSubtitle(this.props.report); - const url = isReport ? `${CONST.NEW_EXPENSIFY_URL}r/${this.props.report.reportID}` : `${CONST.NEW_EXPENSIFY_URL}details?login=${encodeURIComponent(this.props.session.email)}`; + const url = isReport ? `${this.props.environmentURL}r/${this.props.report.reportID}` : `${this.props.environmentURL}details?login=${encodeURIComponent(this.props.session.email)}`; const platform = getPlatform(); const isNative = platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID; @@ -94,4 +96,4 @@ class ShareCodePage extends React.Component { ShareCodePage.propTypes = propTypes; ShareCodePage.defaultProps = defaultProps; -export default compose(withLocalize, withCurrentUserPersonalDetails)(ShareCodePage); +export default compose(withEnvironment, withLocalize, withCurrentUserPersonalDetails)(ShareCodePage); From 2bc3aba38650a5a8f7cd0353529dac8d12a5e577 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Fri, 16 Jun 2023 16:37:48 +0530 Subject: [PATCH 2/5] lint error and additional fix --- src/libs/Environment/Environment.js | 7 ------- src/pages/home/report/ContextMenu/ContextMenuActions.js | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libs/Environment/Environment.js b/src/libs/Environment/Environment.js index 6c90d39369b8..5c73f6bccc59 100644 --- a/src/libs/Environment/Environment.js +++ b/src/libs/Environment/Environment.js @@ -5,13 +5,6 @@ import getEnvironment from './getEnvironment'; import CONFIG from '../../CONFIG'; import * as Url from '../Url'; -const ENVIRONMENT_URLS = { - [CONST.ENVIRONMENT.DEV]: CONST.DEV_NEW_EXPENSIFY_URL + CONFIG.DEV_PORT, - [CONST.ENVIRONMENT.STAGING]: CONST.STAGING_NEW_EXPENSIFY_URL, - [CONST.ENVIRONMENT.PRODUCTION]: CONST.NEW_EXPENSIFY_URL, - [CONST.ENVIRONMENT.ADHOC]: CONST.STAGING_NEW_EXPENSIFY_URL, -}; - const OLDDOT_ENVIRONMENT_URLS = { [CONST.ENVIRONMENT.DEV]: CONST.INTERNAL_DEV_EXPENSIFY_URL, [CONST.ENVIRONMENT.STAGING]: CONST.STAGING_EXPENSIFY_URL, diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 0edcc509d040..f63d9772843c 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -210,7 +210,7 @@ export default [ onPress: (closePopover, {reportAction, reportID}) => { Environment.getEnvironmentURL().then((environmentURL) => { const reportActionID = parseInt(lodashGet(reportAction, 'reportActionID'), 10); - Clipboard.setString(`${environmentURL}/r/${reportID}/${reportActionID}`); + Clipboard.setString(`${environmentURL}r/${reportID}/${reportActionID}`); }); hideContextMenu(true, ReportActionComposeFocusManager.focus); }, From 9569e7684f3873430cdedc9d64fcd832f9e4b5ac Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 19 Jun 2023 11:55:34 +0530 Subject: [PATCH 3/5] Rolled back environment related changes --- src/libs/Environment/Environment.js | 15 ++++++++------- .../home/report/ContextMenu/ContextMenuActions.js | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libs/Environment/Environment.js b/src/libs/Environment/Environment.js index 5c73f6bccc59..c039b49d33aa 100644 --- a/src/libs/Environment/Environment.js +++ b/src/libs/Environment/Environment.js @@ -3,7 +3,13 @@ import lodashGet from 'lodash/get'; import CONST from '../../CONST'; import getEnvironment from './getEnvironment'; import CONFIG from '../../CONFIG'; -import * as Url from '../Url'; + +const ENVIRONMENT_URLS = { + [CONST.ENVIRONMENT.DEV]: CONST.DEV_NEW_EXPENSIFY_URL + CONFIG.DEV_PORT, + [CONST.ENVIRONMENT.STAGING]: CONST.STAGING_NEW_EXPENSIFY_URL, + [CONST.ENVIRONMENT.PRODUCTION]: CONST.NEW_EXPENSIFY_URL, + [CONST.ENVIRONMENT.ADHOC]: CONST.STAGING_NEW_EXPENSIFY_URL, +}; const OLDDOT_ENVIRONMENT_URLS = { [CONST.ENVIRONMENT.DEV]: CONST.INTERNAL_DEV_EXPENSIFY_URL, @@ -37,12 +43,7 @@ function isInternalTestBuild() { */ function getEnvironmentURL() { return new Promise((resolve) => { - getEnvironment().then((environment) => - { - // Our approach is to use staging url only for staging environment and use production url for all other environments. - const environmentURL = (environment === CONST.ENVIRONMENT.STAGING) ? Url.addTrailingForwardSlash(CONST.STAGING_NEW_EXPENSIFY_URL) : CONST.NEW_EXPENSIFY_URL; - resolve(environmentURL); - }); + getEnvironment().then((environment) => resolve(ENVIRONMENT_URLS[environment])); }); } diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index ad01d5243e1a..9f01db925abb 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -206,7 +206,7 @@ export default [ onPress: (closePopover, {reportAction, reportID}) => { Environment.getEnvironmentURL().then((environmentURL) => { const reportActionID = parseInt(lodashGet(reportAction, 'reportActionID'), 10); - Clipboard.setString(`${environmentURL}r/${reportID}/${reportActionID}`); + Clipboard.setString(`${environmentURL}/r/${reportID}/${reportActionID}`); }); hideContextMenu(true, ReportActionComposeFocusManager.focus); }, From ce0d5623660e055be7a6b6b9f5cb46c6dd461a51 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 19 Jun 2023 11:58:28 +0530 Subject: [PATCH 4/5] ensure trailing slash in url --- src/pages/ShareCodePage.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/ShareCodePage.js b/src/pages/ShareCodePage.js index 82a863d0db85..b1471a76cfd9 100644 --- a/src/pages/ShareCodePage.js +++ b/src/pages/ShareCodePage.js @@ -20,6 +20,7 @@ import ContextMenuItem from '../components/ContextMenuItem'; import * as UserUtils from '../libs/UserUtils'; import ROUTES from '../ROUTES'; import withEnvironment, {environmentPropTypes} from '../components/withEnvironment'; +import * as Url from '../libs/Url'; const propTypes = { /** The report currently being looked at */ @@ -43,7 +44,8 @@ class ShareCodePage extends React.Component { const isReport = this.props.report != null && this.props.report.reportID != null; const subtitle = ReportUtils.getChatRoomSubtitle(this.props.report); - const url = isReport ? `${this.props.environmentURL}r/${this.props.report.reportID}` : `${this.props.environmentURL}details?login=${encodeURIComponent(this.props.session.email)}`; + const urlWithTrailingSlash = Url.addTrailingForwardSlash(this.props.environmentURL); + const url = isReport ? `${urlWithTrailingSlash}r/${this.props.report.reportID}` : `${urlWithTrailingSlash}details?login=${encodeURIComponent(this.props.session.email)}`; const platform = getPlatform(); const isNative = platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID; From d8f688e898ab8decead7364d250ed2c122da688e Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 21 Jun 2023 02:59:40 +0530 Subject: [PATCH 5/5] prettier diff lint fix --- src/components/withEnvironment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/withEnvironment.js b/src/components/withEnvironment.js index 51da36c46b70..f9a0cf1fa964 100644 --- a/src/components/withEnvironment.js +++ b/src/components/withEnvironment.js @@ -28,7 +28,7 @@ export default function (WrappedComponent) { this.setState({environment}); }); Environment.getEnvironmentURL().then((environmentURL) => { - this.setState({environmentURL}) + this.setState({environmentURL}); }); }