Manifest.js (4408B)
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 article, 13 h1, 14 table, 15 tbody, 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 const { 21 l10n, 22 } = require("resource://devtools/client/application/src/modules/l10n.js"); 23 24 const ManifestColorItem = createFactory( 25 require("resource://devtools/client/application/src/components/manifest/ManifestColorItem.js") 26 ); 27 const ManifestIconItem = createFactory( 28 require("resource://devtools/client/application/src/components/manifest/ManifestIconItem.js") 29 ); 30 const ManifestUrlItem = createFactory( 31 require("resource://devtools/client/application/src/components/manifest/ManifestUrlItem.js") 32 ); 33 const ManifestItem = createFactory( 34 require("resource://devtools/client/application/src/components/manifest/ManifestItem.js") 35 ); 36 const ManifestIssueList = createFactory( 37 require("resource://devtools/client/application/src/components/manifest/ManifestIssueList.js") 38 ); 39 const ManifestSection = createFactory( 40 require("resource://devtools/client/application/src/components/manifest/ManifestSection.js") 41 ); 42 const ManifestJsonLink = createFactory( 43 require("resource://devtools/client/application/src/components/manifest/ManifestJsonLink.js") 44 ); 45 46 const { 47 MANIFEST_MEMBER_VALUE_TYPES, 48 } = require("resource://devtools/client/application/src/constants.js"); 49 const Types = require("resource://devtools/client/application/src/types/index.js"); 50 51 /** 52 * A canonical manifest, splitted in different sections 53 */ 54 class Manifest extends PureComponent { 55 static get propTypes() { 56 return { 57 ...Types.manifest, // { identity, presentation, icons, validation, url } 58 }; 59 } 60 61 renderIssueSection() { 62 const { validation } = this.props; 63 const shouldRender = validation && !!validation.length; 64 65 return shouldRender 66 ? ManifestSection( 67 { 68 key: `manifest-section-0`, 69 title: l10n.getString("manifest-item-warnings"), 70 }, 71 ManifestIssueList({ issues: validation }) 72 ) 73 : null; 74 } 75 76 renderMember({ key, value, type }, index) { 77 let domKey = key; 78 switch (type) { 79 case MANIFEST_MEMBER_VALUE_TYPES.COLOR: 80 return ManifestColorItem({ label: key, key: domKey, value }); 81 case MANIFEST_MEMBER_VALUE_TYPES.ICON: 82 // since the manifest may have keys with empty size/contentType, 83 // we cannot use them as unique IDs 84 domKey = index; 85 return ManifestIconItem({ label: key, key: domKey, value }); 86 case MANIFEST_MEMBER_VALUE_TYPES.URL: 87 return ManifestUrlItem({ label: key, key: domKey, value }); 88 case MANIFEST_MEMBER_VALUE_TYPES.STRING: 89 default: 90 return ManifestItem({ label: key, key: domKey }, value); 91 } 92 } 93 94 renderItemSections() { 95 const { identity, icons, presentation } = this.props; 96 97 const manifestMembers = [ 98 { localizationId: "manifest-item-identity", items: identity }, 99 { localizationId: "manifest-item-presentation", items: presentation }, 100 { localizationId: "manifest-item-icons", items: icons }, 101 ]; 102 103 return manifestMembers.map(({ localizationId, items }, index) => { 104 return ManifestSection( 105 { 106 key: `manifest-section-${index + 1}`, 107 title: l10n.getString(localizationId), 108 }, 109 // NOTE: this table should probably be its own component, to keep 110 // the same level of abstraction as with the validation issues 111 // Bug https://bugzilla.mozilla.org/show_bug.cgi?id=1577138 112 table({}, tbody({}, items.map(this.renderMember))) 113 ); 114 }); 115 } 116 117 render() { 118 const { url } = this.props; 119 120 return article( 121 { className: "js-manifest" }, 122 Localized( 123 { 124 id: "manifest-view-header", 125 }, 126 h1({ className: "app-page__title" }) 127 ), 128 ManifestJsonLink({ url }), 129 this.renderIssueSection(), 130 this.renderItemSections() 131 ); 132 } 133 } 134 135 // Exports 136 module.exports = Manifest;