WorkersPage.js (2159B)
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 { 8 createFactory, 9 PureComponent, 10 } = require("resource://devtools/client/shared/vendor/react.mjs"); 11 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 12 const { 13 section, 14 } = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 15 const { 16 connect, 17 } = require("resource://devtools/client/shared/vendor/react-redux.js"); 18 19 const Types = require("resource://devtools/client/application/src/types/index.js"); 20 const RegistrationList = createFactory( 21 require("resource://devtools/client/application/src/components/service-workers/RegistrationList.js") 22 ); 23 const RegistrationListEmpty = createFactory( 24 require("resource://devtools/client/application/src/components/service-workers/RegistrationListEmpty.js") 25 ); 26 27 class WorkersPage extends PureComponent { 28 static get propTypes() { 29 return { 30 // mapped from state 31 canDebugWorkers: PropTypes.bool.isRequired, 32 domain: PropTypes.string.isRequired, 33 registrations: Types.registrationArray.isRequired, 34 }; 35 } 36 37 render() { 38 const { canDebugWorkers, domain, registrations } = this.props; 39 40 // Filter out workers from other domains 41 const domainWorkers = registrations.filter( 42 x => !!x.workers.length && new URL(x.workers[0].url).hostname === domain 43 ); 44 const isListEmpty = domainWorkers.length === 0; 45 46 return section( 47 { 48 className: `app-page js-service-workers-page ${ 49 isListEmpty ? "app-page--empty" : "" 50 }`, 51 }, 52 isListEmpty 53 ? RegistrationListEmpty({}) 54 : RegistrationList({ 55 canDebugWorkers, 56 registrations: domainWorkers, 57 }) 58 ); 59 } 60 } 61 62 function mapStateToProps(state) { 63 return { 64 canDebugWorkers: state.workers.canDebugWorkers, 65 domain: state.page.domain, 66 registrations: state.workers.list, 67 }; 68 } 69 70 // Exports 71 module.exports = connect(mapStateToProps)(WorkersPage);