Skip to content

Commit e1373c7

Browse files
committed
Use AlertBanner for coder version notice
1 parent 0bd68a4 commit e1373c7

File tree

5 files changed

+57
-22
lines changed

5 files changed

+57
-22
lines changed

site/src/components/AlertBanner/AlertBanner.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { AlertBannerCtas } from "./AlertBannerCtas"
1818
* @param dismissible: determines whether or not the banner should have a `Dismiss` CTA
1919
* @param retry: a handler to retry the action that spawned the error
2020
*/
21-
export const AlertBanner: FC<AlertBannerProps> = ({
21+
export const AlertBanner: FC<React.PropsWithChildren<AlertBannerProps>> = ({
22+
children,
2223
severity,
2324
text,
2425
error,
@@ -55,6 +56,7 @@ export const AlertBanner: FC<AlertBannerProps> = ({
5556
<Stack direction="row" alignItems="center" spacing={1}>
5657
{severityConstants[severity].icon}
5758
<Stack spacing={0}>
59+
{children}
5860
{alertMessage}
5961
{detail && (
6062
<Expander expanded={showDetails} setExpanded={setShowDetails}>

site/src/components/AuthAndFrame/AuthAndFrame.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { XServiceContext } from "../../xServices/StateContext"
66
import { Footer } from "../Footer/Footer"
77
import { Navbar } from "../Navbar/Navbar"
88
import { RequireAuth } from "../RequireAuth/RequireAuth"
9+
import { UpdateCheckBanner } from "components/UpdateCheckBanner/UpdateCheckBanner"
910

1011
interface AuthAndFrameProps {
1112
children: JSX.Element
@@ -18,11 +19,13 @@ export const AuthAndFrame: FC<AuthAndFrameProps> = ({ children }) => {
1819
const styles = useStyles()
1920
const xServices = useContext(XServiceContext)
2021
const [buildInfoState] = useActor(xServices.buildInfoXService)
22+
const [updateCheckState] = useActor(xServices.updateCheckXService)
2123

2224
return (
2325
<RequireAuth>
2426
<div className={styles.site}>
2527
<Navbar />
28+
<UpdateCheckBanner updateCheck={updateCheckState.context.updateCheck} />
2629
<div className={styles.siteContent}>
2730
<Suspense fallback={<Loader />}>{children}</Suspense>
2831
</div>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Link from "@material-ui/core/Link"
2+
import { makeStyles } from "@material-ui/core/styles"
3+
import { AlertBanner } from "components/AlertBanner/AlertBanner"
4+
import { Margins } from "components/Margins/Margins"
5+
import { Trans, useTranslation } from "react-i18next"
6+
import * as TypesGen from "../../api/typesGenerated"
7+
8+
export interface UpdateCheckBannerProps {
9+
updateCheck?: TypesGen.UpdateCheckResponse
10+
}
11+
12+
export const UpdateCheckBanner: React.FC<
13+
React.PropsWithChildren<UpdateCheckBannerProps>
14+
> = ({ updateCheck }) => {
15+
const styles = useStyles({})
16+
const { t } = useTranslation("common")
17+
18+
return (
19+
<div className={styles.root}>
20+
{updateCheck && !updateCheck.current && (
21+
<Margins>
22+
<AlertBanner severity="info" text="" dismissible>
23+
<div>
24+
<Trans t={t} i18nKey="updateCheck.message">
25+
Coder {updateCheck.version} is now available. View the{" "}
26+
<Link href={updateCheck.url}>release notes</Link> and{" "}
27+
<Link href="https://coder.com/docs/coder-oss/latest/admin/upgrade">
28+
upgrade instructions
29+
</Link>{" "}
30+
for more information.
31+
</Trans>
32+
</div>
33+
</AlertBanner>
34+
</Margins>
35+
)}
36+
</div>
37+
)
38+
}
39+
40+
const useStyles = makeStyles((theme) => ({
41+
root: {
42+
// Common spacing between elements, adds separation from Navbar.
43+
paddingTop: theme.spacing(2),
44+
},
45+
}))

site/src/i18n/en/common.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
},
3636
"emojiPicker": {
3737
"select": "Select emoji"
38+
},
39+
"updateCheck": {
40+
"message": "Coder {updateCheck.version} is now available. View the <4>release notes</4> and <7>upgrade instructions</7> for more information."
3841
}
3942
}

site/src/xServices/updateCheck/updateCheckXService.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { assign, createMachine } from "xstate"
2-
import * as API from "../../api/api"
3-
import * as TypesGen from "../../api/typesGenerated"
4-
import { displayMsg } from "../../components/GlobalSnackbar/utils"
2+
import * as API from "api/api"
3+
import * as TypesGen from "api/typesGenerated"
54

65
export const Language = {
76
updateAvailable: "New version available",
@@ -42,11 +41,7 @@ export const updateCheckMachine = createMachine(
4241
id: "getUpdateCheck",
4342
onDone: [
4443
{
45-
actions: [
46-
"assignUpdateCheck",
47-
"clearGetUpdateCheckError",
48-
"notifyUpdateAvailable",
49-
],
44+
actions: ["assignUpdateCheck", "clearGetUpdateCheckError"],
5045
target: "#updateCheckState.success",
5146
},
5247
],
@@ -85,19 +80,6 @@ export const updateCheckMachine = createMachine(
8580
...context,
8681
getUpdateCheckError: undefined,
8782
})),
88-
notifyUpdateAvailable: (context: UpdateCheckContext) => {
89-
if (context.updateCheck && !context.updateCheck.current) {
90-
// TODO(mafredri): HTML formatting, persistance?
91-
displayMsg(
92-
Language.updateAvailable,
93-
Language.updateAvailableMessage(
94-
context.updateCheck.version,
95-
context.updateCheck.url,
96-
"https://coder.com/docs/coder-oss/latest/admin/upgrade",
97-
),
98-
)
99-
}
100-
},
10183
},
10284
},
10385
)

0 commit comments

Comments
 (0)