Skip to content

Commit

Permalink
Merge pull request #41 from InfuseAI/feature/sc-23364/crane-new-versi…
Browse files Browse the repository at this point in the history
…on-released-update-app-notify

[Feature] sc-23364 Pop up modal when crane have new released version
  • Loading branch information
aar0nTw authored Dec 9, 2021
2 parents 25840ff + 3791cf2 commit 5374d72
Show file tree
Hide file tree
Showing 5 changed files with 787 additions and 5 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"@craco/craco": "^6.3.0",
"@sentry/browser": "^6.15.0",
"@sentry/electron": "^2.5.4",
"@sentry/types": "^6.15.0",
"@sentry/tracing": "^6.15.0",
"@sentry/types": "^6.15.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
Expand All @@ -26,6 +26,7 @@
"antd": "^4.16.13",
"aws-sdk": "^2.1030.0",
"axios": "^0.22.0",
"compare-versions": "^4.1.1",
"craco-less": "^1.20.0",
"dockerode": "^3.3.1",
"electron-is-dev": "^1.2.0",
Expand All @@ -40,9 +41,11 @@
"react-dom": "^17.0.2",
"react-icons": "^4.2.0",
"react-lazylog": "^4.5.3",
"react-markdown": "^7.1.1",
"react-router-dom": "^5.3.0",
"react-scripts": "4.0.3",
"react-syntax-highlighter": "^15.4.5",
"rehype-raw": "^6.1.0",
"timeago.js": "^4.0.2",
"typescript": "^4.1.2",
"uuid": "^8.3.1",
Expand Down
24 changes: 24 additions & 0 deletions src/App.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ body {
span {
cursor: default;
}
.ant-btn span {
cursor: pointer;
}
}

.App-link {
Expand Down Expand Up @@ -194,3 +197,24 @@ body {
margin-right: 8px;
vertical-align: top;
}

.modal-version-update {
.release-note {
max-height: 50vh;
overflow: hidden;
position: relative;
.read-more {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
margin: 0;
padding: 60px 0;
background-image: linear-gradient(to bottom, transparent, white);
}
}
.ant-divider {
margin: 0;
}
}

84 changes: 83 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Switch,
} from 'react-router-dom';
import './App.less';
import { Alert, Button, Space, Layout, Skeleton } from 'antd';
import { Alert, Button, Space, Layout, Skeleton, Modal, Divider } from 'antd';
import Sidebar from './Sidebar';
import BuildImage from './BuildImage';
import ListImage from './ListImage';
Expand All @@ -16,6 +16,10 @@ import { send } from './utils/ipcClient';
import CreatePrimeHubImage from './CreatePrimeHubImage';
import * as Sentry from '@sentry/browser';
import { Integrations } from '@sentry/tracing';
import compareVersions from 'compare-versions';
import ReactMarkdown from 'react-markdown';
import rehypeRaw from 'rehype-raw';
import useLocalStorage from './hooks/useLocalStorage';

Sentry.init({
dsn: 'https://[email protected]/6088888',
Expand All @@ -29,6 +33,14 @@ const OK = 'ok';

const Crane = () => {
const [missingDocker, setMissingDocker] = useState(false);
const [isNewVersionReleased, setIsNewVersionReleased] = useState(false);
const [releasedData, setReleasedData] = useState({
name: '',
version: '',
url: '',
changelog: '',
});
const [skipVersion, setSkipVersion] = useLocalStorage('skip_version', '');
const siderWidth = {
collapsed: 80,
unCollapsed: 160,
Expand All @@ -42,6 +54,17 @@ const Crane = () => {
if (pong !== OK) {
setMissingDocker(true);
}
const crane = await send('get-crane-version');
if (
crane.latest &&
compareVersions(crane.latest.version, crane.version) > 0 &&
crane.latest.version !== skipVersion
) {
// Show New version released
setIsNewVersionReleased(true);
setReleasedData(crane.latest);
console.log(crane.latest);
}
})();
}, []);

Expand Down Expand Up @@ -76,6 +99,65 @@ const Crane = () => {
) : (
<></>
)}
<Modal
title={`New Version Released: ${releasedData.name}`}
width={'50%'}
mask={true}
className='modal-version-update'
visible={isNewVersionReleased}
onOk={() => {
setIsNewVersionReleased(false);
console.log('OK');
}}
onCancel={() => {
setIsNewVersionReleased(false);
console.log('Cancel');
}}
footer={[
<Button
key='download'
type='primary'
href={releasedData.url}
target='_blank'
onClick={() => {
setIsNewVersionReleased(false);
console.log('Download');
}}
>
Download on GitHub
</Button>,
<Button
key='skip'
onClick={() => {
setIsNewVersionReleased(false);
setSkipVersion(releasedData.version);
console.log('Skip');
}}
>
Skip this Version
</Button>,
]}
>
<div className='release-note'>
<ReactMarkdown
children={releasedData.changelog}
rehypePlugins={[rehypeRaw]}
components={{
img: ({ children, ...props }) => {
console.log(props);
return <img src={props.src} alt={props.alt} width='100%' />;
},
}}
/>
<div className='read-more'>
</div>
</div>
<Divider>
<a href={releasedData.url} target='_blank' rel='noreferrer'>
Read More
</a>
</Divider>
</Modal>
<Suspense
fallback={
<div className='site-layout-background'>
Expand Down
29 changes: 29 additions & 0 deletions src/electron/ServerHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createMarkdownArrayTableSync } from 'parse-markdown-table';
import AwsAdapter from './AwsAdapter';
import DockerHubAdapter from './DockerHubAdapter';
import * as Sentry from '@sentry/electron';
import tag from 'antd/lib/tag';

Sentry.init({
dsn: 'https://[email protected]/6088888',
Expand Down Expand Up @@ -145,6 +146,24 @@ export async function getAwsCredential() {
return awsCredential;
}

export async function getCraneLatestVersion() {
const githubApiUrl =
'https://api.github.com/repos/infuseai/crane/releases/latest';
const response = await axios.get(githubApiUrl);

const version: string = response.data['tag_name'];

const release = {
version: version.replace('v', ''),
name: response.data['name'],
url: response.data['html_url'],
changelog: response.data['body'],
// published_at: response.data['published_at'],
};

return release;
}

const handlers = {
build_events: [],
build_status: '',
Expand All @@ -156,6 +175,16 @@ const handlers = {
}
return 'ok';
},
'get-crane-version': async () => {
try {
return {
version: config.version,
latest: await getCraneLatestVersion(),
};
} catch (error) {
return { version: config.version, error: error.message };
}
},
'get-dockerhub-credential': async () => {
return await getCredential(dockerHubCredentialKeyName);
},
Expand Down
Loading

0 comments on commit 5374d72

Please sign in to comment.