summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutlogins/content/components/import-summary-dialog.mjs
blob: 76d19b0190888dc8881bcef263ddc6ee8ec5d3ea (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
/* 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/. */

import { initDialog } from "../aboutLoginsUtils.mjs";

export default class ImportSummaryDialog extends HTMLElement {
  constructor() {
    super();
    this._promise = null;
  }

  connectedCallback() {
    if (this.shadowRoot) {
      return;
    }
    initDialog(this, "#import-summary-dialog-template");
    this._added = this.shadowRoot.querySelector(".import-items-added");
    this._modified = this.shadowRoot.querySelector(".import-items-modified");
    this._noChange = this.shadowRoot.querySelector(".import-items-no-change");
    this._error = this.shadowRoot.querySelector(".import-items-errors");
    this._genericDialog = this.shadowRoot.querySelector("generic-dialog");
  }

  show({ logins }) {
    const report = {
      added: 0,
      modified: 0,
      no_change: 0,
      error: 0,
    };
    for (let loginRow of logins) {
      if (loginRow.result.includes("error")) {
        report.error++;
      } else {
        report[loginRow.result]++;
      }
    }
    this._updateCount(
      report.added,
      this._added,
      "about-logins-import-dialog-items-added"
    );
    this._updateCount(
      report.modified,
      this._modified,
      "about-logins-import-dialog-items-modified"
    );
    this._updateCount(
      report.no_change,
      this._noChange,
      "about-logins-import-dialog-items-no-change"
    );
    this._updateCount(
      report.error,
      this._error,
      "about-logins-import-dialog-items-error"
    );
    this._noChange.querySelector(".result-meta").hidden =
      report.no_change === 0;
    this._error.querySelector(".result-meta").hidden = report.error === 0;
    this._genericDialog.show();
    window.AboutLoginsUtils.setFocus(this._genericDialog._dismissButton);
  }

  _updateCount(count, component, message) {
    if (count != document.l10n.getAttributes(component).args.count) {
      document.l10n.setAttributes(component, message, { count });
    }
  }
}
customElements.define("import-summary-dialog", ImportSummaryDialog);