Skip to content
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

Add version warning banner to web console #3679

Merged
merged 3 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions web/src/components/warning-banner/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { FC, memo } from "react";
import { AppBar, makeStyles } from "@material-ui/core";
import CloseIcon from "@material-ui/icons/Close";

const useStyles = makeStyles((theme) => ({
container: {
zIndex: theme.zIndex.drawer + 1,
height: "30px",
backgroundColor: "#403f4c",
},
content: {
paddingTop: "2px",
textAlign: "center",
fontSize: "1rem",
},
highlight: {
backgroundColor: "yellow",
},
close: {
position: "absolute",
top: "2px",
right: "2px",
},
}));

export interface WarningBannerProps {
onClose: () => void;
}

export const WarningBanner: FC<WarningBannerProps> = memo(
function BannerWarning({ onClose }) {
const classes = useStyles();
const releaseNoteURL = `https://github.com/pipe-cd/pipecd/releases/tag/${process.env.PIPECD_VERSION}`;

return (
<AppBar position="static" className={classes.container}>
<div className={classes.content}>
Version {process.env.PIPECD_VERSION} is available! Find all{" "}
<a
href={releaseNoteURL}
target="_blank"
rel="noreferrer"
className={classes.highlight}
>
details on this release note here.
</a>
</div>
<CloseIcon className={classes.close} onClick={onClose} />
</AppBar>
);
}
);
19 changes: 17 additions & 2 deletions web/src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import loadable from "@loadable/component";
import { EntityId } from "@reduxjs/toolkit";
import { FC, useEffect } from "react";
import { FC, useEffect, useState } from "react";
import {
Redirect,
Route,
Expand All @@ -9,8 +9,9 @@ import {
RouteComponentProps,
} from "react-router-dom";
import { ApplicationIndexPage } from "~/components/applications-page";
import { WarningBanner } from "~/components/warning-banner";
import { DeploymentIndexPage } from "~/components/deployments-page";
import { DeploymentChainsIndexPage } from "./components/deployment-chains-page";
import { DeploymentChainsIndexPage } from "~/components/deployment-chains-page";
import { Header } from "~/components/header";
import { LoginPage } from "~/components/login-page";
import { Toasts } from "~/components/toasts";
Expand Down Expand Up @@ -95,6 +96,8 @@ const useCommandsStatusChecking = (): void => {
};

const REDIRECT_PATH_KEY = "redirect_path";
const BANNER_VERSION_KEY = "banner_version";

export const Routes: FC = () => {
const dispatch = useAppDispatch();
const me = useAppSelector((state) => state.me);
Expand All @@ -114,6 +117,10 @@ export const Routes: FC = () => {
}
}, [location, me, onLoadProject]);

const [showWarningBanner, setShowWarningBaner] = useState(
localStorage.getItem(BANNER_VERSION_KEY) !== `${process.env.PIPECD_VERSION}`
);

if (me === null) {
return (
<>
Expand Down Expand Up @@ -147,8 +154,16 @@ export const Routes: FC = () => {
);
}

const handleCloseWarningBanner = (): void => {
localStorage.setItem(BANNER_VERSION_KEY, `${process.env.PIPECD_VERSION}`);
setShowWarningBaner(false);
};

return (
<>
{showWarningBanner && (
<WarningBanner onClose={handleCloseWarningBanner} />
)}
<Header />
<Switch>
<Route
Expand Down