JsonToolbar.mjs (2454B)
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 import { Component } from "resource://devtools/client/shared/vendor/react.mjs"; 6 import PropTypes from "resource://devtools/client/shared/vendor/react-prop-types.mjs"; 7 import { div } from "resource://devtools/client/shared/vendor/react-dom-factories.mjs"; 8 import { createFactories } from "resource://devtools/client/shared/react-utils.mjs"; 9 10 import SearchBoxClass from "resource://devtools/client/jsonview/components/SearchBox.mjs"; 11 12 const { SearchBox } = createFactories(SearchBoxClass); 13 import ToolbarClass from "resource://devtools/client/jsonview/components/reps/Toolbar.mjs"; 14 15 const { Toolbar, ToolbarButton } = createFactories(ToolbarClass); 16 17 /* 100kB file */ 18 const EXPAND_THRESHOLD = 100 * 1024; 19 20 /** 21 * This template represents a toolbar within the 'JSON' panel. 22 */ 23 class JsonToolbar extends Component { 24 static get propTypes() { 25 return { 26 actions: PropTypes.object, 27 dataSize: PropTypes.number, 28 }; 29 } 30 31 constructor(props) { 32 super(props); 33 this.onSave = this.onSave.bind(this); 34 this.onCopy = this.onCopy.bind(this); 35 this.onCollapse = this.onCollapse.bind(this); 36 this.onExpand = this.onExpand.bind(this); 37 } 38 39 // Commands 40 41 onSave() { 42 this.props.actions.onSaveJson(); 43 } 44 45 onCopy() { 46 this.props.actions.onCopyJson(); 47 } 48 49 onCollapse() { 50 this.props.actions.onCollapse(); 51 } 52 53 onExpand() { 54 this.props.actions.onExpand(); 55 } 56 57 render() { 58 return Toolbar( 59 {}, 60 ToolbarButton( 61 { className: "btn save", onClick: this.onSave }, 62 JSONView.Locale["jsonViewer.Save"] 63 ), 64 ToolbarButton( 65 { className: "btn copy", onClick: this.onCopy }, 66 JSONView.Locale["jsonViewer.Copy"] 67 ), 68 ToolbarButton( 69 { className: "btn collapse", onClick: this.onCollapse }, 70 JSONView.Locale["jsonViewer.CollapseAll"] 71 ), 72 ToolbarButton( 73 { className: "btn expand", onClick: this.onExpand }, 74 this.props.dataSize > EXPAND_THRESHOLD 75 ? JSONView.Locale["jsonViewer.ExpandAllSlow"] 76 : JSONView.Locale["jsonViewer.ExpandAll"] 77 ), 78 div({ className: "devtools-separator" }), 79 SearchBox({ 80 actions: this.props.actions, 81 }) 82 ); 83 } 84 } 85 86 export default { JsonToolbar };