Skip to content

Commit

Permalink
Frontend: add warning banner when server version is different than cl…
Browse files Browse the repository at this point in the history
…ient version (#950)
  • Loading branch information
psrok1 authored Jul 8, 2024
1 parent 961e702 commit e2ea6cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mwdb/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ import { ConfigContext } from "./commons/config";
import { Extendable } from "./commons/plugins";
import { ErrorBoundary } from "./commons/ui";
import { AppRoutes } from "./commons/navigation/AppRoutes";
import { VersionMismatchWarning } from "@mwdb-web/components/VersionMismatchWarning";

import { version as clientVersion } from "../package.json";

export function App() {
const config = useContext(ConfigContext);
return (
<div className="App">
<Navigation />
<div className="content">
{config.isReady ? (
<VersionMismatchWarning
clientVersion={clientVersion}
serverVersion={config.config.server_version}
/>
) : (
[]
)}
<ErrorBoundary>
<Extendable ident="main">
{config.isReady ? <AppRoutes /> : []}
Expand Down
28 changes: 28 additions & 0 deletions mwdb/web/src/components/VersionMismatchWarning.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
type VersionMismatchWarningProps = {
serverVersion?: string;
clientVersion: string;
};

function stripVersionTag(version: string): string {
// Strips possible version tag with Git revision
// e.g. 2.0.0-rc1+6b2f1c1a is converted to 2.0.0-rc1
return version.split("+")[0];
}

export function VersionMismatchWarning({
serverVersion,
clientVersion,
}: VersionMismatchWarningProps) {
if (
!serverVersion ||
stripVersionTag(clientVersion) === stripVersionTag(serverVersion)
)
return <></>;
return (
<div className="alert alert-warning" role="alert">
Server version was recently updated to {serverVersion} while
currently loaded web application is {clientVersion}. Press CTRL+F5
to clear cache and reload the webpage.
</div>
);
}

0 comments on commit e2ea6cb

Please sign in to comment.