Repository navigation
Show the environment badge in the top bar again #106695
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
Changes from all commits
8d8a46b
15b4411
b08e9da
444d1c6
42f5027
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * Small badge shown next to the logo or the top bar title on every environment except production, so it's easy to tell which one you are using. | ||
| */ | ||
| import useEnvironment from '@hooks/useEnvironment'; | ||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| import {isInternalTestBuild} from '@libs/Environment/Environment'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| import type {StyleProp, ViewStyle} from 'react-native'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import pkg from '../../package.json'; | ||
| import Badge from './Badge'; | ||
|
|
||
| const ENVIRONMENT_SHORT_FORM = { | ||
| [CONST.ENVIRONMENT.DEV]: 'DEV', | ||
| [CONST.ENVIRONMENT.STAGING]: 'STG', | ||
| [CONST.ENVIRONMENT.QA]: 'QA', | ||
| [CONST.ENVIRONMENT.PRODUCTION]: 'PROD', | ||
| [CONST.ENVIRONMENT.ADHOC]: 'ADHOC', | ||
| }; | ||
|
|
||
| type EnvironmentBadgeProps = { | ||
| style?: StyleProp<ViewStyle>; | ||
| }; | ||
|
|
||
| function EnvironmentBadge({style}: EnvironmentBadgeProps) { | ||
| const styles = useThemeStyles(); | ||
| const StyleUtils = useStyleUtils(); | ||
| const {environment, isProduction} = useEnvironment(); | ||
|
|
||
| if (isProduction) { | ||
| return null; | ||
| } | ||
|
|
||
| const adhoc = environment === CONST.ENVIRONMENT.ADHOC; | ||
| const success = environment === CONST.ENVIRONMENT.STAGING; | ||
| const error = environment !== CONST.ENVIRONMENT.STAGING && environment !== CONST.ENVIRONMENT.ADHOC; | ||
|
|
||
| const badgeEnvironmentStyle = StyleUtils.getEnvironmentBadgeStyle(success, error, adhoc); | ||
| const text = isInternalTestBuild() ? `v${pkg.version} PR:${CONST.PULL_REQUEST_NUMBER}` : ENVIRONMENT_SHORT_FORM[environment]; | ||
|
|
||
| return ( | ||
| <Badge | ||
| success={success} | ||
| error={error} | ||
| text={text} | ||
| badgeStyles={[styles.headerEnvBadge, styles.environmentBadge, badgeEnvironmentStyle, style]} | ||
| textStyles={styles.headerEnvBadgeText} | ||
| environment={environment} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default EnvironmentBadge; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -892,6 +892,11 @@ const staticStyles = (theme: ThemeColors) => | |
| paddingLeft: variables.flatNavigationBarRowInset + variables.flatNavigationBarRowPadding, | ||
| }, | ||
|
|
||
| // The "y" at the end of the wordmark already leaves empty space on its right, so the badge sits closer than the default badge margin | ||
| flatNavigationBarEnvironmentBadge: { | ||
| marginLeft: 6, | ||
| }, | ||
|
|
||
| flatNavigationBarCreateButtonContainer: { | ||
| marginHorizontal: variables.flatNavigationBarCreateButtonInset, | ||
| marginBottom: variables.flatNavigationBarCreateButtonGap, | ||
|
|
@@ -5197,15 +5202,10 @@ const staticStyles = (theme: ThemeColors) => | |
| }, | ||
|
|
||
| headerEnvBadge: { | ||
| position: 'absolute', | ||
| bottom: -8, | ||
| left: -8, | ||
| height: 12, | ||
| width: 22, | ||
| paddingLeft: 4, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is the other way around, in RN (and react-native-web) the longhand
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. My bad |
||
| paddingRight: 4, | ||
| alignItems: 'center', | ||
| zIndex: -1, | ||
| }, | ||
|
|
||
| headerEnvBadgeText: { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On internal ad-hoc PR builds, this branch produces a long label such as
v9.5.37-0 PR:106694, but the badge still receivesstyles.headerEnvBadge, which fixes its width at 22 px, whileBadgerenders the text withnumberOfLines={1}. The version and PR number will therefore be truncated or overflow the small colored background, making the identifying information unreadable; use a content-sized style for internal-test builds instead of the fixed-width short-form badge.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the fixed width was there since before the badge was removed. Removed it in b08e9da,
environmentBadgealready hasminWidth: 22so the short labels look the same and the ad hoc one grows to fit.