};
render() {
- const isOnCurrentVersion =
- this.props.version === 'latest' ||
- this.state.versions.find(v => v.value === this.props.version) !== undefined;
+ const { versions } = this.state;
+ const currentVersion = versions.find(v => v.current);
+ const selectedVersionValue =
+ currentVersion && this.props.version === 'latest' ? currentVersion.value : this.props.version;
+ const isOnCurrentVersion = !currentVersion || selectedVersionValue === currentVersion.value;
return (
<div className="page-sidebar">
<div className="sidebar-header">
/>
</Link>
<VersionSelect
- location={this.props.location}
- version={this.props.version}
- versions={this.state.versions}
+ isOnCurrentVersion={isOnCurrentVersion}
+ selectedVersionValue={selectedVersionValue}
+ versions={versions}
/>
-
{this.state.loaded &&
!isOnCurrentVersion && (
<div className="alert alert-warning">
onResultsChange={this.handleSearch}
pages={this.props.pages}
/>
- {this.state.query !== '' && this.renderResults()}
- {this.state.query === '' && this.renderCategories(NavigationTree)}
+ {this.state.query !== '' ? this.renderResults() : this.renderCategories(NavigationTree)}
</div>
<div className="sidebar-footer">
<a href="https://www.sonarqube.org/" rel="noopener noreferrer" target="_blank">
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import fetch from 'isomorphic-fetch';
import ChevronDownIcon from './icons/ChevronDownIcon';
import ChevronUpIcon from './icons/ChevronUpIcon';
import OutsideClickHandler from './OutsideClickHandler';
};
render() {
- const { versions } = this.props;
+ const { isOnCurrentVersion, selectedVersionValue, versions } = this.props;
const hasVersions = versions.length > 1;
- const currentVersion = versions.find(v => v.current);
- const versionLabel =
- this.props.version === 'latest' && currentVersion ? currentVersion.value : this.props.version;
- const isOnCurrentVersion =
- !hasVersions || (currentVersion && versionLabel === currentVersion.value);
return (
<div className="version-select">
<button onClick={this.handleClick} type="button">
- Docs <span className={isOnCurrentVersion ? 'current' : ''}>{versionLabel}</span>
+ Docs <span className={isOnCurrentVersion ? 'current' : ''}>{selectedVersionValue}</span>
{hasVersions && !this.state.open && <ChevronDownIcon size={10} />}
{hasVersions && this.state.open && <ChevronUpIcon size={10} />}
</button>