TemporaryExtensionInstallSection.js (2740B)
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 dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 12 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 13 14 const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js"); 15 const Localized = createFactory(FluentReact.Localized); 16 17 const DetailsLog = createFactory( 18 require("resource://devtools/client/aboutdebugging/src/components/shared/DetailsLog.js") 19 ); 20 const Message = createFactory( 21 require("resource://devtools/client/aboutdebugging/src/components/shared/Message.js") 22 ); 23 const TemporaryExtensionInstaller = createFactory( 24 require("resource://devtools/client/aboutdebugging/src/components/debugtarget/TemporaryExtensionInstaller.js") 25 ); 26 27 const { 28 MESSAGE_LEVEL, 29 } = require("resource://devtools/client/aboutdebugging/src/constants.js"); 30 31 /** 32 * This component provides an installer and error message area for temporary extension. 33 */ 34 class TemporaryExtensionInstallSection extends PureComponent { 35 static get propTypes() { 36 return { 37 dispatch: PropTypes.func.isRequired, 38 temporaryInstallError: PropTypes.object, 39 }; 40 } 41 42 renderError() { 43 const { temporaryInstallError } = this.props; 44 45 if (!temporaryInstallError) { 46 return null; 47 } 48 49 const errorMessages = [ 50 temporaryInstallError.message, 51 ...(temporaryInstallError.additionalErrors || []), 52 ]; 53 54 const errors = errorMessages.map((message, index) => { 55 return dom.p( 56 { 57 className: "technical-text", 58 key: "tmp-extension-install-error-" + index, 59 }, 60 message 61 ); 62 }); 63 64 return Message( 65 { 66 level: MESSAGE_LEVEL.ERROR, 67 className: "qa-tmp-extension-install-error", 68 isCloseable: true, 69 }, 70 Localized( 71 { 72 id: "about-debugging-tmp-extension-install-error", 73 }, 74 dom.p({}, "about-debugging-tmp-extension-install-error") 75 ), 76 DetailsLog( 77 { 78 type: MESSAGE_LEVEL.ERROR, 79 }, 80 errors 81 ) 82 ); 83 } 84 85 render() { 86 const { dispatch } = this.props; 87 88 return dom.section( 89 {}, 90 dom.div( 91 { 92 className: "temporary-extension-install-section__toolbar", 93 }, 94 TemporaryExtensionInstaller({ dispatch }) 95 ), 96 this.renderError() 97 ); 98 } 99 } 100 101 module.exports = TemporaryExtensionInstallSection;