Skip to content

Commit 8488531

Browse files
committed
Keep selected version option in sync with URL
1 parent 7ad25a4 commit 8488531

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

tools/docs/www/src/app.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { Route, Switch, withRouter } from 'react-router-dom';
2323
import { Link } from 'react-router-dom';
2424
import SideMenu from './side_menu.jsx';
2525
import WelcomePage from './welcome_page.jsx';
26-
import VERSIONS from './versions.json';
2726
import './css/app.css';
2827
import './css/reset.css';
2928
import './css/highlight.css';
@@ -54,9 +53,11 @@ class App extends Component {
5453
constructor( props ) {
5554
super( props );
5655

56+
const pathname = props.history.location.pathname;
57+
const version = pathname.substring( 1, pathname.indexOf( '/docs' ) );
5758
this.state = {
5859
slideoutIsOpen: true,
59-
version: VERSIONS[ 0 ],
60+
version: version,
6061
packageTree: null,
6162
packageResources: {}
6263
};
@@ -150,6 +151,9 @@ class App extends Component {
150151
}
151152

152153
selectVersion = ( event ) => {
154+
let pathname = this.props.history.location.pathname;
155+
pathname = pathname.replace( this.state.version, event.target.value );
156+
this.props.history.push( pathname );
153157
this.setState({
154158
version: event.target.value
155159
}, this.fetchJSONFiles );

tools/docs/www/src/side_menu.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import RemoveIcon from '@material-ui/icons/Remove';
3131
import IconButton from '@material-ui/core/IconButton';
3232
import ClearIcon from '@material-ui/icons/Clear';
3333
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
34+
import VERSIONS from './versions.json';
3435
import Logo from './logo.jsx';
3536

3637

@@ -276,8 +277,12 @@ class MenuBar extends Component {
276277
<ChevronRightIcon id="menu-close-icon" />
277278
</IconButton>
278279
</div>
279-
<select className="side-menu-version-select" id="lang" onChange={this.props.onVersionChange} value={this.state.version}>
280-
<option value="v0.0.87">v0.0.87</option>
280+
<select
281+
className="side-menu-version-select"
282+
onChange={this.props.onVersionChange}
283+
value={this.props.version}
284+
>
285+
{VERSIONS.map( ( val, key ) => <option key={key} value={val}>{val}</option> )}
281286
</select>
282287
<div className="side-menu-filter" >
283288
<input

0 commit comments

Comments
 (0)