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 upgrade motivation banner #7768

Merged
merged 31 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ca65b31
WIP [ci skip] start implementing upgrade banner
knollengewaechs Apr 17, 2024
2319a68
style banner and add more conditions
knollengewaechs Apr 17, 2024
6b93366
style banner
knollengewaechs Apr 17, 2024
67be3a5
[ci skip] WIP: styling banner
knollengewaechs Apr 22, 2024
713cb2a
adjust styling more
knollengewaechs Apr 24, 2024
dc5f6a7
WIP: use themeprovider to adjust nested theme
knollengewaechs Apr 24, 2024
b7039fa
fix avatar margin if banner is shown above navbar
knollengewaechs Apr 24, 2024
ec267a4
remove comment
knollengewaechs Apr 24, 2024
65e83b4
remove dev edits
knollengewaechs Apr 24, 2024
9f95bcb
improve styling and add testing options
knollengewaechs Apr 25, 2024
c679a07
Merge branch 'master' into upgrade-motivation-banner
knollengewaechs Apr 25, 2024
cc26cb2
Merge branch 'master' into upgrade-motivation-banner
knollengewaechs Apr 29, 2024
f630f94
fix commit date format
knollengewaechs Apr 29, 2024
68418e3
add helper to parse date
knollengewaechs Apr 29, 2024
5ea5ed7
add changelog
knollengewaechs Apr 29, 2024
1e0c83c
[ci skip] WIP: address review
knollengewaechs Apr 30, 2024
9592cf1
WIP[ci skip] address review 2
knollengewaechs May 1, 2024
7e2508a
add WK link and improve style
knollengewaechs May 6, 2024
d19f69d
merge master
knollengewaechs May 6, 2024
e4665ae
remove testing residue
knollengewaechs May 6, 2024
87ee706
remove test remainder 2
knollengewaechs May 7, 2024
b920078
rename navbarHeight var and banners module
knollengewaechs May 8, 2024
74c39c5
Merge branch 'master' into upgrade-motivation-banner
knollengewaechs May 8, 2024
81b5e1b
improve scenario where both upgrade and maintenance banner are shown;…
knollengewaechs May 14, 2024
7d81e8f
merge master
knollengewaechs May 14, 2024
194d4d1
change order in AI job modal to make mito inferral second
knollengewaechs May 14, 2024
a0a0413
add tooltip again
knollengewaechs May 15, 2024
55fc506
merge master
knollengewaechs May 15, 2024
ad0d4f6
revert application.conf edits
knollengewaechs May 15, 2024
2787816
Merge branch 'master' into upgrade-motivation-banner
knollengewaechs May 15, 2024
9f3a18d
Merge branch 'master' into upgrade-motivation-banner
knollengewaechs May 16, 2024
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
93 changes: 89 additions & 4 deletions frontend/javascripts/maintenance_banner.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
getBuildInfo,
listCurrentAndUpcomingMaintenances,
updateNovelUserExperienceInfos,
} from "admin/admin_rest_api";
import { Alert } from "antd";
import { Alert, Button, Space } from "antd";
import FormattedDate from "components/formatted_date";
import { useInterval } from "libs/react_helpers";
import dayjs from "dayjs";
import { useFetch, useInterval } from "libs/react_helpers";
import _ from "lodash";
import constants from "oxalis/constants";
import { setNavbarHeightAction } from "oxalis/model/actions/ui_actions";
Expand All @@ -17,12 +19,13 @@ import { MaintenanceInfo } from "types/api_flow_types";

const INITIAL_DELAY = 5000;
const INTERVAL_TO_FETCH_MAINTENANCES_MS = 60000; // 1min
const UPGRADE_BANNER_LOCAL_STORAGE_KEY = "upgradeBannerWasClickedAway";

const BANNER_STYLE: React.CSSProperties = {
position: "absolute",
top: 0,
left: 0,
height: constants.MAINTENANCE_BANNER_HEIGHT,
height: constants.BANNER_HEIGHT,
};

function setNavbarHeight(newNavbarHeight: number) {
Expand Down Expand Up @@ -116,7 +119,7 @@ export function MaintenanceBanner() {

useEffect(() => {
if (currentMaintenance || closestUpcomingMaintenance) {
setNavbarHeight(constants.DEFAULT_NAVBAR_HEIGHT + constants.MAINTENANCE_BANNER_HEIGHT);
setNavbarHeight(constants.DEFAULT_NAVBAR_HEIGHT + constants.BANNER_HEIGHT);
}

if (currentMaintenance == null && closestUpcomingMaintenance == null) {
Expand Down Expand Up @@ -144,3 +147,85 @@ export function MaintenanceBanner() {

return null;
}

export function UpgradeVersionBanner() {
const white = "var(--ant-color-text-primary)";
const blue = "var(--ant-color-primary)";
const UPGRADE_BANNER_STYLE: React.CSSProperties = {
position: "absolute",
top: 0,
left: 0,
height: constants.BANNER_HEIGHT,
textAlign: "center",
backgroundColor: blue,
color: white,
fontSize: "medium",
};
const customParseFormat = require("dayjs/plugin/customParseFormat");
dayjs.extend(customParseFormat);
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
const currentDate = dayjs();

const isVersionOutdated = useFetch(
async () => {
const buildInfo = await getBuildInfo();
const commitDateWithoutWeekday = buildInfo.webknossos.commitDate.replace(
/(Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun)\w*/,
"",
);
const lastCommitDate = dayjs(commitDateWithoutWeekday, "MMM DD HH:mm:ss YYYY ZZ"); // todo two digit dates? test more once time tracking is merged
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
const needsUpdate = currentDate.diff(lastCommitDate, "month") >= 6;
return needsUpdate;
},
false,
[],
);

const getShouldBannerBeShown = () => {
if (!isVersionOutdated) return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(obviously this can be set to true during testing, dont forget to remove)

const lastTimeBannerWasClickedAway = localStorage.getItem(UPGRADE_BANNER_LOCAL_STORAGE_KEY);
if (lastTimeBannerWasClickedAway == null) return true;
const parsedDate = dayjs(lastTimeBannerWasClickedAway);
return parsedDate.diff(currentDate, "days") >= 3;
};

const shouldBannerBeShown = getShouldBannerBeShown();

useEffect(() => {
if (shouldBannerBeShown) {
setNavbarHeight(constants.DEFAULT_NAVBAR_HEIGHT + constants.BANNER_HEIGHT);
} else {
setNavbarHeight(constants.DEFAULT_NAVBAR_HEIGHT);
}
}, [shouldBannerBeShown]);

return shouldBannerBeShown ? (
<Alert
className="upgrade-banner"
message={
<Space size="middle">
<Space size="small">
You are using an old version of WEBKNOSSOS. Switch to
<b style={{ marginInline: -2 }}>webknossos.org</b> for automatic updates and exclusive
features!
</Space>
<Button
className="upgrade-banner-button"
href="https://webknossos.org/self-hosted-upgrade"
size="small"
>
Learn more
</Button>
</Space>
}
banner
style={UPGRADE_BANNER_STYLE}
closable
onClose={() => {
localStorage.setItem(UPGRADE_BANNER_LOCAL_STORAGE_KEY, dayjs().toISOString());
setNavbarHeight(constants.DEFAULT_NAVBAR_HEIGHT);
}}
type="info"
showIcon={false}
/>
) : null;
}
30 changes: 15 additions & 15 deletions frontend/javascripts/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Tag,
Input,
InputRef,
ConfigProvider,
} from "antd";
import _ from "lodash";
import {
Expand All @@ -25,7 +26,7 @@ import {
import { useHistory, Link } from "react-router-dom";

import classnames from "classnames";
import { connect } from "react-redux";
import { connect, useSelector } from "react-redux";
import React, { useState, useEffect, useRef } from "react";
import Toast from "libs/toast";
import type {
Expand Down Expand Up @@ -61,8 +62,8 @@ import { PricingEnforcedSpan } from "components/pricing_enforcers";
import { ItemType, MenuItemType, SubMenuType } from "antd/lib/menu/hooks/useItems";
import { MenuClickEventHandler } from "rc-menu/lib/interface";
import constants from "oxalis/constants";
import { MaintenanceBanner } from "maintenance_banner";
import { getSystemColorTheme } from "theme";
import { MaintenanceBanner, UpgradeVersionBanner } from "maintenance_banner";
import { getAntdTheme, getSystemColorTheme } from "theme";

const { Header } = Layout;

Expand Down Expand Up @@ -482,8 +483,7 @@ function NotificationIcon({
position: "relative",
display: "flex",
marginRight: 12,
paddingTop:
navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT ? constants.MAINTENANCE_BANNER_HEIGHT : 0,
paddingTop: navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT ? constants.BANNER_HEIGHT : 0,
}}
>
<Tooltip title="See what's new in WEBKNOSSOS" placement="bottomLeft">
Expand Down Expand Up @@ -610,8 +610,7 @@ function LoggedInAvatar({
selectedKeys={["prevent highlighting of this menu"]}
mode="horizontal"
style={{
paddingTop:
navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT ? constants.MAINTENANCE_BANNER_HEIGHT : 0,
paddingTop: navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT ? constants.BANNER_HEIGHT : 0,
lineHeight: `${constants.DEFAULT_NAVBAR_HEIGHT}px`,
}}
theme="dark"
Expand Down Expand Up @@ -701,6 +700,9 @@ function LoggedInAvatar({
}

function AnonymousAvatar() {
const navbarHeight = useSelector(
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
(state: OxalisState) => state.uiInformation.navbarHeight - constants.DEFAULT_NAVBAR_HEIGHT,
);
return (
<Popover
placement="bottomRight"
Expand All @@ -722,6 +724,7 @@ function AnonymousAvatar() {
icon={<UserOutlined />}
style={{
marginLeft: 8,
marginTop: navbarHeight,
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
</Popover>
Expand Down Expand Up @@ -899,15 +902,15 @@ function Navbar({
})}
>
<MaintenanceBanner />
<ConfigProvider theme={{ ...getAntdTheme("light") }}>
<UpgradeVersionBanner />
</ConfigProvider>
<Menu
mode="horizontal"
selectedKeys={selectedKeys}
onOpenChange={(openKeys) => setIsHelpMenuOpen(openKeys.includes(HELP_MENU_KEY))}
style={{
paddingTop:
navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT
? constants.MAINTENANCE_BANNER_HEIGHT
: 0,
paddingTop: navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT ? constants.BANNER_HEIGHT : 0,
lineHeight: `${constants.DEFAULT_NAVBAR_HEIGHT}px`,
}}
theme="dark"
Expand All @@ -930,10 +933,7 @@ function Navbar({
style={{
flex: 1,
display: "flex",
paddingTop:
navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT
? constants.MAINTENANCE_BANNER_HEIGHT
: 0,
paddingTop: navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT ? constants.BANNER_HEIGHT : 0,
}}
/>

Expand Down
2 changes: 1 addition & 1 deletion frontend/javascripts/oxalis/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ const Constants = {
BUCKET_SIZE: 32 ** 3,
VIEWPORT_WIDTH,
DEFAULT_NAVBAR_HEIGHT: 48,
MAINTENANCE_BANNER_HEIGHT: 38,
BANNER_HEIGHT: 38,
// For reference, the area of a large brush size (let's say, 300px) corresponds to
// pi * 300 ^ 2 == 282690.
// We multiply this with 5, since the labeling is not done
Expand Down
19 changes: 18 additions & 1 deletion frontend/stylesheets/trace_view/_tracing_view.less
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ img.keyboard-mouse-icon:first-child {
color: rgba(255, 255, 255, 0.67);
z-index: 1000;

.upgrade-banner{
.ant-alert-close-icon {
.anticon, .anticon-close {
color: var(--ant-color-primary-bg)
}
}
}

&.statusbar-footer {
left: 0px;
bottom: 0px;
Expand Down Expand Up @@ -357,11 +365,19 @@ img.keyboard-mouse-icon:first-child {
.ant-input,
.ant-input-number,
.ant-radio-button-wrapper,
.ant-select > .ant-select-selector {
.ant-select > .ant-select-selector{
background-color: @dark-bg !important;
color: @dark-fg !important;
border-color: @dark-border;

&.upgrade-banner-button{
background-color: var(--ant-button-primary-color) !important;
color: var(--ant-color-primary) !important;
border-color: var(--ant-button-primary-color);
display: flex;
align-items: center;
}

&:hover {
border-color: var(--color-blue-zircon) !important;
z-index: 1 !important;
Expand All @@ -383,6 +399,7 @@ img.keyboard-mouse-icon:first-child {
background-color: @dark-border !important;
}
}

}

.ant-btn[disabled],
Expand Down