Skip to content

Commit

Permalink
feat: edit custom network flow (#25272)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
Edit network flow from the modal added
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25272?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Run `yarn && ENABLE_NETWORK_UI_REDESIGN=1 yarn start`
2. Go to Settings -> Developer Options
3. Tun on the network new toggle
4. Go to the wallet page
5. Click on the network button ( see the video below )
6. click on the three points button
7. click on edit
8. you should be able to edit a network

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**



https://github.com/MetaMask/metamask-extension/assets/26223211/cc2e7716-cb13-4158-9994-1c7bccf377ad


### **After**



https://github.com/MetaMask/metamask-extension/assets/26223211/c6473a45-bdd1-49d7-81bd-cf92f55376f5



## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: David Walsh <[email protected]>
  • Loading branch information
salimtb and darkwing authored Jun 21, 2024
1 parent a6ebbc7 commit 7e3b289
Show file tree
Hide file tree
Showing 22 changed files with 774 additions and 214 deletions.
12 changes: 12 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/components/multichain/multichain-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import 'connected-site-menu';
@import 'token-list-item';
@import 'network-list-item';
@import 'network-list-item-menu';
@import 'network-list-menu';
@import 'product-tour-popover';
@import 'nft-item';
Expand Down
1 change: 1 addition & 0 deletions ui/components/multichain/network-list-item-menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NetworkListItemMenu } from './network-list-item-menu';
8 changes: 8 additions & 0 deletions ui/components/multichain/network-list-item-menu/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use "design-system";

.multichain-network-list-item-menu__popover {
z-index: design-system.$popover-in-modal-z-index;
overflow: hidden;
min-width: 225px;
max-width: 225px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
IconName,
ModalFocus,
Popover,
PopoverPosition,
PopoverRole,
Text,
} from '../../component-library';
import { MenuItem } from '../../ui/menu';
import { IconColor, TextColor } from '../../../helpers/constants/design-system';

export const NetworkListItemMenu = ({
anchorElement,
onClose,
onEditClick,
onDeleteClick,
isOpen,
}) => {
const t = useI18nContext();

return (
<Popover
className="multichain-network-list-item-menu__popover"
onClickOutside={onClose}
referenceElement={anchorElement}
role={PopoverRole.Dialog}
position={PopoverPosition.Bottom}
offset={[0, 0]}
padding={0}
isOpen={isOpen}
isPortal
preventOverflow
flip
>
<ModalFocus restoreFocus initialFocusRef={anchorElement}>
<div>
{onEditClick ? (
<MenuItem
iconName={IconName.Edit}
onClick={(e) => {
e.stopPropagation();

// Pass network info?
onEditClick();
}}
data-testid="network-list-item-options-edit"
>
{t('edit')}
</MenuItem>
) : null}
{onDeleteClick ? (
<MenuItem
iconName={IconName.Trash}
iconColor={IconColor.errorDefault}
onClick={(e) => {
e.stopPropagation();

// Pass network info?
onDeleteClick();
}}
data-testid="network-list-item-options-delete"
>
<Text color={TextColor.errorDefault}>{t('delete')}</Text>
</MenuItem>
) : null}
</div>
</ModalFocus>
</Popover>
);
};

NetworkListItemMenu.propTypes = {
/**
* Element that the menu should display next to
*/
anchorElement: PropTypes.instanceOf(window.Element),
/**
* Function that executes when the menu is closed
*/
onClose: PropTypes.func.isRequired,
/**
* Function that executes when the Edit menu item is clicked
*/
onEditClick: PropTypes.func,
/**
* Function that executes when the Delete menu item is closed
*/
onDeleteClick: PropTypes.func,
/**
* Represents if the menu is open or not
*
* @type {boolean}
*/
isOpen: PropTypes.bool.isRequired,
};
12 changes: 0 additions & 12 deletions ui/components/multichain/network-list-item/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
color: inherit;
}

&:hover,
&:focus,
&:focus-within {
.multichain-network-list-item__delete {
visibility: visible;
}
}

&__network-name {
width: 100%;
flex: 1;
Expand All @@ -44,8 +36,4 @@
top: 4px;
left: 4px;
}

&__delete {
visibility: hidden;
}
}
77 changes: 61 additions & 16 deletions ui/components/multichain/network-list-item/network-list-item.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import React, { useEffect, useRef } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import {
AlignItems,
BackgroundColor,
BlockSize,
BorderRadius,
Color,
Display,
IconColor,
JustifyContent,
Size,
TextColor,
Size,
IconColor,
} from '../../../helpers/constants/design-system';
import {
AvatarNetwork,
Box,
ButtonIcon,
ButtonIconSize,
IconName,
Text,
} from '../../component-library';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { getAvatarNetworkColor } from '../../../helpers/utils/accounts';
import Tooltip from '../../ui/tooltip/tooltip';
import { NetworkListItemMenu } from '../network-list-item-menu';
import { getLocalNetworkMenuRedesignFeatureFlag } from '../../../helpers/utils/feature-flags';

const MAXIMUM_CHARACTERS_WITHOUT_TOOLTIP = 20;

Expand All @@ -33,10 +37,52 @@ export const NetworkListItem = ({
focus = true,
onClick,
onDeleteClick,
onEditClick,
}) => {
const t = useI18nContext();
const networkRef = useRef();

const [networkListItemMenuElement, setNetworkListItemMenuElement] =
useState();
const setNetworkListItemMenuRef = (ref) => {
setNetworkListItemMenuElement(ref);
};
const [networkOptionsMenuOpen, setNetworkOptionsMenuOpen] = useState(false);
const networkMenuRedesign = useSelector(
getLocalNetworkMenuRedesignFeatureFlag,
);

const renderButton = () => {
if (networkMenuRedesign) {
return onDeleteClick || onEditClick ? (
<ButtonIcon
iconName={IconName.MoreVertical}
ref={setNetworkListItemMenuRef}
data-testid="network-list-item-options-button"
ariaLabel={t('networkOptions')}
onClick={(e) => {
e.stopPropagation();
setNetworkOptionsMenuOpen(true);
}}
size={ButtonIconSize.Sm}
/>
) : null;
}

return onDeleteClick ? (
<ButtonIcon
className="multichain-network-list-item__delete"
color={IconColor.errorDefault}
iconName={IconName.Trash}
ariaLabel={t('deleteNetwork')}
size={Size.SM}
onClick={(e) => {
e.stopPropagation();
onDeleteClick();
}}
/>
) : null;
};
useEffect(() => {
if (networkRef.current && focus) {
networkRef.current.focus();
Expand Down Expand Up @@ -103,19 +149,14 @@ export const NetworkListItem = ({
)}
</Text>
</Box>
{onDeleteClick ? (
<ButtonIcon
className="multichain-network-list-item__delete"
color={IconColor.errorDefault}
iconName={IconName.Trash}
ariaLabel={t('deleteNetwork')}
size={Size.SM}
onClick={(e) => {
e.stopPropagation();
onDeleteClick();
}}
/>
) : null}
{renderButton()}
<NetworkListItemMenu
anchorElement={networkListItemMenuElement}
isOpen={networkOptionsMenuOpen}
onDeleteClick={onDeleteClick}
onEditClick={onEditClick}
onClose={() => setNetworkOptionsMenuOpen(false)}
/>
</Box>
);
};
Expand All @@ -141,6 +182,10 @@ NetworkListItem.propTypes = {
* Executes when the delete icon is clicked
*/
onDeleteClick: PropTypes.func,
/**
* Executes when the edit icon is clicked
*/
onEditClick: PropTypes.func,
/**
* Represents if the network item should be keyboard selected
*/
Expand Down
Loading

0 comments on commit 7e3b289

Please sign in to comment.