Sort workspace members list
This commit is contained in:
parent
6575afc1a0
commit
bfc6766caa
@ -1,4 +1,4 @@
|
|||||||
import { compose, filter, equals, indexBy, partial, prop, pipe } from 'ramda'
|
import { compose, sortBy, reverse, indexBy, partial, prop, pipe, toLower } from 'ramda'
|
||||||
|
|
||||||
const search = (query, members) => {
|
const search = (query, members) => {
|
||||||
if (query === '' || query === 'all') {
|
if (query === '' || query === 'all') {
|
||||||
@ -33,6 +33,19 @@ const filterByRole = (role, rolesByDisplayname, members) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sort = (sortInfo, members) => {
|
||||||
|
if (sortInfo.columnName === '') {
|
||||||
|
return members
|
||||||
|
} else {
|
||||||
|
const sortColumn = sortInfo.columns[sortInfo.columnName]
|
||||||
|
const sortedMembers = sortColumn.sortFunc(sortColumn.attr, members)
|
||||||
|
|
||||||
|
return sortInfo.isAscending ?
|
||||||
|
sortedMembers :
|
||||||
|
reverse(sortedMembers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'members-list',
|
name: 'members-list',
|
||||||
|
|
||||||
@ -42,11 +55,46 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
data: function () {
|
data: function () {
|
||||||
|
const alphabeticalSort = (attr, members) => {
|
||||||
|
const lowercaseProp = compose(toLower, prop(attr))
|
||||||
|
return sortBy(lowercaseProp, members)
|
||||||
|
}
|
||||||
|
|
||||||
|
const numericSort = (attr, members) => sortBy(prop(attr), members)
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
displayName: 'Name',
|
||||||
|
attr: 'name',
|
||||||
|
sortFunc: alphabeticalSort
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Environments',
|
||||||
|
attr: 'num_env',
|
||||||
|
sortFunc: numericSort
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Status',
|
||||||
|
attr: 'status',
|
||||||
|
sortFunc: alphabeticalSort
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Workspace Role',
|
||||||
|
attr: 'role',
|
||||||
|
sortFunc: alphabeticalSort
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
searchValue: '',
|
searchValue: '',
|
||||||
status: '',
|
status: '',
|
||||||
role: '',
|
role: '',
|
||||||
rolesByDisplayName: indexBy(prop('display_name'), this.choices),
|
rolesByDisplayName: indexBy(prop('display_name'), this.choices),
|
||||||
|
sortInfo: {
|
||||||
|
columnName: '',
|
||||||
|
isAscending: true,
|
||||||
|
columns: indexBy(prop('displayName'), columns)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -56,7 +104,19 @@ export default {
|
|||||||
partial(search, [this.searchValue]),
|
partial(search, [this.searchValue]),
|
||||||
partial(filterByStatus, [this.status]),
|
partial(filterByStatus, [this.status]),
|
||||||
partial(filterByRole, [this.role, this.rolesByDisplayName]),
|
partial(filterByRole, [this.role, this.rolesByDisplayName]),
|
||||||
|
partial(sort, [this.sortInfo])
|
||||||
)(this.members)
|
)(this.members)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
updateSort: function(columnName) {
|
||||||
|
// clicking a column twice toggles ascending / descending
|
||||||
|
if (columnName === this.sortInfo.columnName) {
|
||||||
|
this.sortInfo.isAscending = !this.sortInfo.isAscending
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sortInfo.columnName = columnName
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,10 @@
|
|||||||
<table v-if='searchedList && searchedList.length'>
|
<table v-if='searchedList && searchedList.length'>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" width="50%">Name</th>
|
<th @click="updateSort('Name')" scope="col" width="50%">Name</th>
|
||||||
<th scope="col" class="table-cell--align-right">Environments</th>
|
<th @click="updateSort('Environments')" scope="col" class="table-cell--align-right">Environments</th>
|
||||||
<th scope="col">Status</th>
|
<th @click="updateSort('Status')" scope="col">Status</th>
|
||||||
<th scope="col">Workspace Role</th>
|
<th @click="updateSort('Workspace Role')" scope="col">Workspace Role</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user