summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/src/components/debugtarget/TemporaryExtensionInstallSection.js
blob: f85618f73dc982186c41f57770aaabd59819c551 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* 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";

const {
  createFactory,
  PureComponent,
} = 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 FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js");
const Localized = createFactory(FluentReact.Localized);

const DetailsLog = createFactory(
  require("resource://devtools/client/aboutdebugging/src/components/shared/DetailsLog.js")
);
const Message = createFactory(
  require("resource://devtools/client/aboutdebugging/src/components/shared/Message.js")
);
const TemporaryExtensionInstaller = createFactory(
  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/TemporaryExtensionInstaller.js")
);

const {
  MESSAGE_LEVEL,
} = require("resource://devtools/client/aboutdebugging/src/constants.js");

/**
 * This component provides an installer and error message area for temporary extension.
 */
class TemporaryExtensionInstallSection extends PureComponent {
  static get propTypes() {
    return {
      dispatch: PropTypes.func.isRequired,
      temporaryInstallError: PropTypes.object,
    };
  }

  renderError() {
    const { temporaryInstallError } = this.props;

    if (!temporaryInstallError) {
      return null;
    }

    const errorMessages = [
      temporaryInstallError.message,
      ...(temporaryInstallError.additionalErrors || []),
    ];

    const errors = errorMessages.map((message, index) => {
      return dom.p(
        {
          className: "technical-text",
          key: "tmp-extension-install-error-" + index,
        },
        message
      );
    });

    return Message(
      {
        level: MESSAGE_LEVEL.ERROR,
        className: "qa-tmp-extension-install-error",
        isCloseable: true,
      },
      Localized(
        {
          id: "about-debugging-tmp-extension-install-error",
        },
        dom.p({}, "about-debugging-tmp-extension-install-error")
      ),
      DetailsLog(
        {
          type: MESSAGE_LEVEL.ERROR,
        },
        errors
      )
    );
  }

  render() {
    const { dispatch } = this.props;

    return dom.section(
      {},
      dom.div(
        {
          className: "temporary-extension-install-section__toolbar",
        },
        TemporaryExtensionInstaller({ dispatch })
      ),
      this.renderError()
    );
  }
}

module.exports = TemporaryExtensionInstallSection;