FIX: show group filter only when user is logged in and groups are present (#14578)

This commit is contained in:
Arpit Jalan 2021-10-12 19:46:39 +05:30 committed by GitHub
parent b44119cdb2
commit d2f9108470
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 19 deletions

View File

@ -3,7 +3,7 @@ import Group from "discourse/models/group";
import { action } from "@ember/object"; import { action } from "@ember/object";
import discourseDebounce from "discourse-common/lib/debounce"; import discourseDebounce from "discourse-common/lib/debounce";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
import { equal } from "@ember/object/computed"; import { and, equal } from "@ember/object/computed";
import { longDate } from "discourse/lib/formatter"; import { longDate } from "discourse/lib/formatter";
import { observes } from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators";
@ -19,8 +19,9 @@ export default Controller.extend({
exclude_usernames: null, exclude_usernames: null,
isLoading: false, isLoading: false,
columns: null, columns: null,
groupsOptions: null, groupOptions: null,
params: null, params: null,
showGroupFilter: and("currentUser", "groupOptions"),
showTimeRead: equal("period", "all"), showTimeRead: equal("period", "all"),
@ -66,15 +67,17 @@ export default Controller.extend({
}, },
loadGroups() { loadGroups() {
return Group.findAll({ ignore_automatic: true }).then((groups) => { if (this.currentUser) {
const groupOptions = groups.map((group) => { return Group.findAll({ ignore_automatic: true }).then((groups) => {
return { const groupOptions = groups.map((group) => {
name: group.full_name || group.name, return {
id: group.name, name: group.full_name || group.name,
}; id: group.name,
};
});
this.set("groupOptions", groupOptions);
}); });
this.set("groupOptions", groupOptions); }
});
}, },
@action @action

View File

@ -25,15 +25,17 @@
placeholderKey="directory.filter_name" placeholderKey="directory.filter_name"
class="filter-name no-blur" class="filter-name no-blur"
}} }}
{{combo-box {{#if showGroupFilter}}
class="directory-group-selector" {{combo-box
value=group class="directory-group-selector"
content=groupOptions value=group
onChange=(action groupChanged) content=groupOptions
options=(hash onChange=(action groupChanged)
none="directory.group.all" options=(hash
) none="directory.group.all"
}} )
}}
{{/if}}
{{#if currentUser.staff}} {{#if currentUser.staff}}
{{d-button {{d-button
icon="wrench" icon="wrench"