Bug 1592670 - Add "Alerts" to Sort Drop Down Menu. r=jaws,fluent-reviewers
authorlesleynorton <lnorton@mozilla.com>
Thu, 26 Mar 2020 15:15:52 +0000
changeset 520581 c66ff7f7dc6da4e0a540040a98a66771f50a63fa
parent 520580 395b889fe0285019ce3e943862351e7ebf90f39c
child 520582 228988ede47da5c247d0a821ad49613babab11ce
push id37253
push usernerli@mozilla.com
push dateThu, 26 Mar 2020 21:36:52 +0000
treeherdermozilla-central@c644dd16e2cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, fluent-reviewers
bugs1592670
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1592670 - Add "Alerts" to Sort Drop Down Menu. r=jaws,fluent-reviewers Differential Revision: https://phabricator.services.mozilla.com/D68111
browser/components/aboutlogins/content/aboutLogins.html
browser/components/aboutlogins/content/components/login-list.js
browser/components/aboutlogins/tests/chrome/test_login_list.html
browser/locales/en-US/browser/aboutLogins.ftl
--- a/browser/components/aboutlogins/content/aboutLogins.html
+++ b/browser/components/aboutlogins/content/aboutLogins.html
@@ -85,17 +85,17 @@
       <div class="meta">
         <label for="login-sort">
           <span data-l10n-id="login-list-sort-label-text"></span>
           <select id="login-sort">
             <option name="name" data-l10n-id="login-list-name-option" value="name">
             <option name="name-reverse" data-l10n-id="login-list-name-reverse-option" value="name-reverse">
             <option name="last-used" data-l10n-id="login-list-last-used-option" value="last-used">
             <option name="last-changed" data-l10n-id="login-list-last-changed-option" value="last-changed">
-            <option name="breached" data-l10n-id="login-list-breached-option" value="breached" hidden>
+            <option name="alerts" data-l10n-id="about-logins-login-list-alerts-option" value="alerts">
           </select>
         </label>
         <span class="count" data-l10n-id="login-list-count" data-l10n-args='{"count": 0}'></span>
       </div>
       <!-- This container is to work around bug 1569292 -->
       <div class="container">
         <ol role="listbox" tabindex="0" data-l10n-id="login-list"></ol>
         <div class="intro">
--- a/browser/components/aboutlogins/content/components/login-list.js
+++ b/browser/components/aboutlogins/content/components/login-list.js
@@ -6,26 +6,32 @@ import LoginListItemFactory from "./logi
 import { recordTelemetryEvent } from "../aboutLoginsUtils.js";
 
 const collator = new Intl.Collator();
 const sortFnOptions = {
   name: (a, b) => collator.compare(a.title, b.title),
   "name-reverse": (a, b) => collator.compare(b.title, a.title),
   "last-used": (a, b) => a.timeLastUsed < b.timeLastUsed,
   "last-changed": (a, b) => a.timePasswordChanged < b.timePasswordChanged,
-  breached: (a, b, breachesByLoginGUID) => {
-    if (!breachesByLoginGUID) {
+  alerts: (a, b, breachesByLoginGUID, vulnerableLoginsByLoginGUID) => {
+    if (!breachesByLoginGUID && !vulnerableLoginsByLoginGUID) {
       return 0;
     }
-    const aIsBreached = breachesByLoginGUID.has(a.guid);
-    const bIsBreached = breachesByLoginGUID.has(b.guid);
-    if (aIsBreached && !bIsBreached) {
+    const aIsBreached = breachesByLoginGUID && breachesByLoginGUID.has(a.guid);
+    const bIsBreached = breachesByLoginGUID && breachesByLoginGUID.has(b.guid);
+    const aIsVulnerable =
+      vulnerableLoginsByLoginGUID && vulnerableLoginsByLoginGUID.has(a.guid);
+    const bIsVulnerable =
+      vulnerableLoginsByLoginGUID && vulnerableLoginsByLoginGUID.has(b.guid);
+
+    if ((aIsBreached && !bIsBreached) || (aIsVulnerable && !bIsVulnerable)) {
       return -1;
     }
-    if (!aIsBreached && bIsBreached) {
+
+    if ((!aIsBreached && bIsBreached) || (!aIsVulnerable && bIsVulnerable)) {
       return 1;
     }
     return collator.compare(a.title, b.title);
   },
 };
 
 export default class LoginList extends HTMLElement {
   constructor() {
@@ -387,19 +393,19 @@ export default class LoginList extends H
     if (this[internalMemberName].size === 0) {
       this.render();
       return;
     }
     for (let [loginGuid] of mapByLoginGUID) {
       let { login, listItem } = this._logins[loginGuid];
       LoginListItemFactory.update(listItem, login);
     }
-    const breachedSortOptionElement = this._sortSelect.namedItem("breached");
-    breachedSortOptionElement.hidden = false;
-    this._sortSelect.selectedIndex = breachedSortOptionElement.index;
+    const alertsSortOptionElement = this._sortSelect.namedItem("alerts");
+    alertsSortOptionElement.hidden = false;
+    this._sortSelect.selectedIndex = alertsSortOptionElement.index;
     this._applySortAndScrollToTop();
     this._selectFirstVisibleLogin();
   }
 
   _internalUpdateMonitorData(internalMemberName, mapByLoginGUID) {
     if (!this[internalMemberName]) {
       this[internalMemberName] = new Map();
     }
@@ -520,17 +526,25 @@ export default class LoginList extends H
     return matchingLoginGuids;
   }
 
   _applySort() {
     const sort = this._sortSelect.value;
     this._loginGuidsSortedOrder = this._loginGuidsSortedOrder.sort((a, b) => {
       let loginA = this._logins[a].login;
       let loginB = this._logins[b].login;
-      return sortFnOptions[sort](loginA, loginB, this._breachesByLoginGUID);
+      if (this._breachesByLoginGUID && this._vulnerableLoginsByLoginGUID) {
+        return sortFnOptions[sort](
+          loginA,
+          loginB,
+          this._breachesByLoginGUID,
+          this._vulnerableLoginsByLoginGUID
+        );
+      }
+      return sortFnOptions[sort](loginA, loginB);
     });
   }
 
   _applySortAndScrollToTop() {
     this._applySort();
     this.render();
     this._list.scrollTop = 0;
   }
--- a/browser/components/aboutlogins/tests/chrome/test_login_list.html
+++ b/browser/components/aboutlogins/tests/chrome/test_login_list.html
@@ -515,25 +515,27 @@ add_task(async function test_sorted_list
   let pwChanged1 = gLoginList._logins[loginListItems[0].dataset.guid].login.timePasswordChanged;
   let pwChanged2 = gLoginList._logins[loginListItems[1].dataset.guid].login.timePasswordChanged;
   let pwChanged3 = gLoginList._logins[loginListItems[2].dataset.guid].login.timePasswordChanged;
   is(pwChanged1 > pwChanged2, true, "Logins sorted by timePasswordChanged. First: " + pwChanged1 + "; Second: " + pwChanged2);
   is(pwChanged2 > pwChanged3, true, "Logins sorted by timePasswordChanged. Second: " + pwChanged2 + "; Third: " + pwChanged3);
 
   // sort by breached when there are breached logins
   gLoginList.setBreaches(TEST_BREACHES_MAP);
-  loginSort.value = "breached";
+  loginSort.value = "alerts";
+  let vulnerableLogins = new Map();
+  gLoginList.setVulnerableLogins(vulnerableLogins);
   dispatchChangeEvent(loginSort);
   loginListItems = gLoginList.shadowRoot.querySelectorAll(".login-list-item:not(#new-login-list-item):not([hidden])");
   is(loginListItems[0].classList.contains("breached"), true, "Breached login should be displayed at top of list");
   is(!loginListItems[1].classList.contains("breached"), true, "Non-breached login should be displayed below breached");
 
   // sort by name when there are no breached logins
   gLoginList.setBreaches(new Map());
-  loginSort.value = "breached";
+  loginSort.value = "alerts";
   dispatchChangeEvent(loginSort);
   loginListItems = gLoginList.shadowRoot.querySelectorAll(".login-list-item:not(#new-login-list-item):not([hidden])");
   title1 = gLoginList._logins[loginListItems[0].dataset.guid].login.title;
   title2 = gLoginList._logins[loginListItems[1].dataset.guid].login.title;
   is(title1.localeCompare(title2), -1, "Logins should be sorted alphabetically by hostname");
 });
 
 add_task(async function test_login_list_item_removed_next_selected() {
--- a/browser/locales/en-US/browser/aboutLogins.ftl
+++ b/browser/locales/en-US/browser/aboutLogins.ftl
@@ -45,17 +45,17 @@ login-list =
 login-list-count =
   { $count ->
       [one] { $count } login
      *[other] { $count } logins
   }
 login-list-sort-label-text = Sort by:
 login-list-name-option = Name (A-Z)
 login-list-name-reverse-option = Name (Z-A)
-login-list-breached-option = Breached Websites
+about-logins-login-list-alerts-option = Alerts
 login-list-last-changed-option = Last Modified
 login-list-last-used-option = Last Used
 login-list-intro-title = No logins found
 login-list-intro-description = When you save a password in { -brand-product-name }, it will show up here.
 about-logins-login-list-empty-search-title = No logins found
 about-logins-login-list-empty-search-description = There are no results matching your search.
 login-list-item-title-new-login = New Login
 login-list-item-subtitle-new-login = Enter your login credentials