|
1 | | -// FIXME: Update this file to be type safe and remove this and next line |
2 | | -// @ts-strict-ignore |
3 | | -import { Component, Input, OnChanges } from "@angular/core"; |
| 1 | +import { ChangeDetectionStrategy, Component, computed, input } from "@angular/core"; |
4 | 2 |
|
5 | 3 | import { SelectionReadOnlyRequest } from "@bitwarden/common/admin-console/models/request/selection-read-only.request"; |
6 | 4 | import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; |
7 | 5 |
|
8 | 6 | import { GroupView } from "../../core"; |
9 | 7 |
|
10 | | -// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush |
11 | | -// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection |
12 | 8 | @Component({ |
13 | 9 | selector: "app-group-badge", |
14 | 10 | templateUrl: "group-name-badge.component.html", |
15 | 11 | standalone: false, |
| 12 | + changeDetection: ChangeDetectionStrategy.OnPush, |
16 | 13 | }) |
17 | | -export class GroupNameBadgeComponent implements OnChanges { |
18 | | - // FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals |
19 | | - // eslint-disable-next-line @angular-eslint/prefer-signals |
20 | | - @Input() selectedGroups: SelectionReadOnlyRequest[]; |
21 | | - // FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals |
22 | | - // eslint-disable-next-line @angular-eslint/prefer-signals |
23 | | - @Input() allGroups: GroupView[]; |
| 14 | +export class GroupNameBadgeComponent { |
| 15 | + readonly selectedGroups = input<SelectionReadOnlyRequest[]>([]); |
| 16 | + readonly allGroups = input<GroupView[]>([]); |
24 | 17 |
|
25 | | - protected groupNames: string[] = []; |
| 18 | + protected readonly groupNames = computed(() => { |
| 19 | + const allGroups = this.allGroups(); |
| 20 | + if (!allGroups) { |
| 21 | + return []; |
| 22 | + } |
26 | 23 |
|
27 | | - constructor(private i18nService: I18nService) {} |
28 | | - |
29 | | - ngOnChanges() { |
30 | | - this.groupNames = this.selectedGroups |
| 24 | + return this.selectedGroups() |
31 | 25 | .map((g) => { |
32 | | - return this.allGroups.find((o) => o.id === g.id)?.name; |
| 26 | + return allGroups.find((o) => o.id === g.id)?.name; |
33 | 27 | }) |
| 28 | + .filter((name): name is string => name !== undefined) |
34 | 29 | .sort(this.i18nService.collator.compare); |
35 | | - } |
| 30 | + }); |
| 31 | + |
| 32 | + constructor(private i18nService: I18nService) {} |
36 | 33 | } |
0 commit comments