-
Notifications
You must be signed in to change notification settings - Fork 479
[LWD] feat(contacts): render desktop contact edit and delete actions #20281
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
Merged
+1,252
β213
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
315 changes: 105 additions & 210 deletions
315
...er-live-desktop/src/mvvm/features/Contacts/__integrations__/Contacts.integration.test.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
apps/ledger-live-desktop/src/mvvm/features/Contacts/hooks/useContactsEditDeletePorts.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { | ||
| deleteContact as deleteContactAction, | ||
| parseContactName, | ||
| renameContact as renameContactAction, | ||
| selectContactById, | ||
| } from "@domain/entity-contact"; | ||
| import { useMemo } from "react"; | ||
| import type { ContactDetailActionsPorts } from "@features/flow-contacts"; | ||
| import { useDispatch, useStore } from "LLD/hooks/redux"; | ||
|
|
||
| export function useContactsEditDeletePorts(): ContactDetailActionsPorts { | ||
| const dispatch = useDispatch(); | ||
| const store = useStore(); | ||
|
|
||
| return useMemo<ContactDetailActionsPorts>( | ||
| () => ({ | ||
| edit: { | ||
| renameContact: async ({ contactId, name }) => { | ||
| dispatch(renameContactAction({ contactId, name: parseContactName(name) })); | ||
| const updatedContact = selectContactById(store.getState(), contactId); | ||
|
|
||
| if (updatedContact === undefined) { | ||
| throw new Error("Contact not found"); | ||
| } | ||
|
|
||
| return updatedContact; | ||
| }, | ||
| }, | ||
| deletion: { | ||
| deleteContact: async contactIdToDelete => { | ||
| dispatch(deleteContactAction(contactIdToDelete)); | ||
| }, | ||
| }, | ||
| }), | ||
| [dispatch, store], | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...-desktop/src/mvvm/features/Contacts/screens/Contacts/useContactDetailEditDeleteAdapter.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { | ||
| ContactIdSchema, | ||
| INVALID_CONTACT_NAME_ERROR_NAME, | ||
| type ContactId, | ||
| } from "@domain/entity-contact"; | ||
| import { | ||
| type ContactsDeleteContactDialogProps, | ||
| type ContactsEditSignerDialogProps, | ||
| type ContactsRenameContactDialogProps, | ||
| type ContactDetailActionsLabels, | ||
| useContactDetailEditDeleteFlowViewModel, | ||
| useRenameContactDialogViewModel, | ||
| } from "@features/flow-contacts"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { useContactsEditDeletePorts } from "../../hooks/useContactsEditDeletePorts"; | ||
|
|
||
| export type ContactDetailEditDeleteDialogProps = Readonly<{ | ||
| detailActions?: Readonly<{ | ||
| canDelete: boolean; | ||
| labels: ContactDetailActionsLabels; | ||
| onEdit: () => void; | ||
| onDelete: () => void; | ||
| }>; | ||
| renameDialog: ContactsRenameContactDialogProps; | ||
| deleteDialog: ContactsDeleteContactDialogProps; | ||
| signerDialog: ContactsEditSignerDialogProps; | ||
| }>; | ||
|
|
||
| export function useContactDetailEditDeleteAdapter( | ||
| contactId: ContactId | undefined, | ||
| onDeleteSuccess: () => void, | ||
| ): ContactDetailEditDeleteDialogProps { | ||
| const { t } = useTranslation(); | ||
| const ports = useContactsEditDeletePorts(); | ||
| const resolvedContactId = contactId ?? ContactIdSchema.parse("contact-me"); | ||
| const flow = useContactDetailEditDeleteFlowViewModel({ | ||
| contactId: resolvedContactId, | ||
| ports, | ||
| onDeleteSuccess, | ||
| }); | ||
| const renameDialogViewModel = useRenameContactDialogViewModel({ | ||
| contactId: resolvedContactId, | ||
| currentName: flow.contactName, | ||
| editPort: ports.edit, | ||
| isRequestedOpen: flow.editUiState === "edit-open", | ||
| onCloseRequest: flow.onEditClose, | ||
| onSaveSuccess: () => undefined, | ||
| }); | ||
| const actionLabels: ContactDetailActionsLabels = { | ||
| editContact: t("contacts.detailActions.editContact"), | ||
| deleteContact: t("contacts.detailActions.deleteContact"), | ||
| }; | ||
| const renameLabels = { | ||
| title: t("contacts.editContact.title"), | ||
| namePlaceholder: t("contacts.editContact.namePlaceholder"), | ||
| namingDisclaimer: t("contacts.editContact.namingDisclaimer"), | ||
| applyChanges: t("contacts.editContact.applyChanges"), | ||
| nameValidationErrors: { | ||
| [INVALID_CONTACT_NAME_ERROR_NAME]: t("contacts.editContact.invalidNameError"), | ||
| }, | ||
| }; | ||
| const deleteLabels = { | ||
| title: t("contacts.deleteContact.title"), | ||
| description: t("contacts.deleteContact.description"), | ||
| confirm: t("contacts.deleteContact.confirm"), | ||
| cancel: t("contacts.deleteContact.cancel"), | ||
| }; | ||
| const signerLabels = { | ||
| title: t("contacts.editSigner.title"), | ||
| description: t("contacts.editSigner.description"), | ||
| confirm: t("contacts.editSigner.confirm"), | ||
| cancel: t("contacts.editSigner.cancel"), | ||
| }; | ||
|
|
||
| return { | ||
| detailActions: contactId | ||
| ? { | ||
| canDelete: flow.canDelete, | ||
| labels: actionLabels, | ||
| onEdit: flow.onEditPress, | ||
| onDelete: flow.onDeletePress, | ||
| } | ||
| : undefined, | ||
| renameDialog: { | ||
| ...renameDialogViewModel, | ||
| labels: renameLabels, | ||
| }, | ||
| deleteDialog: { | ||
| isOpen: flow.deleteLifecycle.status === "open", | ||
| isDeleting: flow.isDeleting, | ||
| labels: deleteLabels, | ||
| onConfirm: flow.confirmDelete, | ||
| onCancel: flow.cancelDelete, | ||
| }, | ||
| signerDialog: { | ||
| isOpen: flow.editUiState === "signer-open", | ||
| labels: signerLabels, | ||
| onConfirm: flow.onSignerConfirm, | ||
| onCancel: flow.onSignerCancel, | ||
| }, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ow/contacts/src/steps/Detail/components/ContactDetailActions/ContactDetailActions.web.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import React from "react"; | ||
| import { IconButton } from "@ledgerhq/lumen-ui-react"; | ||
| import { PenEdit, Trash } from "@ledgerhq/lumen-ui-react/symbols"; | ||
| import type { ContactDetailActionsLabels } from "../../types"; | ||
|
|
||
| export type ContactDetailActionsProps = Readonly<{ | ||
| canDelete: boolean; | ||
| labels: ContactDetailActionsLabels; | ||
| onEdit: () => void; | ||
| onDelete: () => void; | ||
| }>; | ||
|
|
||
| export function ContactDetailActions({ | ||
| canDelete, | ||
| labels, | ||
| onEdit, | ||
| onDelete, | ||
| }: ContactDetailActionsProps): React.ReactNode { | ||
| return ( | ||
| <div className="absolute right-16 top-16 flex gap-8" data-testid="contacts-detail-actions"> | ||
| <IconButton | ||
| appearance="transparent" | ||
| size="sm" | ||
| icon={PenEdit} | ||
| aria-label={labels.editContact} | ||
| onClick={onEdit} | ||
| data-testid="contacts-detail-edit-action" | ||
| /> | ||
| {canDelete ? ( | ||
| <IconButton | ||
| appearance="transparent" | ||
| size="sm" | ||
| icon={Trash} | ||
| aria-label={labels.deleteContact} | ||
| onClick={onDelete} | ||
| data-testid="contacts-detail-delete-action" | ||
| /> | ||
| ) : null} | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ASK] "Ports" is for what? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ports are dependency-injection interfaces that keep @features/flow-contacts platform-agnostic.
The shared flow defines what it needs (
ContactEditPort.renameContact,ContactDeletionPort.deleteContact) without knowing how itβs persisted.useContactsEditDeletePortsis the desktop wiring layer.