Skip to content

Commit

Permalink
[BI-1369] enable backend sorting for roles column of program users table
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeidlin committed Mar 7, 2022
1 parent b3cc9a3 commit bbe8355
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/breeding-insight/service/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class UserService {

UserDAO.getAll(paginationQuery, sort).then((biResponse) => {

biResponse.result.data = PaginationController.mockSortRecords(biResponse.result.data);
// Parse our users into the vue users param
let users = biResponse.result.data.map((user: any) => {
const role: Role | undefined = this.parseSystemRoles(user.systemRoles);
Expand Down
16 changes: 6 additions & 10 deletions src/components/program/ProgramUsersTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<b-table-column field="data.email" label="Email" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ props.row.data.email }}
</b-table-column>
<b-table-column :custom-sort="sortRole" label="Role" v-slot="props" :th-attrs="(column) => ({scope:'col'})">
<b-table-column field="data.roleName" label="Role" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
<template v-if="rolesMap.size > 0">
{{ getRoleName(props.row.data.roleId) }}
</template>
Expand Down Expand Up @@ -263,7 +263,11 @@ export default class ProgramUsersTable extends Vue {
}

setSort(field: string, order: string) {
const fieldMap: any = {'data.email': UserSortField.Email, 'data.name': UserSortField.Name};
const fieldMap: any = {
'data.email': UserSortField.Email,
'data.name': UserSortField.Name,
'data.roleName': UserSortField.Roles
};
if (field in fieldMap) {
this.updateSort(new UserSort(fieldMap[field], Sort.orderAsBI(order)));
this.getUsers();
Expand Down Expand Up @@ -474,14 +478,6 @@ export default class ProgramUsersTable extends Vue {
return this.rolesMap.get(id)!.name;
}

sortRole(a: any, b: any, isAsc: boolean) {
if(isAsc) {
return this.getRoleName(a.data.roleId)!.localeCompare(this.getRoleName(b.data.roleId)!);
} else {
return this.getRoleName(b.data.roleId)!.localeCompare(this.getRoleName(a.data.roleId)!);
}
}

}

</script>
6 changes: 5 additions & 1 deletion src/store/sorting/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export const getters: GetterTree<SortState, RootState> = {
return state.programUserSort;
},
programUserSortFieldAsBuefy(state: SortState): string {
const fieldMap: any = {[UserSortField.Email]: 'data.email', [UserSortField.Name]: 'data.name'};
const fieldMap: any = {
[UserSortField.Email]: 'data.email',
[UserSortField.Name]: 'data.name',
[UserSortField.Roles]: 'data.roleName'
};
return fieldMap[state.programUserSort.field];
},
programUserSortOrderAsBuefy(state: SortState): string {
Expand Down

0 comments on commit bbe8355

Please sign in to comment.