2017-02-28 21:32:23 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-03-08 05:52:17 +00:00
|
|
|
import Link from '../base/link';
|
|
|
|
import Modal from '../base/modal';
|
|
|
|
import ModalBody from '../base/modal-body';
|
|
|
|
import ModalHeader from '../base/modal-header';
|
|
|
|
import ModalFooter from '../base/modal-footer';
|
2017-08-12 16:58:22 +00:00
|
|
|
import {getAppVersion, CHANGELOG_URL, CHANGELOG_PAGE, isDevelopment} from '../../../common/constants';
|
|
|
|
import * as querystring from '../../../common/querystring';
|
2016-07-20 00:34:47 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
class ChangelogModal extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2017-03-03 20:09:08 +00:00
|
|
|
changelog: null
|
2017-03-03 01:44:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_setModalRef (m) {
|
|
|
|
this.modal = m;
|
|
|
|
}
|
2017-02-28 21:32:23 +00:00
|
|
|
|
2016-11-23 19:59:26 +00:00
|
|
|
show () {
|
2016-08-15 17:04:36 +00:00
|
|
|
this.modal.show();
|
2016-11-23 19:59:26 +00:00
|
|
|
}
|
2016-07-20 00:34:47 +00:00
|
|
|
|
2017-03-29 02:21:49 +00:00
|
|
|
hide () {
|
|
|
|
this.modal.hide();
|
|
|
|
}
|
|
|
|
|
2016-11-23 19:59:26 +00:00
|
|
|
toggle () {
|
|
|
|
this.modal.toggle();
|
2016-07-21 16:33:35 +00:00
|
|
|
}
|
|
|
|
|
2016-10-29 22:15:13 +00:00
|
|
|
async componentDidMount () {
|
|
|
|
let changelog;
|
|
|
|
try {
|
2017-08-02 20:38:31 +00:00
|
|
|
// TODO: Implement release channels
|
2017-08-02 20:38:40 +00:00
|
|
|
// NOTE: We add current version to break CDN cache
|
2017-08-12 16:58:22 +00:00
|
|
|
const params = [
|
|
|
|
{name: 'v', value: getAppVersion()},
|
|
|
|
{name: 'channel', value: 'stable'}
|
|
|
|
];
|
|
|
|
|
|
|
|
// Add extra param during dev so we don't affect CDN cache
|
|
|
|
if (isDevelopment()) {
|
|
|
|
params.push({name: 'dev'});
|
|
|
|
}
|
|
|
|
|
|
|
|
const qs = querystring.buildFromParams(params);
|
|
|
|
const url = querystring.joinUrl(CHANGELOG_URL, qs);
|
|
|
|
const response = await window.fetch(url);
|
2016-10-29 22:15:13 +00:00
|
|
|
changelog = await response.json();
|
|
|
|
} catch (e) {
|
|
|
|
console.warn('Failed to fetch changelog', e);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-20 00:34:47 +00:00
|
|
|
|
2016-10-29 22:15:13 +00:00
|
|
|
this.setState({changelog});
|
2016-07-20 00:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2016-11-23 19:59:26 +00:00
|
|
|
const {changelog} = this.state;
|
2016-07-20 00:34:47 +00:00
|
|
|
|
|
|
|
let html;
|
|
|
|
|
|
|
|
if (!changelog) {
|
|
|
|
html = [
|
2016-07-20 18:35:08 +00:00
|
|
|
<div key="spinner" className="txt-lg">
|
2017-07-25 22:28:53 +00:00
|
|
|
<i className="fa fa-refresh fa-spin"/>
|
2016-07-20 00:34:47 +00:00
|
|
|
</div>
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
html = [];
|
|
|
|
|
2016-11-23 19:59:26 +00:00
|
|
|
const startVersion = getAppVersion();
|
2016-07-21 16:33:35 +00:00
|
|
|
let startIndex = changelog.findIndex(c => c.version === startVersion);
|
|
|
|
if (startIndex < 0) {
|
|
|
|
startIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
changelog.slice(startIndex).map((change, i) => {
|
2016-07-20 00:34:47 +00:00
|
|
|
html = [
|
|
|
|
...html,
|
2016-07-21 16:33:35 +00:00
|
|
|
<h1 key={`changes.${i}`}>v{change.version} Changes</h1>
|
2016-07-20 00:34:47 +00:00
|
|
|
];
|
2016-12-01 00:02:35 +00:00
|
|
|
|
2016-07-20 00:34:47 +00:00
|
|
|
if (change.summary) {
|
|
|
|
if (!Array.isArray(change.summary)) {
|
|
|
|
html = [
|
|
|
|
...html,
|
2016-10-29 22:15:13 +00:00
|
|
|
<p key={`summary.${i}`}>{change.summary}</p>
|
2017-03-03 20:09:08 +00:00
|
|
|
];
|
2016-07-20 00:34:47 +00:00
|
|
|
} else {
|
|
|
|
html = [
|
|
|
|
...html,
|
2016-10-29 22:15:13 +00:00
|
|
|
<p key={`summary.${i}`}><strong>{change.summary[0]}</strong></p>,
|
2016-08-15 17:04:36 +00:00
|
|
|
...change.summary.slice(1).map(
|
2016-10-29 22:15:13 +00:00
|
|
|
(text, j) => <p key={`summary.${i}[${j}]`}>{text}</p>
|
2016-08-15 17:04:36 +00:00
|
|
|
)
|
2017-03-03 20:09:08 +00:00
|
|
|
];
|
2016-07-20 00:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 00:02:35 +00:00
|
|
|
if (change.link) {
|
|
|
|
html = [
|
|
|
|
...html,
|
2017-03-01 21:15:56 +00:00
|
|
|
<Link href={change.link} className="btn btn--clicky" button key={`link.${i}`}>
|
2016-12-01 00:02:35 +00:00
|
|
|
Read More
|
|
|
|
</Link>
|
2017-03-03 20:09:08 +00:00
|
|
|
];
|
2016-12-01 00:02:35 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 17:46:19 +00:00
|
|
|
const printThing = (text, key) => {
|
|
|
|
const match = text.match(/\(PR:(\d+)(:([^)]+))?\)/);
|
|
|
|
let link = null;
|
|
|
|
if (match) {
|
|
|
|
const prNumber = match[1];
|
|
|
|
const user = match[3] || '';
|
|
|
|
text = text.replace(match[0], '');
|
|
|
|
link = (
|
|
|
|
<Link href={`https://github.com/getinsomnia/insomnia/pull/${prNumber}`}>
|
|
|
|
#{prNumber}
|
|
|
|
{user ? ` by ${user}` : null}
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <li key={key}>{text}{link && '('}{link}{link && ')'}</li>;
|
|
|
|
};
|
|
|
|
|
2016-07-20 00:34:47 +00:00
|
|
|
if (change.major && change.major.length) {
|
|
|
|
html = [
|
|
|
|
...html,
|
2016-11-30 23:11:36 +00:00
|
|
|
<h3 key={`major.${i}`}>Major</h3>,
|
2016-07-21 16:33:35 +00:00
|
|
|
<ul key={`major.${i}.list`}>
|
2017-06-30 17:46:19 +00:00
|
|
|
{change.major.map(printThing)}
|
2016-07-20 18:35:08 +00:00
|
|
|
</ul>
|
2016-07-20 00:34:47 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change.fixes && change.fixes.length) {
|
|
|
|
html = [
|
|
|
|
...html,
|
2016-11-30 23:11:36 +00:00
|
|
|
<h3 key={`fixes.${i}`}>Bug Fixes</h3>,
|
2016-07-21 16:33:35 +00:00
|
|
|
<ul key={`fixes.${i}.list`}>
|
2017-06-30 17:46:19 +00:00
|
|
|
{change.fixes.map(printThing)}
|
2016-07-21 16:33:35 +00:00
|
|
|
</ul>
|
2016-07-20 00:34:47 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change.minor && change.minor.length) {
|
|
|
|
html = [
|
|
|
|
...html,
|
2016-11-30 23:11:36 +00:00
|
|
|
<h3 key={`minor.${i}`}>Minor</h3>,
|
2016-07-21 16:33:35 +00:00
|
|
|
<ul key={`minor.${i}.list`}>
|
2017-06-30 17:46:19 +00:00
|
|
|
{change.minor.map(printThing)}
|
2016-07-21 16:33:35 +00:00
|
|
|
</ul>
|
2016-07-20 00:34:47 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
html = [
|
|
|
|
...html,
|
2016-07-21 16:33:35 +00:00
|
|
|
<hr key={`hr.${i}`}/>
|
2017-03-03 20:09:08 +00:00
|
|
|
];
|
2016-07-20 00:34:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-04-04 23:06:43 +00:00
|
|
|
<Modal tall ref={this._setModalRef} {...this.props}>
|
2016-07-20 00:34:47 +00:00
|
|
|
<ModalHeader>Insomnia Changelog</ModalHeader>
|
|
|
|
<ModalBody className="pad changelog">
|
|
|
|
{html}
|
|
|
|
</ModalBody>
|
2016-10-21 17:20:36 +00:00
|
|
|
<ModalFooter>
|
2017-03-01 21:15:56 +00:00
|
|
|
<Link className="btn" href={CHANGELOG_PAGE} button>
|
2016-10-29 22:15:13 +00:00
|
|
|
Visit Full Changelog
|
|
|
|
</Link>
|
2016-07-20 00:34:47 +00:00
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ChangelogModal.propTypes = {};
|
|
|
|
|
|
|
|
export default ChangelogModal;
|