Fix "Not Participating" filter checkbox on Discover Challenges screen, Fixes #13025 (#13183)

* change 'role' options and filters to 'membership'

* added membership filtering function to discover challenges

* fix accidental deletion

* complete removal of roles from challenge filters

* abstract challenge "participating" filtering into mixin

* selecting "participating" and "not participating" shows all challenges
This commit is contained in:
Liza
2021-05-28 17:57:03 -04:00
committed by GitHub
parent f097077009
commit 9e655d70d2
4 changed files with 36 additions and 60 deletions

View File

@@ -31,7 +31,8 @@
</div> </div>
<div class="row"> <div class="row">
<div <div
v-if="!loading && filteredChallenges.length === 0" v-if="!loading &&
this.filteredChallenges.length === 0"
class="no-challenges text-center col-md-6 offset-3" class="no-challenges text-center col-md-6 offset-3"
> >
<h2 v-once> <h2 v-once>
@@ -41,7 +42,7 @@
</div> </div>
<div class="row"> <div class="row">
<div <div
v-for="challenge in filteredChallenges" v-for="challenge in this.filteredChallenges"
:key="challenge._id" :key="challenge._id"
class="col-12 col-md-6" class="col-12 col-md-6"
> >
@@ -170,9 +171,6 @@ export default {
}, },
computed: { computed: {
...mapState({ user: 'user.data' }), ...mapState({ user: 'user.data' }),
filteredChallenges () {
return this.challenges;
},
}, },
mounted () { mounted () {
this.$store.dispatch('common:setTitle', { this.$store.dispatch('common:setTitle', {

View File

@@ -51,7 +51,7 @@
</div> </div>
<div class="row"> <div class="row">
<div <div
v-if="!loading && challenges.length > 0 && filteredChallenges.length === 0" v-if="!loading && challenges.length > 0 && this.filteredChallenges.length === 0"
class="no-challenges text-center col-md-6 offset-3" class="no-challenges text-center col-md-6 offset-3"
> >
<h2 v-once> <h2 v-once>
@@ -61,7 +61,7 @@
</div> </div>
<div class="row"> <div class="row">
<div <div
v-for="challenge in filteredChallenges" v-for="challenge in this.filteredChallenges"
:key="challenge._id" :key="challenge._id"
class="col-12 col-md-6" class="col-12 col-md-6"
> >
@@ -197,25 +197,6 @@ export default {
}, },
computed: { computed: {
...mapState({ user: 'user.data' }), ...mapState({ user: 'user.data' }),
filteredChallenges () {
const { filters } = this;
const { user } = this;
return this.challenges.filter(challenge => {
let isMember = true;
const filteringRole = filters.roles && filters.roles.length > 0;
if (filteringRole && filters.roles.indexOf('participating') !== -1) {
isMember = this.isMemberOfChallenge(user, challenge);
}
if (filteringRole && filters.roles.indexOf('not_participating') !== -1) {
isMember = !this.isMemberOfChallenge(user, challenge);
}
return isMember;
});
},
}, },
mounted () { mounted () {
this.$store.dispatch('common:setTitle', { this.$store.dispatch('common:setTitle', {

View File

@@ -34,42 +34,19 @@
</div> </div>
</div> </div>
</filter-group> </filter-group>
<filter-group :title="$t('role')">
<div
v-for="group in roleOptions"
:key="group.key"
class="form-check"
>
<div class="custom-control custom-checkbox">
<input
:id="group.key"
v-model="roleFilters"
class="custom-control-input"
type="checkbox"
:value="group.key"
>
<label
v-once
class="custom-control-label"
:for="group.key"
>{{ $t(group.label) }}</label>
</div>
</div>
</filter-group>
<filter-group <filter-group
v-if="$route.name !== 'findChallenges'"
:title="$t('membership')" :title="$t('membership')"
class="form-group" class="form-group"
> >
<div <div
v-for="group in roleOptions" v-for="group in membershipOptions"
:key="group.key" :key="group.key"
class="form-check" class="form-check"
> >
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input <input
:id="group.key" :id="group.key"
v-model="roleFilters" v-model="membershipFilters"
class="custom-control-input" class="custom-control-input"
type="checkbox" type="checkbox"
:value="group.key" :value="group.key"
@@ -176,8 +153,8 @@ export default {
key: 'time_management', key: 'time_management',
}, },
], ],
roleFilters: [], membershipFilters: [],
roleOptions: [ membershipOptions: [
{ {
label: 'participating', label: 'participating',
key: 'participating', key: 'participating',
@@ -186,10 +163,6 @@ export default {
label: 'not_participating', label: 'not_participating',
key: 'not_participating', key: 'not_participating',
}, },
// {
// label: 'either',
// key: 'either',
// },
], ],
ownershipFilters: [], ownershipFilters: [],
ownershipOptions: [ ownershipOptions: [
@@ -213,10 +186,10 @@ export default {
categoryFilters: function categoryFilters () { categoryFilters: function categoryFilters () {
this.emitFilters(); this.emitFilters();
}, },
roleFilters: function roleFilters () { ownershipFilters: function ownershipFilters () {
this.emitFilters(); this.emitFilters();
}, },
ownershipFilters: function ownershipFilters () { membershipFilters: function membershipFilters () {
this.emitFilters(); this.emitFilters();
}, },
searchTerm: throttle(function searchTerm (newSearch) { searchTerm: throttle(function searchTerm (newSearch) {
@@ -229,8 +202,8 @@ export default {
emitFilters () { emitFilters () {
this.$emit('filter', { this.$emit('filter', {
categories: this.categoryFilters, categories: this.categoryFilters,
roles: this.roleFilters,
ownership: this.ownershipFilters, ownership: this.ownershipFilters,
membership: this.membershipFilters,
}); });
}, },
}, },

View File

@@ -4,4 +4,28 @@ export default {
return user.challenges.indexOf(challenge._id) !== -1; return user.challenges.indexOf(challenge._id) !== -1;
}, },
}, },
computed: {
filteredChallenges () {
const { filters } = this;
const { user } = this;
return this.challenges.filter(challenge => {
const filteringMembership = filters.membership && filters.membership.length > 0;
// if both filters are selected, display all challenges
if (filteringMembership && filters.membership.indexOf('participating') !== -1
&& filteringMembership && filters.membership.indexOf('not_participating') !== -1) {
return true;
}
if (filteringMembership && filters.membership.indexOf('participating') !== -1) {
return this.isMemberOfChallenge(user, challenge);
}
if (filteringMembership && filters.membership.indexOf('not_participating') !== -1) {
return !this.isMemberOfChallenge(user, challenge);
}
return true;
});
},
},
}; };