mirror of
https://github.com/bitwarden/browser
synced 2026-02-19 10:54:00 +00:00
[PM-31155] reorder policies in policies page (#18564)
* Refactor policy edit registration to centralize ownership and improve organization. Reordered policies for clarity and added new policies for enhanced functionality. * Add PolicyOrderPipe for sorting policies and update policies component to utilize it * Add organizationDataOwnership to POLICY_ORDER_MAP for policy sorting * Fix PR comments
This commit is contained in:
@@ -5,3 +5,4 @@ export { POLICY_EDIT_REGISTER } from "./policy-register-token";
|
||||
export { AutoConfirmPolicy } from "./policy-edit-definitions";
|
||||
export { PolicyEditDialogResult } from "./policy-edit-dialog.component";
|
||||
export * from "./policy-edit-dialogs";
|
||||
export { PolicyOrderPipe } from "./pipes/policy-order.pipe";
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Pipe, PipeTransform } from "@angular/core";
|
||||
|
||||
import { BasePolicyEditDefinition } from "../base-policy-edit.component";
|
||||
|
||||
/**
|
||||
* Order mapping for policies. Policies are ordered according to this mapping.
|
||||
* Policies not in this mapping will appear at the end, maintaining their relative order.
|
||||
*/
|
||||
const POLICY_ORDER_MAP = new Map<string, number>([
|
||||
["singleOrg", 1],
|
||||
["organizationDataOwnership", 2],
|
||||
["centralizeDataOwnership", 2],
|
||||
["masterPassPolicyTitle", 3],
|
||||
["accountRecoveryPolicy", 4],
|
||||
["requireSso", 5],
|
||||
["automaticAppLoginWithSSO", 6],
|
||||
["twoStepLoginPolicyTitle", 7],
|
||||
["blockClaimedDomainAccountCreation", 8],
|
||||
["sessionTimeoutPolicyTitle", 9],
|
||||
["removeUnlockWithPinPolicyTitle", 10],
|
||||
["passwordGenerator", 11],
|
||||
["uriMatchDetectionPolicy", 12],
|
||||
["activateAutofill", 13],
|
||||
["sendOptions", 14],
|
||||
["disableSend", 15],
|
||||
["restrictedItemTypePolicy", 16],
|
||||
["freeFamiliesSponsorship", 17],
|
||||
["disableExport", 18],
|
||||
]);
|
||||
|
||||
/**
|
||||
* Default order for policies not in the mapping. This ensures unmapped policies
|
||||
* appear at the end while maintaining their relative order.
|
||||
*/
|
||||
const DEFAULT_ORDER = 999;
|
||||
|
||||
@Pipe({
|
||||
name: "policyOrder",
|
||||
standalone: true,
|
||||
})
|
||||
export class PolicyOrderPipe implements PipeTransform {
|
||||
transform(
|
||||
policies: readonly BasePolicyEditDefinition[] | null | undefined,
|
||||
): BasePolicyEditDefinition[] {
|
||||
if (policies == null || policies.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const sortedPolicies = [...policies];
|
||||
|
||||
sortedPolicies.sort((a, b) => {
|
||||
const orderA = POLICY_ORDER_MAP.get(a.name) ?? DEFAULT_ORDER;
|
||||
const orderB = POLICY_ORDER_MAP.get(b.name) ?? DEFAULT_ORDER;
|
||||
|
||||
if (orderA !== orderB) {
|
||||
return orderA - orderB;
|
||||
}
|
||||
|
||||
const indexA = policies.indexOf(a);
|
||||
const indexB = policies.indexOf(b);
|
||||
return indexA - indexB;
|
||||
});
|
||||
|
||||
return sortedPolicies;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
} @else {
|
||||
<bit-table>
|
||||
<ng-template body>
|
||||
@for (p of policies$ | async; track $index) {
|
||||
@for (p of policies$ | async | policyOrder; track $index) {
|
||||
@if (p.display$(organization, configService) | async) {
|
||||
<tr bitRow>
|
||||
<td bitCell ngPreserveWhitespaces>
|
||||
|
||||
@@ -21,13 +21,14 @@ import { HeaderModule } from "../../../layouts/header/header.module";
|
||||
import { SharedModule } from "../../../shared";
|
||||
|
||||
import { BasePolicyEditDefinition, PolicyDialogComponent } from "./base-policy-edit.component";
|
||||
import { PolicyOrderPipe } from "./pipes/policy-order.pipe";
|
||||
import { PolicyEditDialogComponent } from "./policy-edit-dialog.component";
|
||||
import { PolicyListService } from "./policy-list.service";
|
||||
import { POLICY_EDIT_REGISTER } from "./policy-register-token";
|
||||
|
||||
@Component({
|
||||
templateUrl: "policies.component.html",
|
||||
imports: [SharedModule, HeaderModule],
|
||||
imports: [SharedModule, HeaderModule, PolicyOrderPipe],
|
||||
providers: [
|
||||
safeProvider({
|
||||
provide: PolicyListService,
|
||||
|
||||
Reference in New Issue
Block a user