From 345e001008c1df68b3311945f46cba9424ccae9a Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:10:16 +0200 Subject: [PATCH 1/5] swap from using Environment to using hook useEnvironment --- src/libs/Environment/Environment.ts | 9 +-------- .../report/ContextMenu/ContextMenuActions.tsx | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/libs/Environment/Environment.ts b/src/libs/Environment/Environment.ts index c343788bed05..1f5a391d3b13 100644 --- a/src/libs/Environment/Environment.ts +++ b/src/libs/Environment/Environment.ts @@ -38,13 +38,6 @@ function isDevelopment(): boolean { return (Config?.ENVIRONMENT ?? CONST.ENVIRONMENT.DEV) === CONST.ENVIRONMENT.DEV; } -/** - * Are we running the app in staging? - */ -function isStaging(): boolean { - return (Config?.ENVIRONMENT ?? CONST.ENVIRONMENT.DEV) === CONST.ENVIRONMENT.STAGING; -} - /** * Are we running the app in production? */ @@ -83,4 +76,4 @@ function getSpotnanaEnvironmentTMCID(): Promise { return getEnvironment().then((environment) => SPOTNANA_ENVIRONMENT_TMC_ID[environment]); } -export {getEnvironment, isInternalTestBuild, isDevelopment, isStaging, isProduction, getEnvironmentURL, getOldDotEnvironmentURL, getTravelDotEnvironmentURL, getSpotnanaEnvironmentTMCID}; +export {getEnvironment, isInternalTestBuild, isDevelopment, isProduction, getEnvironmentURL, getOldDotEnvironmentURL, getTravelDotEnvironmentURL, getSpotnanaEnvironmentTMCID}; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index b0a4d3d59d09..00b69b3adee7 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -35,6 +35,7 @@ import type {Beta, Download as DownloadOnyx, OnyxInputOrEntry, ReportAction, Rep import type IconAsset from '@src/types/utils/IconAsset'; import type {ContextMenuAnchor} from './ReportActionContextMenu'; import {hideContextMenu, showDeleteModal} from './ReportActionContextMenu'; +import useEnvironment from '@hooks/useEnvironment'; /** Gets the HTML version of the message in an action */ function getActionHtml(reportAction: OnyxInputOrEntry): string { @@ -542,7 +543,22 @@ const ContextMenuActions: ContextMenuAction[] = [ icon: Expensicons.Copy, successTextTranslateKey: 'reportActionContextMenu.copied', successIcon: Expensicons.Checkmark, - shouldShow: (type) => type === CONST.CONTEXT_MENU_TYPES.REPORT && (Environment.isDevelopment() || Environment.isStaging() || Environment.isInternalTestBuild()), + shouldShow: (type) => { + const {environment, isProduction} = useEnvironment(); + + // If we are on production, don't show this option + if (isProduction) { + return false; + } + + const isADHOC = environment === CONST.ENVIRONMENT.ADHOC; + const isStaging = environment === CONST.ENVIRONMENT.STAGING; + const isDevelopment = environment === CONST.ENVIRONMENT.DEV; + + return ( + type === CONST.CONTEXT_MENU_TYPES.REPORT && (isDevelopment || isStaging || isADHOC) + ); + }, onPress: (closePopover, {reportID}) => { const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; Clipboard.setString(JSON.stringify(report, null, 4)); From ac37fdbedc69d246c3ebb7f8252167a987348073 Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:15:15 +0200 Subject: [PATCH 2/5] fix prettier --- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 00b69b3adee7..bdd456201c49 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -9,6 +9,7 @@ import type {Emoji} from '@assets/emojis/types'; import * as Expensicons from '@components/Icon/Expensicons'; import MiniQuickEmojiReactions from '@components/Reactions/MiniQuickEmojiReactions'; import QuickEmojiReactions from '@components/Reactions/QuickEmojiReactions'; +import useEnvironment from '@hooks/useEnvironment'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import * as Browser from '@libs/Browser'; import Clipboard from '@libs/Clipboard'; @@ -35,7 +36,6 @@ import type {Beta, Download as DownloadOnyx, OnyxInputOrEntry, ReportAction, Rep import type IconAsset from '@src/types/utils/IconAsset'; import type {ContextMenuAnchor} from './ReportActionContextMenu'; import {hideContextMenu, showDeleteModal} from './ReportActionContextMenu'; -import useEnvironment from '@hooks/useEnvironment'; /** Gets the HTML version of the message in an action */ function getActionHtml(reportAction: OnyxInputOrEntry): string { @@ -545,7 +545,7 @@ const ContextMenuActions: ContextMenuAction[] = [ successIcon: Expensicons.Checkmark, shouldShow: (type) => { const {environment, isProduction} = useEnvironment(); - + // If we are on production, don't show this option if (isProduction) { return false; @@ -555,9 +555,7 @@ const ContextMenuActions: ContextMenuAction[] = [ const isStaging = environment === CONST.ENVIRONMENT.STAGING; const isDevelopment = environment === CONST.ENVIRONMENT.DEV; - return ( - type === CONST.CONTEXT_MENU_TYPES.REPORT && (isDevelopment || isStaging || isADHOC) - ); + return type === CONST.CONTEXT_MENU_TYPES.REPORT && (isDevelopment || isStaging || isADHOC); }, onPress: (closePopover, {reportID}) => { const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; From b2d4926ce4fbed1ee49d514b977cf40d72f83608 Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:29:13 +0200 Subject: [PATCH 3/5] fix lint by disabling check for hook rule --- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index bdd456201c49..f0a8b63c1c72 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -544,6 +544,7 @@ const ContextMenuActions: ContextMenuAction[] = [ successTextTranslateKey: 'reportActionContextMenu.copied', successIcon: Expensicons.Checkmark, shouldShow: (type) => { + // eslint-disable-next-line react-hooks/rules-of-hooks const {environment, isProduction} = useEnvironment(); // If we are on production, don't show this option From f20f5374169dc5105643e3664737c724b6012de3 Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:00:17 +0200 Subject: [PATCH 4/5] simplify environment check --- .../home/report/ContextMenu/ContextMenuActions.tsx | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index f0a8b63c1c72..cd8e3583e54d 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -545,18 +545,9 @@ const ContextMenuActions: ContextMenuAction[] = [ successIcon: Expensicons.Checkmark, shouldShow: (type) => { // eslint-disable-next-line react-hooks/rules-of-hooks - const {environment, isProduction} = useEnvironment(); + const {isProduction} = useEnvironment(); - // If we are on production, don't show this option - if (isProduction) { - return false; - } - - const isADHOC = environment === CONST.ENVIRONMENT.ADHOC; - const isStaging = environment === CONST.ENVIRONMENT.STAGING; - const isDevelopment = environment === CONST.ENVIRONMENT.DEV; - - return type === CONST.CONTEXT_MENU_TYPES.REPORT && (isDevelopment || isStaging || isADHOC); + return type === CONST.CONTEXT_MENU_TYPES.REPORT && !isProduction; }, onPress: (closePopover, {reportID}) => { const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; From f24cd055cc575e3744f9b0b141333557a095bbb0 Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:11:34 +0200 Subject: [PATCH 5/5] move useEnvironment into a component --- .../report/ContextMenu/BaseReportActionContextMenu.tsx | 4 +++- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 9 ++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 7a191d7bff03..f1b9cd4bfabe 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -10,6 +10,7 @@ import type {ContextMenuItemHandle} from '@components/ContextMenuItem'; import ContextMenuItem from '@components/ContextMenuItem'; import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal'; import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager'; +import useEnvironment from '@hooks/useEnvironment'; import useKeyboardShortcut from '@hooks/useKeyboardShortcut'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; @@ -126,6 +127,7 @@ function BaseReportActionContextMenu({ const [shouldKeepOpen, setShouldKeepOpen] = useState(false); const wrapperStyle = StyleUtils.getReportActionContextMenuStyles(isMini, shouldUseNarrowLayout); const {isOffline} = useNetwork(); + const {isProduction} = useEnvironment(); const threedotRef = useRef(null); const reportAction: OnyxEntry = useMemo(() => { @@ -145,7 +147,7 @@ function BaseReportActionContextMenu({ let filteredContextMenuActions = ContextMenuActions.filter( (contextAction) => !disabledActions.includes(contextAction) && - contextAction.shouldShow(type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isUnreadChat, !!isOffline, isMini), + contextAction.shouldShow(type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isUnreadChat, !!isOffline, isMini, isProduction), ); if (isMini) { diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index cd8e3583e54d..3dad270bc66d 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -9,7 +9,6 @@ import type {Emoji} from '@assets/emojis/types'; import * as Expensicons from '@components/Icon/Expensicons'; import MiniQuickEmojiReactions from '@components/Reactions/MiniQuickEmojiReactions'; import QuickEmojiReactions from '@components/Reactions/QuickEmojiReactions'; -import useEnvironment from '@hooks/useEnvironment'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import * as Browser from '@libs/Browser'; import Clipboard from '@libs/Clipboard'; @@ -67,6 +66,7 @@ type ShouldShow = ( isUnreadChat: boolean, isOffline: boolean, isMini: boolean, + isProduction: boolean, ) => boolean; type ContextMenuActionPayload = { @@ -543,12 +543,7 @@ const ContextMenuActions: ContextMenuAction[] = [ icon: Expensicons.Copy, successTextTranslateKey: 'reportActionContextMenu.copied', successIcon: Expensicons.Checkmark, - shouldShow: (type) => { - // eslint-disable-next-line react-hooks/rules-of-hooks - const {isProduction} = useEnvironment(); - - return type === CONST.CONTEXT_MENU_TYPES.REPORT && !isProduction; - }, + shouldShow: (type, isProduction) => type === CONST.CONTEXT_MENU_TYPES.REPORT && !isProduction, onPress: (closePopover, {reportID}) => { const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; Clipboard.setString(JSON.stringify(report, null, 4));