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

Notification when an update is available #238

Open
wants to merge 5 commits into
base: v0.22.0-old
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions src/components/sidenav/Sidenav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSelector } from "react-redux";
import store from "../../store"
import { set } from "automate-redux"
import { DownOutlined, InfoCircleOutlined } from '@ant-design/icons';
import { Collapse, Divider, Typography, Space } from "antd";
import { Collapse, Divider, Typography, Space, Button, Popover } from "antd";
import { capitalizeFirstCharacter } from '../../utils';
import { getEnv } from '../../operations/cluster';
import { projectModules } from '../../constants';
Expand Down Expand Up @@ -50,6 +50,7 @@ const Sidenav = (props) => {
const showSidenav = useSelector(state => state.uiState.showSidenav)
const sideNavActiveKeys = useSelector(state => state.uiState.sideNavActiveKeys)
const { plan, version } = useSelector(state => getEnv(state))
const scLatestVersion = useSelector(state => state.scLatestVersion)
const planName = getPlanName(plan)
const closeSidenav = () => {
store.dispatch(set("uiState.showSidenav", false))
Expand All @@ -59,6 +60,8 @@ const Sidenav = (props) => {
store.dispatch(set("uiState.sideNavActiveKeys", activeKeys))
}

const isUpdateAvailable = scLatestVersion && scLatestVersion !== version

return (
<div className="sidenav-container">
<div className={showSidenav ? 'overlay' : 'no-overlay'} onClick={() => store.dispatch(set("uiState.showSidenav", false))}></div>
Expand Down Expand Up @@ -116,16 +119,23 @@ const Sidenav = (props) => {
<SidenavItem name="Settings" icon="settings" active={props.selectedItem === projectModules.SETTINGS} />
</Link>
</div>
<div className="sidenav-bottom-content">
{isUpdateAvailable &&
<div className="sc-update">
Upgrade to v{scLatestVersion} <Button type="primary" ghost style={{ marginLeft: 9 }}>Update</Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens onClick?

</div>}
<div className="sidenav-version">
<InfoCircleOutlined style={{ fontSize: "20px", fontWeight: "700" }} />
<Popover placement="right" content={`UI Version - v${uiVersion}`}>
<InfoCircleOutlined style={{ fontSize: "20px", fontWeight: "700", cursor: "pointer" }} />
</Popover>
<div className="sidenav-version-content">
<Space direction="vertical" size={4}>
<Typography.Text>SC Version - v{version}</Typography.Text>
<Typography.Text>UI Version - v{uiVersion}</Typography.Text>
<Typography.Text type="secondary">{planName}</Typography.Text>
</Space>
</div>
</div>
</div>
</div>
</div>
);
Expand Down
10 changes: 9 additions & 1 deletion src/components/sidenav/sidenav.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@
padding: 16px;
border-top: 1px solid #eee;
width: 100%;
margin-top: auto;
display: flex;
}

.sidenav-bottom-content {
margin-top: auto;
}

.sc-update {
background-color: #D2E0FF;
padding: 16px;
}

.sidenav-version .sidenav-version-content {
display: inline-block;
margin-left: 16px;
Expand Down
20 changes: 18 additions & 2 deletions src/operations/cluster.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { set, get } from "automate-redux";
import client from "../client";
import store from "../store";
import { getAPIToken } from "./projects";

export function loadClusterSettings() {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -39,11 +40,12 @@ export function saveClusterSetting(key, value) {
})
}

export function loadClusterEnv() {
export function loadClusterEnv(projectId) {
return new Promise((resolve, reject) => {
client.cluster.fetchEnv()
.then(env => {
setEnv(env)
getScLatestVersion(projectId, env.version)
resolve()
})
.catch(error => reject(error))
Expand Down Expand Up @@ -119,6 +121,18 @@ export function removeClusterLicense() {
})
}

function getScLatestVersion(projectId, currentVersion) {
return new Promise((resolve, reject) => {
const internalToken = getAPIToken(store.getState())
client.cluster.fetchScLatestVersion(projectId, currentVersion, () => internalToken)
.then((latestVersion) => {
setScLatestVersion(latestVersion)
resolve()
})
.catch(error => reject(error))
})
}

export function getEnv(state) {
return get(state, "env", {})
}
Expand Down Expand Up @@ -171,4 +185,6 @@ export function isLoggedIn(state) {
}

return true
}
}

const setScLatestVersion = (latestVersion) => store.dispatch(set("scLatestVersion", latestVersion))
31 changes: 31 additions & 0 deletions src/services/cluster.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { spaceCloudClusterOrigin } from "../constants"
import { createGraphQLClient } from "./client"
import gql from 'graphql-tag';

class Cluster {
constructor(client) {
this.client = client
Expand Down Expand Up @@ -132,6 +136,33 @@ class Cluster {
}).catch(ex => reject({title: "Failed to login", msg: ex.message}))
})
}

fetchScLatestVersion(projectId, currentVersion, getToken) {
let uri = `/v1/api/${projectId}/graphql`
if (spaceCloudClusterOrigin) {
uri = spaceCloudClusterOrigin + uri;
}
const graphqlClient = createGraphQLClient(uri, getToken)
return new Promise((resolve, reject) => {
graphqlClient.query({
query: gql`
query {
sc_version(where: {version_no: $currentVersion},limit:1, sort:["-version_code"]) @db {
compatible_version
}
}
`,
variables: { currentVersion }
}).then(res => {
const { data, errors } = res
if (errors && errors.length > 0) {
reject(errors[0].message)
return
}
resolve(data.sc_version ? data.sc_version[0].compatible_version : "")
}).catch(ex => reject(ex.toString()))
})
}
}

export default Cluster
5 changes: 2 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ export function redirectToLogin() {
// Its intended to be called whenever the mission control is (re)loaded.
export function performSetup() {
return new Promise((resolve, reject) => {

const { projectId } = extractPathInfo(history.location.pathname)
// Load cluster environment and refresh token (if present) parallely
const promises = [loadClusterEnv(), refreshClusterTokenIfPresent()]
const promises = [loadClusterEnv(projectId), refreshClusterTokenIfPresent()]

Promise.all(promises)
.then(() => {
Expand Down Expand Up @@ -450,7 +450,6 @@ export function performSetup() {
})

// Refresh admin token periodically (every 15 minutes)
const { projectId } = extractPathInfo(history.location.pathname)
loadProjectAPIToken(projectId)
}, 15 * 60 * 1000)

Expand Down