From aaded45a8b57100c1017ba83cf5168ebccb0bbe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Wed, 9 Oct 2024 10:18:08 +0200 Subject: [PATCH 1/4] feat: Add qualification label in paper saved notification --- apps/browser/src/_locales/en/messages.json | 8 +++++++- apps/browser/src/_locales/fr/messages.json | 8 +++++++- .../background/abstractions/notification.background.ts | 1 + .../src/autofill/background/notification.background.ts | 3 +++ .../src/autofill/background/overlay.background.ts | 10 +++++++++- apps/browser/src/autofill/content/notification-bar.ts | 1 + .../notification/abstractions/notification-bar.ts | 1 + apps/browser/src/autofill/notification/bar.ts | 5 ++++- 8 files changed, 33 insertions(+), 4 deletions(-) diff --git a/apps/browser/src/_locales/en/messages.json b/apps/browser/src/_locales/en/messages.json index 87c78bfb562..f71e0ff1e53 100755 --- a/apps/browser/src/_locales/en/messages.json +++ b/apps/browser/src/_locales/en/messages.json @@ -980,7 +980,13 @@ "description": "Clipboard is the operating system thing where you copy/paste data to on your device." }, "notificationPaperSavedDesc": { - "message": "A new document with the information entered has just been added to your Cozy's My Papers application." + "message": "A new $VALUE$ document with the information entered has just been added to your Cozy's My Papers application.", + "placeholders": { + "value": { + "content": "$1", + "example": "Identity card" + } + } }, "notificationPaperSavedUnderstood": { "message": "Understood" diff --git a/apps/browser/src/_locales/fr/messages.json b/apps/browser/src/_locales/fr/messages.json index 58ebf1e5563..636d895ba0b 100755 --- a/apps/browser/src/_locales/fr/messages.json +++ b/apps/browser/src/_locales/fr/messages.json @@ -980,7 +980,13 @@ "description": "Clipboard is the operating system thing where you copy/paste data to on your device." }, "notificationPaperSavedDesc": { - "message": "Un nouveau document avec l'information saisie vient d'être ajouté dans l'application Mes Papiers de votre Cozy." + "message": "Un nouveau document $VALUE$ avec l'information saisie vient d'être ajouté dans l'application Mes Papiers de votre Cozy.", + "placeholders": { + "value": { + "content": "$1", + "example": "Carte d'identité" + } + } }, "notificationPaperSavedUnderstood": { "message": "J'ai compris" diff --git a/apps/browser/src/autofill/background/abstractions/notification.background.ts b/apps/browser/src/autofill/background/abstractions/notification.background.ts index 1cb68e212eb..52b9f0a4bb9 100644 --- a/apps/browser/src/autofill/background/abstractions/notification.background.ts +++ b/apps/browser/src/autofill/background/abstractions/notification.background.ts @@ -18,6 +18,7 @@ interface AddPaperSavedQueueMessage extends NotificationQueueMessage { type: "paper-saved"; paperSavedId: string; paperSavedQualification: string; + paperSavedQualificationLabel: string; } // Cozy customization end; diff --git a/apps/browser/src/autofill/background/notification.background.ts b/apps/browser/src/autofill/background/notification.background.ts index 984396f046a..93116feaaa1 100644 --- a/apps/browser/src/autofill/background/notification.background.ts +++ b/apps/browser/src/autofill/background/notification.background.ts @@ -205,6 +205,8 @@ export default class NotificationBackground { case NotificationQueueMessageType.PaperSaved: typeData.paperSavedId = notificationQueueMessage.paperSavedId; typeData.paperSavedQualification = notificationQueueMessage.paperSavedQualification; + typeData.paperSavedQualificationLabel = + notificationQueueMessage.paperSavedQualificationLabel; break; // Cozy customization end; case NotificationQueueMessageType.AddLogin: @@ -413,6 +415,7 @@ export default class NotificationBackground { wasVaultLocked: false, paperSavedId: options.paperSavedId, paperSavedQualification: options.paperSavedQualification, + paperSavedQualificationLabel: options.paperSavedQualificationLabel, }; await this.sendNotificationQueueMessage(tab, message); } diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index c7a346a0071..b029bcaf302 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -69,7 +69,7 @@ import { /* start Cozy imports */ /* eslint-disable */ -import { Q } from "cozy-client"; +import { Q, models } from "cozy-client"; import { IOCozyContact } from "cozy-client/types/types"; // @ts-ignore import { CONTACTS_DOCTYPE } from "cozy-client/dist/models/contact"; @@ -85,6 +85,10 @@ import { cleanFormattedAddress, } from "../../../../../libs/cozy/contact.helper"; import NotificationBackground from "./notification.background"; + +const { + document: { locales }, +} = models; /* eslint-enable */ /* end Cozy imports */ @@ -1052,9 +1056,13 @@ export class OverlayBackground implements OverlayBackgroundInterface { logService: this.logService, }); + const locale = this.i18nService.translationLocale || "en"; + const t = locales.getBoundT(locale); + await this.notificationBackground.paperSaved(port.sender.tab, { paperSavedId: createdOrUpdatedCozyDoctype._id, paperSavedQualification: createdOrUpdatedCozyDoctype.metadata.qualification.label, + paperSavedQualificationLabel: t(`Scan.items.${createdOrUpdatedCozyDoctype.metadata.qualification.label}`), }); const isAddress = inputValues.values.some((inputValue) => inputValue.key === "street"); diff --git a/apps/browser/src/autofill/content/notification-bar.ts b/apps/browser/src/autofill/content/notification-bar.ts index 1479b3ad59c..e6e786c7c0e 100644 --- a/apps/browser/src/autofill/content/notification-bar.ts +++ b/apps/browser/src/autofill/content/notification-bar.ts @@ -841,6 +841,7 @@ async function loadNotificationBar() { importType: typeData.importType, paperSavedId: typeData.paperSavedId, paperSavedQualification: typeData.paperSavedQualification, + paperSavedQualificationLabel: typeData.paperSavedQualificationLabel, }; const notificationBarUrl = "notification/bar.html"; diff --git a/apps/browser/src/autofill/notification/abstractions/notification-bar.ts b/apps/browser/src/autofill/notification/abstractions/notification-bar.ts index 8f6cdc92189..d2b1e2d327f 100644 --- a/apps/browser/src/autofill/notification/abstractions/notification-bar.ts +++ b/apps/browser/src/autofill/notification/abstractions/notification-bar.ts @@ -6,6 +6,7 @@ type NotificationBarIframeInitData = { importType?: string; paperSavedId?: string; paperSavedQualification?: string; + paperSavedQualificationLabel?: string; }; type NotificationBarWindowMessage = { diff --git a/apps/browser/src/autofill/notification/bar.ts b/apps/browser/src/autofill/notification/bar.ts index f7836a0984a..193a522955a 100644 --- a/apps/browser/src/autofill/notification/bar.ts +++ b/apps/browser/src/autofill/notification/bar.ts @@ -47,7 +47,10 @@ function initNotificationBar(message: NotificationBarWindowMessage) { never: chrome.i18n.getMessage("never"), folder: chrome.i18n.getMessage("folder"), // Cozy customization; paper saved notification - notificationPaperSavedDesc: chrome.i18n.getMessage("notificationPaperSavedDesc"), + notificationPaperSavedDesc: chrome.i18n.getMessage( + "notificationPaperSavedDesc", + notificationBarIframeInitData.paperSavedQualificationLabel, + ), notificationPaperSavedUnderstood: chrome.i18n.getMessage("notificationPaperSavedUnderstood"), notificationPaperSavedSee: chrome.i18n.getMessage("notificationPaperSavedSee"), // Cozy customization end; From c959d6e36fd641c1638bfa9d921fa18e3c8fbf30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Wed, 9 Oct 2024 10:23:04 +0200 Subject: [PATCH 2/4] fix: Show paper saved notification only if it is a paper --- .../autofill/background/overlay.background.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index b029bcaf302..e81de75c20f 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -72,7 +72,6 @@ import { import { Q, models } from "cozy-client"; import { IOCozyContact } from "cozy-client/types/types"; // @ts-ignore -import { CONTACTS_DOCTYPE } from "cozy-client/dist/models/contact"; import { nameToColor } from "cozy-ui/transpiled/react/Avatar/helpers"; import { CozyClientService } from "../../popup/services/cozyClient.service"; import { AmbiguousContactFieldName, AmbiguousContactFieldValue } from "src/autofill/types"; @@ -85,6 +84,7 @@ import { cleanFormattedAddress, } from "../../../../../libs/cozy/contact.helper"; import NotificationBackground from "./notification.background"; +import { CONTACTS_DOCTYPE, FILES_DOCTYPE } from "../../../../../libs/cozy/constants"; const { document: { locales }, @@ -1056,14 +1056,18 @@ export class OverlayBackground implements OverlayBackgroundInterface { logService: this.logService, }); - const locale = this.i18nService.translationLocale || "en"; - const t = locales.getBoundT(locale); + if (createdOrUpdatedCozyDoctype._type === FILES_DOCTYPE) { + const locale = this.i18nService.translationLocale || "en"; + const t = locales.getBoundT(locale); - await this.notificationBackground.paperSaved(port.sender.tab, { - paperSavedId: createdOrUpdatedCozyDoctype._id, - paperSavedQualification: createdOrUpdatedCozyDoctype.metadata.qualification.label, - paperSavedQualificationLabel: t(`Scan.items.${createdOrUpdatedCozyDoctype.metadata.qualification.label}`), - }); + await this.notificationBackground.paperSaved(port.sender.tab, { + paperSavedId: createdOrUpdatedCozyDoctype._id, + paperSavedQualification: createdOrUpdatedCozyDoctype.metadata.qualification.label, + paperSavedQualificationLabel: t( + `Scan.items.${createdOrUpdatedCozyDoctype.metadata.qualification.label}`, + ), + }); + } const isAddress = inputValues.values.some((inputValue) => inputValue.key === "street"); // If is an address, we need set the value of the field to the formatted address, because getCozyValue refers to `formattedAddress` to return values corresponding to the postal address. From afcae659a0de865e087350626134f86db3fe8e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Wed, 9 Oct 2024 14:55:28 +0200 Subject: [PATCH 3/4] fix: Autofill on popup for paper --- .../vault/popup/components/vault/current-tab.component.ts | 5 ++++- .../vault/popup/components/vault/vault-items.component.ts | 5 ++++- .../src/vault/popup/components/vault/view.component.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/browser/src/vault/popup/components/vault/current-tab.component.ts b/apps/browser/src/vault/popup/components/vault/current-tab.component.ts index abdc0c9b8c1..11cd26e0731 100644 --- a/apps/browser/src/vault/popup/components/vault/current-tab.component.ts +++ b/apps/browser/src/vault/popup/components/vault/current-tab.component.ts @@ -262,7 +262,10 @@ export class CurrentTabComponent implements OnInit, OnDestroy { // Cozy customization; send doAutoFill to background because // doAutoFill needs a Cozy Client store with all the contacts // and only the background Cozy Client store has them on Manifest V3 - if (cipher.type === CipherType.Contact && BrowserApi.isManifestVersion(3)) { + if ( + (cipher.type === CipherType.Contact || cipher.type === CipherType.Paper) && + BrowserApi.isManifestVersion(3) + ) { this.messageSender.send("doAutoFill", { autofillOptions: { tab: this.tab, diff --git a/apps/browser/src/vault/popup/components/vault/vault-items.component.ts b/apps/browser/src/vault/popup/components/vault/vault-items.component.ts index bb032ecd168..732966d22fa 100644 --- a/apps/browser/src/vault/popup/components/vault/vault-items.component.ts +++ b/apps/browser/src/vault/popup/components/vault/vault-items.component.ts @@ -461,7 +461,10 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnIn // Cozy customization; send doAutoFill to background because // doAutoFill needs a Cozy Client store with all the contacts // and only the background Cozy Client store has them on Manifest V3 - if (cipher.type === CipherType.Contact && BrowserApi.isManifestVersion(3)) { + if ( + (cipher.type === CipherType.Contact || cipher.type === CipherType.Paper) && + BrowserApi.isManifestVersion(3) + ) { this.messageSender.send("doAutoFill", { autofillOptions: { cipher: cipher, diff --git a/apps/browser/src/vault/popup/components/vault/view.component.ts b/apps/browser/src/vault/popup/components/vault/view.component.ts index 8552f544e5a..be7c851804b 100644 --- a/apps/browser/src/vault/popup/components/vault/view.component.ts +++ b/apps/browser/src/vault/popup/components/vault/view.component.ts @@ -512,7 +512,10 @@ export class ViewComponent extends BaseViewComponent implements OnInit, OnDestro // Cozy customization; send doAutoFill to background because // doAutoFill needs a Cozy Client store with all the contacts // and only the background Cozy Client store has them on Manifest V3 - if (this.cipher.type === CipherType.Contact && BrowserApi.isManifestVersion(3)) { + if ( + (this.cipher.type === CipherType.Contact || this.cipher.type === CipherType.Paper) && + BrowserApi.isManifestVersion(3) + ) { this.messageSender.send("doAutoFill", { autofillOptions: { tab: this.tab, From f394523d5c1a93ca9321a91370340772929a9771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Wed, 9 Oct 2024 15:36:13 +0200 Subject: [PATCH 4/4] fix: Alignment of radio in paper list --- .../overlay/inline-menu/pages/list/autofill-inline-menu-list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/browser/src/autofill/overlay/inline-menu/pages/list/autofill-inline-menu-list.ts b/apps/browser/src/autofill/overlay/inline-menu/pages/list/autofill-inline-menu-list.ts index 1a859ff6524..24ba7aaadc7 100644 --- a/apps/browser/src/autofill/overlay/inline-menu/pages/list/autofill-inline-menu-list.ts +++ b/apps/browser/src/autofill/overlay/inline-menu/pages/list/autofill-inline-menu-list.ts @@ -864,7 +864,7 @@ export class AutofillInlineMenuList extends AutofillInlineMenuPageElement { radio.setAttribute("type", "radio"); radio.setAttribute("name", "contact"); radio.setAttribute("id", "contact"); - radio.style.marginRight = "2rem"; + radio.classList.add("fill-cipher-contact-radio"); const detailsSpan = document.createElement("span"); detailsSpan.classList.add("cipher-details");