diff --git a/package.json b/package.json index 93f1e6c0..5232ef88 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "admin-on-rest": "^1.1", - "api-doc-parser": "^0.1.7", + "api-doc-parser": "^0.2.0", "babel-runtime": "^6.23", "jsonld": "^0.4", "lodash.isplainobject": "^4.0.6", diff --git a/src/hydra/HydraAdmin.js b/src/hydra/HydraAdmin.js index cf964a7a..45d82659 100644 --- a/src/hydra/HydraAdmin.js +++ b/src/hydra/HydraAdmin.js @@ -7,34 +7,70 @@ import restClient from './hydraClient'; class HydraAdmin extends Component { static defaultProps = { apiDocumentationParser, + customRoutes: [], + error: 'Unable to retrieve API documentation.', + loading: 'Loading...', restClient, }; static propTypes = { apiDocumentationParser: PropTypes.func, + customRoutes: PropTypes.array, entrypoint: PropTypes.string.isRequired, + error: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), + loading: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), restClient: PropTypes.func, }; state = { api: null, + customRoutes: [], + hasError: false, + loaded: false, }; componentDidMount() { this.props .apiDocumentationParser(this.props.entrypoint) - .then(api => this.setState({api})); + .then( + ({api, customRoutes = []}) => ({ + api, + customRoutes, + hasError: false, + loaded: true, + }), + ({api, customRoutes = []}) => ({ + api, + customRoutes, + hasError: true, + loaded: true, + }), + ) + .then(this.setState.bind(this)); } render() { - if (null === this.state.api) { - return Loading...; + if (false === this.state.loaded) { + return 'function' === typeof this.props.loading + ? + : + {this.props.loading} + ; + } + + if (true === this.state.hasError) { + return 'function' === typeof this.props.error + ? + : + {this.props.error} + ; } return ( ); diff --git a/yarn.lock b/yarn.lock index 5d1a1287..efeb07e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -115,9 +115,9 @@ anymatch@^1.3.0: arrify "^1.0.0" micromatch "^2.1.5" -api-doc-parser@^0.1.7: - version "0.1.7" - resolved "https://registry.yarnpkg.com/api-doc-parser/-/api-doc-parser-0.1.7.tgz#b55697a92b425b2118e7dcd14f9d444b7e10f673" +api-doc-parser@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/api-doc-parser/-/api-doc-parser-0.2.0.tgz#7751ec1b7b377cd91be7698b360b7829bb234c33" dependencies: babel-runtime "^6.23.0" jsonld "^0.4.11"