Skip to content

Commit 1b065ff

Browse files
authored
Show beta info in header (#340)
* Expose version from package.json to app * Setup beta info component * Update header with beta info + tweak for small screens * Use latest commit hash instead of package.json version
1 parent 38ddcf2 commit 1b065ff

File tree

7 files changed

+76
-7
lines changed

7 files changed

+76
-7
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@import 'src/design-system/variables/variables.scss';
2+
@import 'src/design-system/variables/colors.scss';
3+
@import 'src/design-system/variables/typography.scss';
4+
5+
.wrapper {
6+
display: flex;
7+
align-items: center;
8+
justify-content: center;
9+
gap: 16px;
10+
}
11+
12+
.badge {
13+
padding: 4px 16px;
14+
border-radius: 4px;
15+
background-color: $color-success-100;
16+
color: $color-success-700;
17+
text-align: center;
18+
@include label();
19+
}
20+
21+
.version {
22+
@include paragraph-x-small();
23+
white-space: nowrap;
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Tooltip } from 'design-system/components/tooltip/tooltip'
2+
import styles from './beta-info.module.scss'
3+
4+
const COPY = {
5+
LABEL: 'Beta',
6+
INFO: 'All data is considered test data and may be changed or deleted at any time. Use with caution.',
7+
VERSION: `Build ${__COMMIT_HASH__}`,
8+
}
9+
10+
export const BetaInfo = () => {
11+
return (
12+
<div className={styles.wrapper}>
13+
<Tooltip content={COPY.INFO}>
14+
<div className={styles.badge}>{COPY.LABEL}</div>
15+
</Tooltip>
16+
<span className={styles.version}>{COPY.VERSION}</span>
17+
</div>
18+
)
19+
}

ui/src/components/header/header.module.scss

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
height: 64px;
99
display: flex;
1010
align-items: center;
11-
justify-content: space-between;
11+
justify-content: flex-start;
12+
gap: 32px;
1213
padding: 0 100px;
1314
background-color: $color-generic-white;
1415
border-bottom: 1px solid $color-neutral-100;
@@ -22,12 +23,18 @@
2223
vertical-align: middle;
2324
}
2425

25-
.infoPages {
26+
.rightContent {
2627
display: flex;
2728
align-items: center;
29+
justify-content: flex-end;
30+
flex: 1;
2831
gap: 4px;
2932
}
3033

34+
.infoPages {
35+
display: contents;
36+
}
37+
3138
@media only screen and (max-width: $medium-screen-breakpoint) {
3239
.header {
3340
padding: 0 32px;
@@ -37,5 +44,10 @@
3744
@media only screen and (max-width: $small-screen-breakpoint) {
3845
.header {
3946
padding: 0 16px;
47+
gap: 16px;
48+
}
49+
50+
.infoPages {
51+
display: none;
4052
}
4153
}

ui/src/components/header/header.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { STRING, translate } from 'utils/language'
88
import { usePageTitle } from 'utils/usePageTitle'
99
import { useUser } from 'utils/user/userContext'
1010
import ami from './ami.png'
11+
import { BetaInfo } from './beta-info/beta-info'
1112
import styles from './header.module.scss'
1213
import { UserInfoDialog } from './user-info-dialog/user-info-dialog'
1314

@@ -31,10 +32,13 @@ export const Header = () => {
3132
className={styles.logo}
3233
/>
3334
</Link>
34-
<div className={styles.infoPages}>
35-
{pages.map((page) => (
36-
<InfoDialog key={page.id} name={page.name} slug={page.slug} />
37-
))}
35+
<BetaInfo />
36+
<div className={styles.rightContent}>
37+
<div className={styles.infoPages}>
38+
{pages.map((page) => (
39+
<InfoDialog key={page.id} name={page.name} slug={page.slug} />
40+
))}
41+
</div>
3842
<Button
3943
label={translate(STRING.SIGN_UP)}
4044
theme={ButtonTheme.Plain}

ui/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
"baseUrl": "src",
1919
"types": ["vite/client", "vite-plugin-svgr/client"]
2020
},
21-
"include": ["src"]
21+
"include": ["src", "vite-env.d.ts"]
2222
}

ui/vite-env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/// <reference types="vite/client" />
2+
3+
declare const __COMMIT_HASH__: string

ui/vite.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import react from '@vitejs/plugin-react'
2+
import childProcees from 'child_process'
23
import { defineConfig } from 'vite'
34
import eslint from 'vite-plugin-eslint'
45
import svgr from 'vite-plugin-svgr'
56
import viteTsconfigPaths from 'vite-tsconfig-paths'
67

8+
const commitHash = childProcees
9+
.execSync('git rev-parse --short HEAD')
10+
.toString()
11+
712
export default defineConfig({
813
base: '/',
914
build: {
@@ -15,6 +20,9 @@ export default defineConfig({
1520
svgr({ include: '**/*.svg?react' }),
1621
eslint({ exclude: ['/virtual:/**', 'node_modules/**'] }),
1722
],
23+
define: {
24+
__COMMIT_HASH__: JSON.stringify(commitHash),
25+
},
1826
server: {
1927
open: true,
2028
port: 3000,

0 commit comments

Comments
 (0)