Skip to content

Commit

Permalink
feat: Add a new component to display contact labels
Browse files Browse the repository at this point in the history
io.cozy.contacts label management has been improved. A phone number, an address or an email can have :
- a type which can be "cell", "voice", "fax" or a custom string
- a label which can be "home" or "work"
- both

See io.cozy.contacts documentation to learn more.

Here we introduce and use a new component to display correctly the label value.

We also modify our types to correspond to io.cozy.contacts.
  • Loading branch information
zatteo committed Apr 20, 2024
1 parent 8407119 commit 3e718c3
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 6 deletions.
15 changes: 15 additions & 0 deletions apps/browser/src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2423,5 +2423,20 @@
},
"encryptedInfoDismiss": {
"message": "I understand"
},
"home": {
"message": "Home"
},
"work": {
"message": "Work"
},
"cell": {
"message": "Cell"
},
"voice": {
"message": "Voice"
},
"fax": {
"message": "Fax"
}
}
15 changes: 15 additions & 0 deletions apps/browser/src/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2471,5 +2471,20 @@
},
"encryptedInfoDismiss": {
"message": "J'ai compris"
},
"home": {
"message": "Perso"
},
"work": {
"message": "Pro"
},
"cell": {
"message": "Mobile"
},
"voice": {
"message": "Fixe"
},
"fax": {
"message": "Fax"
}
}
2 changes: 2 additions & 0 deletions apps/browser/src/popup/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { FlagConditionalComponent } from "../cozy/components/flag-conditional/fl
import { IfFlagDirective } from "../cozy/components/flag-conditional/if-flag.directive";
import { AddGenericComponent } from "../cozy/components/add-generic/add-generic.component";
import { ViewExpirationDateComponent } from "../vault/popup/components/vault/view-expiration-date.component";
import { ViewLabelComponent } from "../vault/popup/components/vault/view-label.component";
import { ContactAvatarComponent } from "../vault/popup/components/vault/contact-avatar.component";
import { ProfilesMigrationComponent } from "../cozy/components/profiles-migration/profiles-migration.component";
import { EncryptedInfoComponent } from "../cozy/components/encrypted-info/encrypted-info.component";
Expand Down Expand Up @@ -170,6 +171,7 @@ import { EncryptedInfoComponent } from "../cozy/components/encrypted-info/encryp
IfFlagDirective,
AddGenericComponent,
ViewExpirationDateComponent,
ViewLabelComponent,
ContactAvatarComponent,
ProfilesMigrationComponent,
EncryptedInfoComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ <h2 class="box-header">
(dragstart)="setTextDataOnDrag($event, field.value)"
>
{{ field.name }}
<span *ngIf="field.label" aria-hidden="true"> · </span>
<span *ngIf="field.label">
{{ field.label.type }}
</span>
<app-vault-view-label *ngIf="field.label" [label]="field.label"></app-vault-view-label>
</span>
<!-- Cozy customization end -->
<span *ngIf="field.type === fieldType.Linked" class="row-label">{{ field.name }}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span aria-hidden="true"> · {{ this.stringifiedLabel }}</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Component, Input, OnInit } from "@angular/core";

import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LabelData } from "@bitwarden/common/vault/models/data/label.data";

@Component({
selector: "app-vault-view-label",
templateUrl: "./view-label.component.html",
})
export class ViewLabelComponent implements OnInit {
@Input() label: LabelData;
stringifiedLabel: string;

constructor(private i18nService: I18nService) {}

ngOnInit(): void {
if (this.label.type && !this.label.label) {
this.stringifiedLabel = this.getTranslatedType(this.label.type);
} else if (!this.label.type && this.label.label) {
this.stringifiedLabel = this.getTranslatedLabel(this.label.label);
} else if (this.label.type && this.label.label) {
this.stringifiedLabel = `${this.getTranslatedType(
this.label.type
)} (${this.getTranslatedLabel(this.label.label).toLowerCase()})`;
}
}

getTranslatedType(type: string) {
return ["cell", "voice", "fax"].includes(type) ? this.i18nService.translate(type) : type;
}

getTranslatedLabel(label: string) {
return this.i18nService.translate(label);
}
}
2 changes: 1 addition & 1 deletion libs/common/src/vault/models/data/label.data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Cozy customization
export type LabelData = {
type: string;
type?: string;
label?: "home" | "work";
};
// Cozy customization end
2 changes: 1 addition & 1 deletion libs/cozy/fields.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const buildContactField = ({

const fieldOptions: FieldOptions = {};

if (type) {
if (type || label) {
fieldOptions.label = {
type,
label,
Expand Down

0 comments on commit 3e718c3

Please sign in to comment.