summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutlogins/content/components/import-details-row.mjs
blob: 13fe40da59e3dd8b53b2af76a6df5f8d001f31d6 (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
/* 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/. */

const resultToUiData = {
  no_change: {
    message: "about-logins-import-report-row-description-no-change",
  },
  modified: {
    message: "about-logins-import-report-row-description-modified",
  },
  added: {
    message: "about-logins-import-report-row-description-added",
  },
  error: {
    message: "about-logins-import-report-row-description-error",
    isError: true,
  },
  error_multiple_values: {
    message: "about-logins-import-report-row-description-error-multiple-values",
    isError: true,
  },
  error_missing_field: {
    message: "about-logins-import-report-row-description-error-missing-field",
    isError: true,
  },
};

export default class ImportDetailsRow extends HTMLElement {
  constructor(number, reportRow) {
    super();
    this._login = reportRow;

    let rowElement = document
      .querySelector("#import-details-row-template")
      .content.cloneNode(true);

    const uiData = resultToUiData[reportRow.result];
    if (uiData.isError) {
      this.classList.add("error");
    }
    const rowCount = rowElement.querySelector(".row-count");
    const rowDetails = rowElement.querySelector(".row-details");
    while (rowElement.childNodes.length) {
      this.appendChild(rowElement.childNodes[0]);
    }
    document.l10n.connectRoot(this);
    document.l10n.setAttributes(
      rowCount,
      "about-logins-import-report-row-index",
      {
        number,
      }
    );
    document.l10n.setAttributes(rowDetails, uiData.message, {
      field: reportRow.field_name,
    });
  }
}
customElements.define("import-details-row", ImportDetailsRow);