Skip to content

Commit

Permalink
Data list's toggle all button now selects maximum possible entries (#…
Browse files Browse the repository at this point in the history
…6816)

Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
ncla and jasonvarga committed Nov 1, 2022
1 parent 7ce9b4d commit 7a3cfb7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion resources/js/components/collections/Listing.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<data-list :columns="columns" :rows="rows">
<data-list ref="dataList" :columns="columns" :rows="rows">
<div class="card p-0" slot-scope="{ filteredRows: rows }">
<data-list-table :rows="rows">
<template slot="cell-title" slot-scope="{ row: collection }">
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/data-list/HasFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default {
},

unselectAllItems() {
if (this.$refs.toggleAll) {
this.$refs.toggleAll.uncheckAllItems();
if (this.$refs.dataList) {
this.$refs.dataList.clearSelections();
}
},

Expand Down
14 changes: 6 additions & 8 deletions resources/js/components/data-list/ToggleAll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
export default {
inject: ['sharedState'],
computed: {
allItemsChecked() {
if (this.sharedState.rows.length === 0) return false;
return this.sharedState.selections.length === this.sharedState.rows.length;
},
anyItemsChecked() {
return this.sharedState.selections.length > 0;
},
},
methods: {
toggle() {
this.anyItemsChecked ? this.uncheckAllItems() : this.checkAllItems()
this.anyItemsChecked ? this.uncheckAllItems() : this.checkMaximumAmountOfItems()
},
checkAllItems() {
this.sharedState.selections = _.values(_.map(this.sharedState.rows, item => item.id))
checkMaximumAmountOfItems() {
this.sharedState.selections = _.chain(this.sharedState.rows)
.map(item => item.id)
.first(this.sharedState.maxSelections ?? Infinity)
.value()
},
uncheckAllItems() {
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/entries/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<data-list
v-if="!initializing"
ref="dataList"
:rows="items"
:columns="columns"
:sort="false"
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/inputs/relationship/Selector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<data-list
v-if="!initializing"
ref="dataList"
:rows="items"
:columns="columns"
:sort="false"
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/terms/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<data-list
v-if="!initializing"
ref="dataList"
:rows="items"
:columns="columns"
:sort="false"
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/users/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<data-list
v-if="!initializing"
ref="dataList"
:columns="columns"
:rows="items"
:sort="false"
Expand Down

0 comments on commit 7a3cfb7

Please sign in to comment.