import React, {PureComponent} from 'react'; import autobind from 'autobind-decorator'; 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'; import {getAppVersion, CHANGELOG_URL, CHANGELOG_PAGE, isDevelopment} from '../../../common/constants'; import * as querystring from '../../../common/querystring'; @autobind class ChangelogModal extends PureComponent { constructor (props) { super(props); this.state = { changelog: null }; } _setModalRef (m) { this.modal = m; } show () { this.modal.show(); } hide () { this.modal.hide(); } toggle () { this.modal.toggle(); } async componentDidMount () { let changelog; try { // TODO: Implement release channels // NOTE: We add current version to break CDN cache 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); changelog = await response.json(); } catch (e) { console.warn('Failed to fetch changelog', e); return; } this.setState({changelog}); } render () { const {changelog} = this.state; let html; if (!changelog) { html = [
]; } else { html = []; const startVersion = getAppVersion(); let startIndex = changelog.findIndex(c => c.version === startVersion); if (startIndex < 0) { startIndex = 0; } changelog.slice(startIndex).map((change, i) => { html = [ ...html,

v{change.version} Changes

]; if (change.summary) { if (!Array.isArray(change.summary)) { html = [ ...html,

{change.summary}

]; } else { html = [ ...html,

{change.summary[0]}

, ...change.summary.slice(1).map( (text, j) =>

{text}

) ]; } } if (change.link) { html = [ ...html, Read More ]; } 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 = ( #{prNumber} {user ? ` by ${user}` : null} ); } return
  • {text}{link && '('}{link}{link && ')'}
  • ; }; if (change.major && change.major.length) { html = [ ...html,

    Major

    , ]; } if (change.fixes && change.fixes.length) { html = [ ...html,

    Bug Fixes

    , ]; } if (change.minor && change.minor.length) { html = [ ...html,

    Minor

    , ]; } html = [ ...html,
    ]; }); } return ( Insomnia Changelog {html} Visit Full Changelog ); } } ChangelogModal.propTypes = {}; export default ChangelogModal;