ManifestPage.js (2312B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 8 const { 9 createFactory, 10 PureComponent, 11 } = require("resource://devtools/client/shared/vendor/react.mjs"); 12 const { 13 section, 14 } = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 15 16 const { 17 connect, 18 } = require("resource://devtools/client/shared/vendor/react-redux.js"); 19 20 const Types = require("resource://devtools/client/application/src/types/index.js"); 21 22 const ManifestLoader = createFactory( 23 require("resource://devtools/client/application/src/components/manifest/ManifestLoader.js") 24 ); 25 const Manifest = createFactory( 26 require("resource://devtools/client/application/src/components/manifest/Manifest.js") 27 ); 28 const ManifestEmpty = createFactory( 29 require("resource://devtools/client/application/src/components/manifest/ManifestEmpty.js") 30 ); 31 32 class ManifestPage extends PureComponent { 33 static get propTypes() { 34 return { 35 // these props are automatically injected via connect 36 hasLoadingFailed: PropTypes.bool.isRequired, 37 isManifestLoading: PropTypes.bool.isRequired, 38 manifest: PropTypes.shape(Types.manifest), 39 }; 40 } 41 42 get shouldShowLoader() { 43 const { isManifestLoading, hasLoadingFailed } = this.props; 44 const mustLoadManifest = typeof this.props.manifest === "undefined"; 45 return isManifestLoading || mustLoadManifest || hasLoadingFailed; 46 } 47 48 renderManifest() { 49 const { manifest } = this.props; 50 return manifest ? Manifest({ ...manifest }) : ManifestEmpty({}); 51 } 52 53 render() { 54 const { manifest } = this.props; 55 56 return section( 57 { 58 className: `app-page js-manifest-page ${ 59 !manifest ? "app-page--empty" : "" 60 }`, 61 }, 62 this.shouldShowLoader ? ManifestLoader({}) : this.renderManifest() 63 ); 64 } 65 } 66 67 function mapStateToProps(state) { 68 return { 69 hasLoadingFailed: !!state.manifest.errorMessage, 70 isManifestLoading: state.manifest.isLoading, 71 manifest: state.manifest.manifest, 72 }; 73 } 74 75 // Exports 76 module.exports = connect(mapStateToProps)(ManifestPage);