ManifestIssue.js (2035B)
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 img, 14 li, 15 span, 16 } = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 17 18 const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js"); 19 const Localized = createFactory(FluentReact.Localized); 20 21 const { 22 MANIFEST_ISSUE_LEVELS, 23 } = require("resource://devtools/client/application/src/constants.js"); 24 const Types = require("resource://devtools/client/application/src/types/index.js"); 25 26 /** 27 * A Manifest validation issue (warning, error) 28 */ 29 class ManifestIssue extends PureComponent { 30 static get propTypes() { 31 return { 32 className: PropTypes.string, 33 ...Types.manifestIssue, // { level, message } 34 }; 35 } 36 37 getIconData(level) { 38 switch (level) { 39 case MANIFEST_ISSUE_LEVELS.WARNING: 40 return { 41 src: "resource://devtools-shared-images/alert-small.svg", 42 localizationId: "icon-warning", 43 }; 44 case MANIFEST_ISSUE_LEVELS.ERROR: 45 default: 46 return { 47 src: "resource://devtools-shared-images/error-small.svg", 48 localizationId: "icon-error", 49 }; 50 } 51 } 52 53 render() { 54 const { level, message, className } = this.props; 55 const icon = this.getIconData(level); 56 57 return li( 58 { className: `js-manifest-issue ${className ? className : ""}` }, 59 Localized( 60 { id: icon.localizationId, attrs: { alt: true, title: true } }, 61 img({ 62 className: `manifest-issue__icon manifest-issue__icon--${level}`, 63 src: icon.src, 64 }) 65 ), 66 span({}, message) 67 ); 68 } 69 } 70 71 // Exports 72 module.exports = ManifestIssue;