[PM-46826] Fix role ordering (#24729)

* Fix role ordering

* Cuts comment down to 1 line
This commit is contained in:
Jared
2026-11-13 15:20:09 -05:00
committed by GitHub
parent 892283f4f7
commit 06ba95dd36
4 changed files with 29 additions and 5 deletions

View File

@@ -41,11 +41,11 @@ export type MemberFilters = {
policies?: PolicyOption[];
};
/** The roles offered in the Role filter, in display order. */
/** The roles offered in the Role filter, in display order. Also the Role column sort order. */
export const ROLE_OPTIONS: readonly { value: OrganizationUserType; labelKey: string }[] = [
{ value: OrganizationUserType.Owner, labelKey: "owner" },
{ value: OrganizationUserType.Admin, labelKey: "admin" },
{ value: OrganizationUserType.User, labelKey: "user" },
{ value: OrganizationUserType.Admin, labelKey: "admin" },
{ value: OrganizationUserType.Owner, labelKey: "owner" },
{ value: OrganizationUserType.Custom, labelKey: "custom" },
];

View File

@@ -207,7 +207,7 @@
</bit-column>
<!-- Role -->
<bit-column sortable width="minmax(120px, 1fr)">
<bit-column sortable [sortFn]="sortByRole" width="minmax(120px, 1fr)">
<bit-header-cell>{{ "role" | i18n }}</bit-header-cell>
<!-- Matches v1: clicking the role cell opens the member dialog on the role tab. -->
<bit-cell

View File

@@ -271,6 +271,22 @@ describe("MembersV2Component", () => {
]);
});
it("sorts by role in filter order", () => {
const rows = [
OrganizationUserType.Custom,
OrganizationUserType.Owner,
OrganizationUserType.Admin,
OrganizationUserType.User,
].map((type) => member({ type }));
expect(rows.sort(component.sortByRole).map((r) => r.type)).toEqual([
OrganizationUserType.User,
OrganizationUserType.Admin,
OrganizationUserType.Owner,
OrganizationUserType.Custom,
]);
});
it("sorts groups by the first group, then by how many there are", () => {
const rows = [
member({ id: "b" as Guid, groupNames: ["Sales"] }),

View File

@@ -27,7 +27,7 @@ import { RegistrationUserAddIcon, SearchFolder } from "@bitwarden/assets/svg";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { OrganizationUserType, PolicyType } from "@bitwarden/common/admin-console/enums";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
@@ -604,6 +604,9 @@ export class MembersV2Component {
protected readonly sortByStatus = (a: OrganizationUserView, b: OrganizationUserView) =>
statusOrder(a.status) - statusOrder(b.status);
protected readonly sortByRole = (a: OrganizationUserView, b: OrganizationUserView) =>
roleOrder(a.type) - roleOrder(b.type);
/** Orders by the first name shown in the badge, then by how many more there are. */
protected readonly sortByFirstName = (a: string[], b: string[]) =>
this.compareText(a[0] ?? "", b[0] ?? "") || a.length - b.length;
@@ -645,3 +648,8 @@ function statusOrder(status: OrganizationUserStatusType): number {
const index = STATUS_BADGES.findIndex((badge) => badge.status === status);
return index === -1 ? STATUS_BADGES.length : index;
}
function roleOrder(type: OrganizationUserType): number {
const index = ROLE_OPTIONS.findIndex((role) => role.value === type);
return index === -1 ? ROLE_OPTIONS.length : index;
}