Skip to content

Commit

Permalink
Show beta info in header (#340)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
annavik authored Feb 1, 2024
1 parent 38ddcf2 commit 1b065ff
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 7 deletions.
24 changes: 24 additions & 0 deletions ui/src/components/header/beta-info/beta-info.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import 'src/design-system/variables/variables.scss';
@import 'src/design-system/variables/colors.scss';
@import 'src/design-system/variables/typography.scss';

.wrapper {
display: flex;
align-items: center;
justify-content: center;
gap: 16px;
}

.badge {
padding: 4px 16px;
border-radius: 4px;
background-color: $color-success-100;
color: $color-success-700;
text-align: center;
@include label();
}

.version {
@include paragraph-x-small();
white-space: nowrap;
}
19 changes: 19 additions & 0 deletions ui/src/components/header/beta-info/beta-info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Tooltip } from 'design-system/components/tooltip/tooltip'
import styles from './beta-info.module.scss'

const COPY = {
LABEL: 'Beta',
INFO: 'All data is considered test data and may be changed or deleted at any time. Use with caution.',
VERSION: `Build ${__COMMIT_HASH__}`,
}

export const BetaInfo = () => {
return (
<div className={styles.wrapper}>
<Tooltip content={COPY.INFO}>
<div className={styles.badge}>{COPY.LABEL}</div>
</Tooltip>
<span className={styles.version}>{COPY.VERSION}</span>
</div>
)
}
16 changes: 14 additions & 2 deletions ui/src/components/header/header.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
justify-content: flex-start;
gap: 32px;
padding: 0 100px;
background-color: $color-generic-white;
border-bottom: 1px solid $color-neutral-100;
Expand All @@ -22,12 +23,18 @@
vertical-align: middle;
}

.infoPages {
.rightContent {
display: flex;
align-items: center;
justify-content: flex-end;
flex: 1;
gap: 4px;
}

.infoPages {
display: contents;
}

@media only screen and (max-width: $medium-screen-breakpoint) {
.header {
padding: 0 32px;
Expand All @@ -37,5 +44,10 @@
@media only screen and (max-width: $small-screen-breakpoint) {
.header {
padding: 0 16px;
gap: 16px;
}

.infoPages {
display: none;
}
}
12 changes: 8 additions & 4 deletions ui/src/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { STRING, translate } from 'utils/language'
import { usePageTitle } from 'utils/usePageTitle'
import { useUser } from 'utils/user/userContext'
import ami from './ami.png'
import { BetaInfo } from './beta-info/beta-info'
import styles from './header.module.scss'
import { UserInfoDialog } from './user-info-dialog/user-info-dialog'

Expand All @@ -31,10 +32,13 @@ export const Header = () => {
className={styles.logo}
/>
</Link>
<div className={styles.infoPages}>
{pages.map((page) => (
<InfoDialog key={page.id} name={page.name} slug={page.slug} />
))}
<BetaInfo />
<div className={styles.rightContent}>
<div className={styles.infoPages}>
{pages.map((page) => (
<InfoDialog key={page.id} name={page.name} slug={page.slug} />
))}
</div>
<Button
label={translate(STRING.SIGN_UP)}
theme={ButtonTheme.Plain}
Expand Down
2 changes: 1 addition & 1 deletion ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"baseUrl": "src",
"types": ["vite/client", "vite-plugin-svgr/client"]
},
"include": ["src"]
"include": ["src", "vite-env.d.ts"]
}
2 changes: 2 additions & 0 deletions ui/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/// <reference types="vite/client" />

declare const __COMMIT_HASH__: string
8 changes: 8 additions & 0 deletions ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import react from '@vitejs/plugin-react'
import childProcees from 'child_process'
import { defineConfig } from 'vite'
import eslint from 'vite-plugin-eslint'
import svgr from 'vite-plugin-svgr'
import viteTsconfigPaths from 'vite-tsconfig-paths'

const commitHash = childProcees
.execSync('git rev-parse --short HEAD')
.toString()

export default defineConfig({
base: '/',
build: {
Expand All @@ -15,6 +20,9 @@ export default defineConfig({
svgr({ include: '**/*.svg?react' }),
eslint({ exclude: ['/virtual:/**', 'node_modules/**'] }),
],
define: {
__COMMIT_HASH__: JSON.stringify(commitHash),
},
server: {
open: true,
port: 3000,
Expand Down

0 comments on commit 1b065ff

Please sign in to comment.