Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes on paper notification #296

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/browser/src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion apps/browser/src/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface AddPaperSavedQueueMessage extends NotificationQueueMessage {
type: "paper-saved";
paperSavedId: string;
paperSavedQualification: string;
paperSavedQualificationLabel: string;
}
// Cozy customization end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -413,6 +415,7 @@ export default class NotificationBackground {
wasVaultLocked: false,
paperSavedId: options.paperSavedId,
paperSavedQualification: options.paperSavedQualification,
paperSavedQualificationLabel: options.paperSavedQualificationLabel,
};
await this.sendNotificationQueueMessage(tab, message);
}
Expand Down
24 changes: 18 additions & 6 deletions apps/browser/src/autofill/background/overlay.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ 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";
import { nameToColor } from "cozy-ui/transpiled/react/Avatar/helpers";
import { CozyClientService } from "../../popup/services/cozyClient.service";
import { AmbiguousContactFieldName, AmbiguousContactFieldValue } from "src/autofill/types";
Expand All @@ -85,6 +84,11 @@ import {
cleanFormattedAddress,
} from "../../../../../libs/cozy/contact.helper";
import NotificationBackground from "./notification.background";
import { CONTACTS_DOCTYPE, FILES_DOCTYPE } from "../../../../../libs/cozy/constants";

const {
document: { locales },
} = models;
/* eslint-enable */
/* end Cozy imports */

Expand Down Expand Up @@ -1052,10 +1056,18 @@ export class OverlayBackground implements OverlayBackgroundInterface {
logService: this.logService,
});

await this.notificationBackground.paperSaved(port.sender.tab, {
paperSavedId: createdOrUpdatedCozyDoctype._id,
paperSavedQualification: createdOrUpdatedCozyDoctype.metadata.qualification.label,
});
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}`,
),
});
}

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.
Expand Down
1 change: 1 addition & 0 deletions apps/browser/src/autofill/content/notification-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ async function loadNotificationBar() {
importType: typeData.importType,
paperSavedId: typeData.paperSavedId,
paperSavedQualification: typeData.paperSavedQualification,
paperSavedQualificationLabel: typeData.paperSavedQualificationLabel,
};
const notificationBarUrl = "notification/bar.html";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type NotificationBarIframeInitData = {
importType?: string;
paperSavedId?: string;
paperSavedQualification?: string;
paperSavedQualificationLabel?: string;
};

type NotificationBarWindowMessage = {
Expand Down
5 changes: 4 additions & 1 deletion apps/browser/src/autofill/notification/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading