summaryrefslogtreecommitdiffstats
path: root/devtools/client/dom/content/components/MainToolbar.js
blob: f3f018741a74475c5c5d58d6b464a47f05e1e4f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

// React
const {
  Component,
  createFactory,
} = require("resource://devtools/client/shared/vendor/react.js");
const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.js");
const SearchBox = createFactory(
  require("resource://devtools/client/shared/components/SearchBox.js")
);

const { l10n } = require("resource://devtools/client/dom/content/utils.js");

// Actions
const {
  fetchProperties,
} = require("resource://devtools/client/dom/content/actions/grips.js");
const {
  setVisibilityFilter,
} = require("resource://devtools/client/dom/content/actions/filter.js");

/**
 * This template is responsible for rendering a toolbar
 * within the 'Headers' panel.
 */
class MainToolbar extends Component {
  static get propTypes() {
    return {
      object: PropTypes.any.isRequired,
      dispatch: PropTypes.func.isRequired,
    };
  }

  constructor(props) {
    super(props);
    this.onRefresh = this.onRefresh.bind(this);
    this.onSearch = this.onSearch.bind(this);
  }

  onRefresh() {
    this.props.dispatch(fetchProperties(this.props.object));
  }

  onSearch(value) {
    this.props.dispatch(setVisibilityFilter(value));
  }

  render() {
    return dom.div(
      { className: "devtools-toolbar devtools-input-toolbar" },
      SearchBox({
        key: "filter",
        delay: 250,
        onChange: this.onSearch,
        placeholder: l10n.getStr("dom.filterDOMPanel"),
        type: "filter",
      }),
      dom.span({ className: "devtools-separator" }),
      dom.button({
        key: "refresh",
        className: "refresh devtools-button",
        id: "dom-refresh-button",
        title: l10n.getStr("dom.refresh"),
        onClick: this.onRefresh,
      })
    );
  }
}

// Exports from this module
module.exports = MainToolbar;