Skip to content

Commit bf042ef

Browse files
authored
Revert "[PM-11201] Add the ability to sort by Name, Group, and Permission wit…" (#11445)
This reverts commit 37faccb.
1 parent e47415f commit bf042ef

File tree

2 files changed

+6
-168
lines changed

2 files changed

+6
-168
lines changed

apps/web/src/app/vault/components/vault-items/vault-items.component.html

+3-28
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,13 @@
1616
"all" | i18n
1717
}}</label>
1818
</th>
19-
<!-- Organization vault -->
20-
<th
21-
*ngIf="showAdminActions"
22-
bitCell
23-
bitSortable="name"
24-
[fn]="sortByName"
25-
[class]="showExtraColumn ? 'lg:tw-w-3/5' : 'tw-w-full'"
26-
>
27-
{{ "name" | i18n }}
28-
</th>
29-
<!-- Individual vault -->
30-
<th
31-
*ngIf="!showAdminActions"
32-
bitCell
33-
[class]="showExtraColumn ? 'lg:tw-w-3/5' : 'tw-w-full'"
34-
>
35-
{{ "name" | i18n }}
36-
</th>
19+
<th bitCell [class]="showExtraColumn ? 'lg:tw-w-3/5' : 'tw-w-full'">{{ "name" | i18n }}</th>
3720
<th bitCell *ngIf="showOwner" class="tw-hidden tw-w-2/5 lg:tw-table-cell">
3821
{{ "owner" | i18n }}
3922
</th>
4023
<th bitCell class="tw-w-2/5" *ngIf="showCollections">{{ "collections" | i18n }}</th>
41-
<th bitCell bitSortable="groups" [fn]="sortByGroups" class="tw-w-2/5" *ngIf="showGroups">
42-
{{ "groups" | i18n }}
43-
</th>
44-
<th
45-
bitCell
46-
bitSortable="permissions"
47-
[fn]="sortByPermissions"
48-
class="tw-w-2/5"
49-
*ngIf="showPermissionsColumn"
50-
>
24+
<th bitCell class="tw-w-2/5" *ngIf="showGroups">{{ "groups" | i18n }}</th>
25+
<th bitCell class="tw-w-2/5" *ngIf="showPermissionsColumn">
5126
{{ "permission" | i18n }}
5227
</th>
5328
<th bitCell class="tw-w-12 tw-text-right">

apps/web/src/app/vault/components/vault-items/vault-items.component.ts

+3-140
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import { SelectionModel } from "@angular/cdk/collections";
2-
import { Component, EventEmitter, inject, Input, Output } from "@angular/core";
2+
import { Component, EventEmitter, Input, Output } from "@angular/core";
33

4-
import { CollectionAdminView, Unassigned } from "@bitwarden/admin-console/common";
4+
import { Unassigned } from "@bitwarden/admin-console/common";
55
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
6-
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
76
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
87
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
98
import { TableDataSource } from "@bitwarden/components";
109

1110
import { GroupView } from "../../../admin-console/organizations/core";
1211

13-
import {
14-
CollectionPermission,
15-
convertToPermission,
16-
} from "./../../../admin-console/organizations/shared/components/access-selector/access-selector.models";
1712
import { VaultItem } from "./vault-item";
1813
import { VaultItemEvent } from "./vault-item-event";
1914

@@ -30,7 +25,6 @@ const MaxSelectionCount = 500;
3025
// changeDetection: ChangeDetectionStrategy.OnPush,
3126
})
3227
export class VaultItemsComponent {
33-
protected i18nService = inject(I18nService);
3428
protected RowHeight = RowHeight;
3529

3630
@Input() disabled: boolean;
@@ -203,7 +197,7 @@ export class VaultItemsComponent {
203197
private refreshItems() {
204198
const collections: VaultItem[] = this.collections.map((collection) => ({ collection }));
205199
const ciphers: VaultItem[] = this.ciphers.map((cipher) => ({ cipher }));
206-
let items: VaultItem[] = [].concat(collections).concat(ciphers);
200+
const items: VaultItem[] = [].concat(collections).concat(ciphers);
207201

208202
this.selection.clear();
209203

@@ -214,11 +208,6 @@ export class VaultItemsComponent {
214208
(item.collection !== undefined && item.collection.id !== Unassigned),
215209
);
216210

217-
// Apply sorting only for organization vault
218-
if (this.showAdminActions) {
219-
items = items.sort(this.sortByGroups);
220-
}
221-
222211
this.dataSource.data = items;
223212
}
224213

@@ -304,112 +293,6 @@ export class VaultItemsComponent {
304293
return false;
305294
}
306295

307-
/**
308-
* Sorts VaultItems, grouping collections before ciphers, and sorting each group alphabetically by name.
309-
*/
310-
protected sortByName = (a: VaultItem, b: VaultItem) => {
311-
const getName = (item: VaultItem) => item.collection?.name || item.cipher?.name;
312-
313-
// First, sort collections before ciphers
314-
if (a.collection && !b.collection) {
315-
return -1;
316-
}
317-
if (!a.collection && b.collection) {
318-
return 1;
319-
}
320-
321-
return getName(a).localeCompare(getName(b));
322-
};
323-
324-
/**
325-
* Sorts VaultItems based on group names
326-
*/
327-
protected sortByGroups = (a: VaultItem, b: VaultItem): number => {
328-
const getGroupNames = (item: VaultItem): string => {
329-
if (item.collection instanceof CollectionAdminView) {
330-
return item.collection.groups
331-
.map((group) => this.getGroupName(group.id))
332-
.filter(Boolean)
333-
.join(",");
334-
}
335-
336-
return "";
337-
};
338-
339-
const aGroupNames = getGroupNames(a);
340-
const bGroupNames = getGroupNames(b);
341-
342-
if (aGroupNames.length !== bGroupNames.length) {
343-
return bGroupNames.length - aGroupNames.length;
344-
}
345-
346-
return aGroupNames.localeCompare(bGroupNames);
347-
};
348-
349-
/**
350-
* Sorts VaultItems based on their permissions, with higher permissions taking precedence.
351-
* If permissions are equal, it falls back to sorting by name.
352-
*/
353-
protected sortByPermissions = (a: VaultItem, b: VaultItem): number => {
354-
const getPermissionPriority = (item: VaultItem): number => {
355-
if (item.collection instanceof CollectionAdminView) {
356-
const permission = this.getCollectionPermission(item.collection);
357-
358-
switch (permission) {
359-
case CollectionPermission.Manage:
360-
return 5;
361-
case CollectionPermission.Edit:
362-
return 4;
363-
case CollectionPermission.EditExceptPass:
364-
return 3;
365-
case CollectionPermission.View:
366-
return 2;
367-
case CollectionPermission.ViewExceptPass:
368-
return 1;
369-
case "NoAccess":
370-
return 0;
371-
}
372-
}
373-
374-
return -1;
375-
};
376-
377-
const priorityA = getPermissionPriority(a);
378-
const priorityB = getPermissionPriority(b);
379-
380-
// Higher priority first
381-
if (priorityA !== priorityB) {
382-
return priorityB - priorityA;
383-
}
384-
385-
return this.sortByName(a, b);
386-
};
387-
388-
/**
389-
* Default sorting function for vault items.
390-
* Sorts by: 1. Collections before ciphers
391-
* 2. Highest permission first
392-
* 3. Alphabetical order of collections and ciphers
393-
*/
394-
private defaultSort = (a: VaultItem, b: VaultItem) => {
395-
// First, sort collections before ciphers
396-
if (a.collection && !b.collection) {
397-
return -1;
398-
}
399-
if (!a.collection && b.collection) {
400-
return 1;
401-
}
402-
403-
// Next, sort by permissions
404-
const permissionSort = this.sortByPermissions(a, b);
405-
if (permissionSort !== 0) {
406-
return permissionSort;
407-
}
408-
409-
// Finally, sort by name
410-
return this.sortByName(a, b);
411-
};
412-
413296
private hasPersonalItems(): boolean {
414297
return this.selection.selected.some(({ cipher }) => cipher?.organizationId === null);
415298
}
@@ -423,24 +306,4 @@ export class VaultItemsComponent {
423306
private getUniqueOrganizationIds(): Set<string> {
424307
return new Set(this.selection.selected.flatMap((i) => i.cipher?.organizationId ?? []));
425308
}
426-
427-
private getGroupName(groupId: string): string | undefined {
428-
return this.allGroups.find((g) => g.id === groupId)?.name;
429-
}
430-
431-
private getCollectionPermission(
432-
collection: CollectionAdminView,
433-
): CollectionPermission | "NoAccess" {
434-
const organization = this.allOrganizations.find((o) => o.id === collection.organizationId);
435-
436-
if (collection.id == Unassigned && organization?.canEditUnassignedCiphers) {
437-
return CollectionPermission.Edit;
438-
}
439-
440-
if (collection.assigned) {
441-
return convertToPermission(collection);
442-
}
443-
444-
return "NoAccess";
445-
}
446309
}

0 commit comments

Comments
 (0)