ManifestIssueList.js (1833B)
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 { 12 ul, 13 } = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 14 15 const { 16 MANIFEST_ISSUE_LEVELS, 17 } = require("resource://devtools/client/application/src/constants.js"); 18 const Types = require("resource://devtools/client/application/src/types/index.js"); 19 20 const ManifestIssue = createFactory( 21 require("resource://devtools/client/application/src/components/manifest/ManifestIssue.js") 22 ); 23 24 /** 25 * A collection of manifest issues (errors, warnings) 26 */ 27 class ManifestIssueList extends PureComponent { 28 static get propTypes() { 29 return { 30 issues: Types.manifestIssueArray.isRequired, 31 }; 32 } 33 34 // group the errors by level, and order by severity 35 groupIssuesByLevel() { 36 const { issues } = this.props; 37 38 const errors = issues.filter(x => x.level === MANIFEST_ISSUE_LEVELS.ERROR); 39 const warnings = issues.filter( 40 x => x.level === MANIFEST_ISSUE_LEVELS.WARNING 41 ); 42 43 return [errors, warnings]; 44 } 45 46 render() { 47 const groups = this.groupIssuesByLevel().filter(list => !!list.length); 48 49 return groups.map((list, listIndex) => { 50 return ul( 51 { 52 className: "manifest-issues js-manifest-issues", 53 key: `issuelist-${listIndex}`, 54 }, 55 list.map((issue, issueIndex) => 56 ManifestIssue({ 57 className: "manifest-issues__item", 58 key: `issue-${issueIndex}`, 59 ...issue, 60 }) 61 ) 62 ); 63 }); 64 } 65 } 66 67 // Exports 68 module.exports = ManifestIssueList;