2020
2121import React , { Component , Fragment } from 'react' ;
2222import { debounce } from 'throttle-debounce' ;
23- import isObject from '@stdlib/assert/is-object' ;
24- import contains from '@stdlib/assert/contains' ;
25- import objectKeys from '@stdlib/utils/keys' ;
2623import List from '@material-ui/core/List' ;
2724import ListItem from '@material-ui/core/ListItem' ;
2825import Collapse from '@material-ui/core/Collapse' ;
@@ -32,7 +29,6 @@ import AddIcon from '@material-ui/icons/Add';
3229import RemoveIcon from '@material-ui/icons/Remove' ;
3330import IconButton from '@material-ui/core/IconButton' ;
3431import ChevronRightIcon from '@material-ui/icons/ChevronRight' ;
35- import packageTree from './../public/assets/v0.0.87/package_tree.json' ;
3632import Logo from './logo.jsx' ;
3733
3834
@@ -43,7 +39,6 @@ class MenuBar extends Component {
4339 super ( props )
4440 this . state = {
4541 activePkg : null ,
46- version : 'v0.0.87' ,
4742 filter : null ,
4843 found : { }
4944 } ;
@@ -74,16 +69,16 @@ class MenuBar extends Component {
7469 }
7570
7671 renderItems ( namespace , path , level ) {
77- const keys = objectKeys ( namespace ) ;
72+ const keys = Object . keys ( namespace ) ;
7873 return keys . map ( ( pkg ) => {
7974 const pkgPath = `${ path } /${ pkg } ` ;
8075 if ( pkg === '__namespace__' ) {
8176 return null ;
8277 }
83- if ( ! isObject ( namespace [ pkg ] ) ) {
78+ if ( typeof namespace [ pkg ] !== 'object' ) {
8479 // Case: Individual package
8580 if (
86- this . state . filter && ! contains ( pkgPath , this . state . filter )
81+ this . state . filter && ! pkgPath . includes ( this . state . filter )
8782 ) {
8883 return null ;
8984 }
@@ -95,7 +90,7 @@ class MenuBar extends Component {
9590 className = "side-menu-list-item"
9691 onClick = { ( ) => {
9792 this . handlePackageClick ( pkg ) ;
98- const path = `/${ this . state . version } /docs/api/${ pkgPath } ` ;
93+ const path = `/${ this . props . version } /docs/api/${ pkgPath } ` ;
9994 this . props . onReadmeChange ( path ) ;
10095 } }
10196 style = { {
@@ -121,7 +116,7 @@ class MenuBar extends Component {
121116 button
122117 onClick = { ( ) => {
123118 this . handleClick ( pkgPath ) ;
124- const path = `/${ this . state . version } /docs/api/${ pkgPath } ` ;
119+ const path = `/${ this . props . version } /docs/api/${ pkgPath } ` ;
125120 this . props . onReadmeChange ( path ) ;
126121 } }
127122 className = "side-menu-list-item-namespace"
@@ -150,12 +145,6 @@ class MenuBar extends Component {
150145 } )
151146 }
152147
153- selectVersion = ( event ) => {
154- this . setState ( {
155- version : event . target . value
156- } ) ;
157- }
158-
159148 handleFilterChange = ( event ) => {
160149 const newFilter = event . target . value ;
161150 this . setState ( {
@@ -171,8 +160,8 @@ class MenuBar extends Component {
171160 applyFilterChange = ( ) => {
172161 if ( this . state . filter ) {
173162 const found = { } ;
174- this . checkFilter ( found , packageTree , '@stdlib' , this . state . filter ) ;
175- const keys = objectKeys ( found ) ;
163+ this . checkFilter ( found , this . props . packageTree , '@stdlib' , this . state . filter ) ;
164+ const keys = Object . keys ( found ) ;
176165 const newState = { } ;
177166 for ( let i = 0 ; i < keys . length ; i ++ ) {
178167 newState [ keys [ i ] ] = true ;
@@ -182,7 +171,7 @@ class MenuBar extends Component {
182171 found
183172 } ) ;
184173 } else {
185- const keys = objectKeys ( this . state . found ) ;
174+ const keys = Object . keys ( this . state . found ) ;
186175 const newState = { } ;
187176 for ( let i = 0 ; i < keys . length ; i ++ ) {
188177 newState [ keys [ i ] ] = false ;
@@ -195,15 +184,15 @@ class MenuBar extends Component {
195184 }
196185
197186 checkFilter ( state , docs , path , filter ) {
198- const keys = objectKeys ( docs ) ;
187+ const keys = Object . keys ( docs ) ;
199188 let matched = false ;
200189 for ( let i = 0 ; i < keys . length ; i ++ ) {
201190 const pkg = keys [ i ] ;
202- if ( ! isObject ( docs [ pkg ] ) ) {
203- if ( contains ( pkg , filter ) ) {
191+ if ( typeof docs [ pkg ] !== 'object' ) {
192+ if ( pkg . includes ( filter ) ) {
204193 matched = true ;
205194 }
206- } else if ( contains ( pkg , filter ) ) {
195+ } else if ( pkg . includes ( filter ) ) {
207196 matched = true ;
208197 state [ path + '/' + pkg ] = true ;
209198 } else {
@@ -247,7 +236,7 @@ class MenuBar extends Component {
247236 < ChevronRightIcon id = "menu-close-icon" />
248237 </ IconButton >
249238 </ div >
250- < select className = "side-menu-version-select" id = "lang" onChange = { this . selectVersion } value = { this . state . version } >
239+ < select className = "side-menu-version-select" id = "lang" onChange = { this . props . onVersionChange } value = { this . state . version } >
251240 < option value = "v0.0.87" > v0.0.87</ option >
252241 </ select >
253242 < input
@@ -258,7 +247,10 @@ class MenuBar extends Component {
258247 />
259248 < div className = "side-menu-list-wrapper" >
260249 < List disablePadding >
261- { this . renderItems ( packageTree , '@stdlib' , 0 ) }
250+ { this . props . packageTree ?
251+ this . renderItems ( this . props . packageTree , '@stdlib' , 0 ) :
252+ null
253+ }
262254 </ List >
263255 </ div >
264256 </ Drawer >
0 commit comments