FEATURE: Add group filter to user directory (#13330)

FEATURE: Add group filter to user directory (#13330)

diff --git a/app/assets/javascripts/discourse/app/controllers/users.js b/app/assets/javascripts/discourse/app/controllers/users.js
index 98f4872..e287882 100644
--- a/app/assets/javascripts/discourse/app/controllers/users.js
+++ b/app/assets/javascripts/discourse/app/controllers/users.js
@@ -18,6 +18,7 @@ export default Controller.extend({
   exclude_usernames: null,
   isLoading: false,
   columns: null,
+  groupsOptions: null,
 
   showTimeRead: equal("period", "all"),
 
@@ -32,7 +33,7 @@ export default Controller.extend({
       .map((c) => c.user_field_id)
       .join("|");
 
-    this.store
+    return this.store
       .find("directoryItem", Object.assign(params, { user_field_ids }))
       .then((model) => {
         const lastUpdatedAt = model.get("resultSetMeta.last_updated_at");
@@ -47,13 +48,31 @@ export default Controller.extend({
       });
   },
 
+  loadGroups() {
+    return this.store.findAll("group").then((groups) => {
+      const groupOptions = groups.map((group) => {
+        return {
+          name: group.name,
+          id: group.id,
+        };
+      });
+      this.set("groupOptions", groupOptions);
+    });
+  },
+
+  @action
+  groupChanged(_, groupAttrs) {
+    // First param is the group name, which include none or 'all groups'. Ignore this and look at second param.
+    this.set("group", groupAttrs.id ? groupAttrs.name : null);
+  },
+
   @action
   showEditColumnsModal() {
     showModal("edit-user-directory-columns");
   },
 
   @action
-  onFilterChanged(filter) {
+  onUsernameFilterChanged(filter) {
     discourseDebounce(this, this._setName, filter, 500);
   },
 
diff --git a/app/assets/javascripts/discourse/app/routes/users.js b/app/assets/javascripts/discourse/app/routes/users.js
index 8c059ad..181204d 100644
--- a/app/assets/javascripts/discourse/app/routes/users.js
+++ b/app/assets/javascripts/discourse/app/routes/users.js
@@ -1,6 +1,7 @@
 import DiscourseRoute from "discourse/routes/discourse";
 import I18n from "I18n";
 import PreloadStore from "discourse/lib/preload-store";
+import { Promise } from "rsvp";
 
 export default DiscourseRoute.extend({
   queryParams: {
@@ -44,7 +45,10 @@ export default DiscourseRoute.extend({
 
   setupController(controller, model) {
     controller.set("columns", model.columns);
-    controller.loadUsers(model.params);
+    return Promise.all([
+      controller.loadGroups(),
+      controller.loadUsers(model.params),
+    ]);
   },
 
   actions: {
diff --git a/app/assets/javascripts/discourse/app/templates/mobile/users.hbs b/app/assets/javascripts/discourse/app/templates/mobile/users.hbs
index 44d463a..ff80213 100644
--- a/app/assets/javascripts/discourse/app/templates/mobile/users.hbs
+++ b/app/assets/javascripts/discourse/app/templates/mobile/users.hbs
@@ -13,10 +13,19 @@
         {{/if}}
         {{input
           value=(readonly nameInput)
-          input=(action "onFilterChanged" value="target.value")
+          input=(action "onUsernameFilterChanged" value="target.value")
           placeholderKey="directory.filter_name"
           class="filter-name no-blur"
         }}
+        {{combo-box
+          class="directory-group-selector"
+          value=group
+          content=groupOptions
+          onChange=(action groupChanged)
+          options=(hash
+            none="directory.group.all"
+          )
+        }}
         {{#if currentUser.staff}}
           {{d-button
             icon="wrench"
diff --git a/app/assets/javascripts/discourse/app/templates/users.hbs b/app/assets/javascripts/discourse/app/templates/users.hbs
index d2c85f6..d6c7450 100644
--- a/app/assets/javascripts/discourse/app/templates/users.hbs
+++ b/app/assets/javascripts/discourse/app/templates/users.hbs
@@ -21,10 +21,19 @@
             </span>
             {{input
               value=(readonly nameInput)
-              input=(action "onFilterChanged" value="target.value")
+              input=(action "onUsernameFilterChanged" value="target.value")
               placeholderKey="directory.filter_name"
               class="filter-name no-blur"
             }}
+            {{combo-box
+              class="directory-group-selector"
+              value=group
+              content=groupOptions
+              onChange=(action groupChanged)
+              options=(hash
+                none="directory.group.all"
+              )
+            }}
             {{#if currentUser.staff}}
               {{d-button
                 icon="wrench"
diff --git a/app/assets/stylesheets/common/base/directory.scss b/app/assets/stylesheets/common/base/directory.scss
index 3d93803..2a8e82b 100644
--- a/app/assets/stylesheets/common/base/directory.scss
+++ b/app/assets/stylesheets/common/base/directory.scss
@@ -20,6 +20,9 @@
         margin: 0;
       }
     }
+    .directory-group-selector {
+      vertical-align: top;
+    }
   }
 
   .user-info {
diff --git a/app/assets/stylesheets/mobile/directory.scss b/app/assets/stylesheets/mobile/directory.scss
index 25532ea..987580c 100644
--- a/app/assets/stylesheets/mobile/directory.scss
+++ b/app/assets/stylesheets/mobile/directory.scss
@@ -3,14 +3,9 @@
     font-size: $font-up-1;
   }
 
-  .open-edit-columns-btn {
-    margin: -0.7em 0 0.5em;
-  }
-
   &.users-directory {
     .filter-name {
       width: 100%;
-      margin-bottom: 1em;
     }
 
     .directory-last-updated {
@@ -59,4 +54,5 @@
 
 .edit-user-directory-columns-modal .modal-inner-container {
   width: 90%;
+  min-width: unset;
 }
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index bb78a81..57ef0b2 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -650,6 +650,8 @@ en:
         title: "Edit Directory Columns"
         save: "Save"
         reset_to_default: "Reset to default"
+      group:
+        all: "all groups"
 
     group_histories:
       actions:

GitHub sha: d500d0cc9966aaf0028097d7167425a627648bb6

This commit appears in #13330 which was approved by eviltrout. It was merged by markvanlan.