11import React , { Component } from "react" ;
22import ExamplePairing from "../ExamplePairing/ExamplePairing" ;
3- import { Typography , List , ListItem , ListItemText , Grid , MenuItem , Menu , withStyles } from "@material-ui/core" ;
3+ import { Typography , List , ListItem , ListItemText , Grid , MenuItem , Menu , withStyles , ExpansionPanelDetails } from "@material-ui/core" ;
44import { MethodObject , ExamplePairingObject , ContentDescriptorObject , ReferenceObject } from "@open-rpc/meta-schema" ;
55
66interface IProps {
@@ -26,10 +26,11 @@ const newExample: ExamplePairingObject = {
2626} ;
2727const getExamplesFromMethod = ( method ?: MethodObject ) : ExamplePairingObject [ ] => {
2828 if ( ! method ) { return [ ] ; }
29+ if ( ! method . params ) { return [ ] ; }
2930 const examples : ExamplePairingObject [ ] = [ ] ;
3031
3132 ( method . params as ContentDescriptorObject [ ] ) . forEach ( ( param , index : number ) => {
32- if ( param . schema . examples && param . schema . examples . length > 0 ) {
33+ if ( param . schema && param . schema . examples && param . schema . examples . length > 0 ) {
3334 param . schema . examples . forEach ( ( ex : any , i : number ) => {
3435 if ( ! examples [ i ] ) {
3536 examples . push ( { ...newExample } ) ;
@@ -92,48 +93,50 @@ class ExamplePairings extends Component<IProps, IState> {
9293 return null ;
9394 }
9495 return (
95- < Grid container >
96- < Grid item xs = { 12 } >
97- < Typography variant = "h5" > Examples</ Typography >
96+ < ExpansionPanelDetails key = "examples" >
97+ < Grid container >
98+ < Grid item xs = { 12 } >
99+ < Typography variant = "h5" > Examples</ Typography >
100+ </ Grid >
101+ < Grid item xs = { 12 } >
102+ < List component = "nav" >
103+ < ListItem
104+ button
105+ aria-haspopup = "true"
106+ aria-controls = "menu-menu"
107+ aria-label = "Method Examples"
108+ onClick = { this . handleClickListItem } >
109+ < ListItemText
110+ primary = { examples [ this . state . selectedIndex ] . name }
111+ secondary = { examples [ this . state . selectedIndex ] . summary } />
112+ </ ListItem >
113+ < Menu
114+ id = "menu-menu"
115+ anchorEl = { anchorEl as HTMLElement }
116+ open = { Boolean ( anchorEl ) }
117+ onClose = { this . handleClose }
118+ >
119+ { examples . map ( ( example , index ) => (
120+ < MenuItem
121+ key = { example . name }
122+ selected = { index === this . state . selectedIndex }
123+ onClick = { ( event ) => this . handleMenuItemClick ( event , index ) }
124+ >
125+ { example . name }
126+ </ MenuItem >
127+ ) ) }
128+ </ Menu >
129+ </ List >
130+ </ Grid >
131+ < Grid item xs = { 12 } >
132+ { examples &&
133+ < ExamplePairing
134+ examplePairing = { examples [ this . state . selectedIndex ] }
135+ methodName = { this . props . method && this . props . method . name }
136+ reactJsonOptions = { this . props . reactJsonOptions } /> }
137+ </ Grid >
98138 </ Grid >
99- < Grid item xs = { 12 } >
100- < List component = "nav" >
101- < ListItem
102- button
103- aria-haspopup = "true"
104- aria-controls = "menu-menu"
105- aria-label = "Method Examples"
106- onClick = { this . handleClickListItem } >
107- < ListItemText
108- primary = { examples [ this . state . selectedIndex ] . name }
109- secondary = { examples [ this . state . selectedIndex ] . summary } />
110- </ ListItem >
111- < Menu
112- id = "menu-menu"
113- anchorEl = { anchorEl as HTMLElement }
114- open = { Boolean ( anchorEl ) }
115- onClose = { this . handleClose }
116- >
117- { examples . map ( ( example , index ) => (
118- < MenuItem
119- key = { example . name }
120- selected = { index === this . state . selectedIndex }
121- onClick = { ( event ) => this . handleMenuItemClick ( event , index ) }
122- >
123- { example . name }
124- </ MenuItem >
125- ) ) }
126- </ Menu >
127- </ List >
128- </ Grid >
129- < Grid item xs = { 12 } >
130- { examples &&
131- < ExamplePairing
132- examplePairing = { examples [ this . state . selectedIndex ] }
133- methodName = { this . props . method && this . props . method . name }
134- reactJsonOptions = { this . props . reactJsonOptions } /> }
135- </ Grid >
136- </ Grid >
139+ </ ExpansionPanelDetails >
137140 ) ;
138141 }
139142}
0 commit comments