From d6a6dedbba06d94daa7806b85b0aba744424a998 Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Tue, 8 Nov 2022 21:56:27 -0500 Subject: [PATCH] [PS-1843] Sort organizations in `buildOrganizations` (#4015) * Sort organizations in buildOrganizations * Add sort by name to Organization Switcher --- .../app/components/organization-switcher.component.ts | 6 ++++-- .../vault/vault-filter/services/vault-filter.service.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/web/src/app/components/organization-switcher.component.ts b/apps/web/src/app/components/organization-switcher.component.ts index ba6c04920ba..70ea6385fe2 100644 --- a/apps/web/src/app/components/organization-switcher.component.ts +++ b/apps/web/src/app/components/organization-switcher.component.ts @@ -1,11 +1,12 @@ import { Component, Input, OnInit } from "@angular/core"; -import { Observable } from "rxjs"; +import { map, Observable } from "rxjs"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { canAccessAdmin, OrganizationService, } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; +import { Utils } from "@bitwarden/common/misc/utils"; import { Organization } from "@bitwarden/common/models/domain/organization"; @Component({ @@ -22,7 +23,8 @@ export class OrganizationSwitcherComponent implements OnInit { async ngOnInit() { this.organizations$ = this.organizationService.organizations$.pipe( - canAccessAdmin(this.i18nService) + canAccessAdmin(this.i18nService), + map((orgs) => orgs.sort(Utils.getSortFunction(this.i18nService, "name"))) ); this.loaded = true; diff --git a/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts b/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts index 995ff1a12a5..5f33a8b78ac 100644 --- a/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts +++ b/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts @@ -37,8 +37,13 @@ export class VaultFilterService { return new Set(await this.stateService.getCollapsedGroupings()); } - buildOrganizations(): Promise { - return this.organizationService.getAll(); + async buildOrganizations(): Promise { + let organizations = await this.organizationService.getAll(); + if (organizations != null) { + organizations = organizations.sort((a, b) => a.name.localeCompare(b.name)); + } + + return organizations; } buildNestedFolders(organizationId?: string): Observable> {