@@ -7,34 +7,70 @@ import restClient from './hydraClient';
77class HydraAdmin extends Component {
88 static defaultProps = {
99 apiDocumentationParser,
10+ customRoutes : [ ] ,
11+ error : 'Unable to retrieve API documentation.' ,
12+ loading : 'Loading...' ,
1013 restClient,
1114 } ;
1215
1316 static propTypes = {
1417 apiDocumentationParser : PropTypes . func ,
18+ customRoutes : PropTypes . array ,
1519 entrypoint : PropTypes . string . isRequired ,
20+ error : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . string ] ) ,
21+ loading : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . string ] ) ,
1622 restClient : PropTypes . func ,
1723 } ;
1824
1925 state = {
2026 api : null ,
27+ customRoutes : [ ] ,
28+ hasError : false ,
29+ loaded : false ,
2130 } ;
2231
2332 componentDidMount ( ) {
2433 this . props
2534 . apiDocumentationParser ( this . props . entrypoint )
26- . then ( api => this . setState ( { api} ) ) ;
35+ . then (
36+ ( { api, customRoutes = [ ] } ) => ( {
37+ api,
38+ customRoutes,
39+ hasError : false ,
40+ loaded : true ,
41+ } ) ,
42+ ( { api, customRoutes = [ ] } ) => ( {
43+ api,
44+ customRoutes,
45+ hasError : true ,
46+ loaded : true ,
47+ } ) ,
48+ )
49+ . then ( this . setState . bind ( this ) ) ;
2750 }
2851
2952 render ( ) {
30- if ( null === this . state . api ) {
31- return < span > Loading...</ span > ;
53+ if ( false === this . state . loaded ) {
54+ return 'function' === typeof this . props . loading
55+ ? < this . props . loading />
56+ : < span className = "loading" >
57+ { this . props . loading }
58+ </ span > ;
59+ }
60+
61+ if ( true === this . state . hasError ) {
62+ return 'function' === typeof this . props . error
63+ ? < this . props . error />
64+ : < span className = "error" >
65+ { this . props . error }
66+ </ span > ;
3267 }
3368
3469 return (
3570 < AdminBuilder
3671 { ...this . props }
3772 api = { this . state . api }
73+ customRoutes = { this . props . customRoutes . concat ( this . state . customRoutes ) }
3874 restClient = { this . props . restClient ( this . state . api ) }
3975 />
4076 ) ;
0 commit comments