[MM-57962] Remove outdated Copy Link menu in favour of native Electron dropdown (#26856)

This commit is contained in:
Devin Binnie 2024-04-24 16:39:47 -04:00 committed by GitHub
parent 542e84b140
commit e532807454
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 5 additions and 303 deletions

View File

@ -1,107 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/CopyUrlContextMenu should copy absolute url on click 1`] = `
<span>
<ContextMenu
className=""
data={Object {}}
hideOnLeave={false}
id="copy-url-context-menuresource"
onHide={[Function]}
onMouseLeave={[Function]}
onShow={[Function]}
preventHideOnContextMenu={false}
preventHideOnResize={false}
preventHideOnScroll={false}
rtl={false}
style={Object {}}
>
<MenuItem
attributes={Object {}}
className=""
data={Object {}}
disabled={false}
divider={false}
onClick={[Function]}
onMouseLeave={[Function]}
onMouseMove={[Function]}
preventClose={false}
selected={false}
>
<MemoizedFormattedMessage
defaultMessage="Copy Link"
id="copy_url_context_menu.getChannelLink"
/>
</MenuItem>
</ContextMenu>
<ContextMenuTrigger
attributes={Object {}}
collect={[Function]}
disable={false}
disableIfShiftIsPressed={false}
holdToDisplay={-1}
id="copy-url-context-menuresource"
mouseButton={2}
posX={0}
posY={0}
renderTag="div"
>
<span>
Click
</span>
</ContextMenuTrigger>
</span>
`;
exports[`components/CopyUrlContextMenu should copy relative url on click 1`] = `
<span>
<ContextMenu
className=""
data={Object {}}
hideOnLeave={false}
id="copy-url-context-menuresource"
onHide={[Function]}
onMouseLeave={[Function]}
onShow={[Function]}
preventHideOnContextMenu={false}
preventHideOnResize={false}
preventHideOnScroll={false}
rtl={false}
style={Object {}}
>
<MenuItem
attributes={Object {}}
className=""
data={Object {}}
disabled={false}
divider={false}
onClick={[Function]}
onMouseLeave={[Function]}
onMouseMove={[Function]}
preventClose={false}
selected={false}
>
<MemoizedFormattedMessage
defaultMessage="Copy Link"
id="copy_url_context_menu.getChannelLink"
/>
</MenuItem>
</ContextMenu>
<ContextMenuTrigger
attributes={Object {}}
collect={[Function]}
disable={false}
disableIfShiftIsPressed={false}
holdToDisplay={-1}
id="copy-url-context-menuresource"
mouseButton={2}
posX={0}
posY={0}
renderTag="div"
>
<span>
Click
</span>
</ContextMenuTrigger>
</span>
`;

View File

@ -1,51 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import CopyUrlContextMenu from 'components/copy_url_context_menu/copy_url_context_menu';
describe('components/CopyUrlContextMenu', () => {
test('should copy relative url on click', () => {
const props = {
siteURL: 'http://example.com',
link: '/path/to/resource',
menuId: 'resource',
actions: {
copyToClipboard: jest.fn(),
},
};
const wrapper = shallow(
<CopyUrlContextMenu {...props}>
<span>{'Click'}</span>
</CopyUrlContextMenu>,
);
expect(wrapper).toMatchSnapshot();
wrapper.find('MenuItem').simulate('click');
expect(props.actions.copyToClipboard).toBeCalledWith('http://example.com/path/to/resource');
});
test('should copy absolute url on click', () => {
const props = {
siteURL: 'http://example.com',
link: 'http://site.example.com/path/to/resource',
menuId: 'resource',
actions: {
copyToClipboard: jest.fn(),
},
};
const wrapper = shallow(
<CopyUrlContextMenu {...props}>
<span>{'Click'}</span>
</CopyUrlContextMenu>,
);
expect(wrapper).toMatchSnapshot();
wrapper.find('MenuItem').simulate('click');
expect(props.actions.copyToClipboard).toBeCalledWith('http://site.example.com/path/to/resource');
});
});

View File

@ -1,80 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {memo, useCallback} from 'react';
import {ContextMenu, ContextMenuTrigger, MenuItem} from 'react-contextmenu';
import {FormattedMessage} from 'react-intl';
type Props = {
/**
* The child component that will be right-clicked on to show the context menu
*/
children: React.ReactNode;
/**
* The link to copy to the user's clipboard when the 'Copy' option is selected from the context menu
*/
link: string;
/**
* A unique id differentiating this instance of context menu from others on the page
*/
menuId: string;
siteURL?: string;
actions: {
copyToClipboard: (link: string) => void;
};
}
const CopyUrlContextMenu = ({
link,
siteURL,
actions,
menuId,
children,
}: Props) => {
const copy = useCallback(() => {
let siteLink = link;
// Transform relative links to absolute ones for copy and paste.
if (siteLink.indexOf('http://') === -1 && siteLink.indexOf('https://') === -1) {
siteLink = siteURL + link;
}
actions.copyToClipboard(siteLink);
}, [actions, link, siteURL]);
const contextMenu = (
<ContextMenu id={`copy-url-context-menu${menuId}`}>
<MenuItem
onClick={copy}
>
<FormattedMessage
id='copy_url_context_menu.getChannelLink'
defaultMessage='Copy Link'
/>
</MenuItem>
</ContextMenu>
);
const contextMenuTrigger = (
<ContextMenuTrigger
id={`copy-url-context-menu${menuId}`}
holdToDisplay={-1}
>
{children}
</ContextMenuTrigger>
);
return (
<span>
{contextMenu}
{contextMenuTrigger}
</span>
);
};
export default memo(CopyUrlContextMenu);

View File

@ -1,30 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {copyToClipboard} from 'utils/utils';
import type {GlobalState} from 'types/store/index.js';
import CopyUrlContextMenu from './copy_url_context_menu';
function mapStateToProps(state: GlobalState) {
const config = getConfig(state);
return {
siteURL: config.SiteURL,
};
}
function mapDispatchToProps() {
return {
actions: {
copyToClipboard,
},
};
}
export default connect(mapStateToProps, mapDispatchToProps)(CopyUrlContextMenu);

View File

@ -9,7 +9,6 @@ import type {Channel} from '@mattermost/types/channels';
import {mark, trackEvent} from 'actions/telemetry_actions'; import {mark, trackEvent} from 'actions/telemetry_actions';
import CopyUrlContextMenu from 'components/copy_url_context_menu';
import CustomStatusEmoji from 'components/custom_status/custom_status_emoji'; import CustomStatusEmoji from 'components/custom_status/custom_status_emoji';
import OverlayTrigger from 'components/overlay_trigger'; import OverlayTrigger from 'components/overlay_trigger';
import Tooltip from 'components/tooltip'; import Tooltip from 'components/tooltip';
@ -19,7 +18,6 @@ import Pluggable from 'plugins/pluggable';
import Constants, {RHSStates} from 'utils/constants'; import Constants, {RHSStates} from 'utils/constants';
import {wrapEmojis} from 'utils/emoji_utils'; import {wrapEmojis} from 'utils/emoji_utils';
import {cmdOrCtrlPressed} from 'utils/keyboard'; import {cmdOrCtrlPressed} from 'utils/keyboard';
import {isDesktopApp} from 'utils/user_agent';
import {localizeMessage} from 'utils/utils'; import {localizeMessage} from 'utils/utils';
import type {RhsState} from 'types/store/rhs'; import type {RhsState} from 'types/store/rhs';
@ -290,7 +288,7 @@ export default class SidebarChannelLink extends React.PureComponent<Props, State
selected: isChannelSelected, selected: isChannelSelected,
}, },
]); ]);
let element = ( return (
<Link <Link
className={className} className={className}
id={`sidebarItem_${channel.name}`} id={`sidebarItem_${channel.name}`}
@ -303,18 +301,5 @@ export default class SidebarChannelLink extends React.PureComponent<Props, State
{channelsTutorialTip} {channelsTutorialTip}
</Link> </Link>
); );
if (isDesktopApp()) {
element = (
<CopyUrlContextMenu
link={this.props.link}
menuId={channel.id}
>
{element}
</CopyUrlContextMenu>
);
}
return element;
} }
} }

View File

@ -9,13 +9,10 @@ import {Link} from 'react-router-dom';
import {mark, trackEvent} from 'actions/telemetry_actions.jsx'; import {mark, trackEvent} from 'actions/telemetry_actions.jsx';
import CopyUrlContextMenu from 'components/copy_url_context_menu';
import TeamIcon from 'components/widgets/team_icon/team_icon'; import TeamIcon from 'components/widgets/team_icon/team_icon';
import WithTooltip from 'components/with_tooltip'; import WithTooltip from 'components/with_tooltip';
import {ShortcutKeys} from 'components/with_tooltip/shortcut'; import {ShortcutKeys} from 'components/with_tooltip/shortcut';
import {isDesktopApp} from 'utils/user_agent';
const messages = defineMessages({ const messages = defineMessages({
nameUndefined: { nameUndefined: {
id: 'team.button.name_undefined', id: 'team.button.name_undefined',
@ -163,7 +160,7 @@ export default function TeamButton({
</WithTeamTooltip> </WithTeamTooltip>
); );
let teamButton = ( const teamButton = (
<Link <Link
id={`${url.slice(1)}TeamButton`} id={`${url.slice(1)}TeamButton`}
aria-label={ariaLabel} aria-label={ariaLabel}
@ -174,20 +171,6 @@ export default function TeamButton({
</Link> </Link>
); );
if (isDesktopApp()) {
// if this is not a "special" team button, give it a context menu
if (isNotCreateTeamButton) {
teamButton = (
<CopyUrlContextMenu
link={url}
menuId={url}
>
{teamButton}
</CopyUrlContextMenu>
);
}
}
return isDraggable ? ( return isDraggable ? (
<Draggable <Draggable
draggableId={teamId!} draggableId={teamId!}

View File

@ -17,6 +17,8 @@
} }
.TeamIcon__initials { .TeamIcon__initials {
user-select: none;
&.TeamIcon__initials__lg { &.TeamIcon__initials__lg {
font-size: 3em; font-size: 3em;
} }

View File

@ -3296,7 +3296,6 @@
"convert_channel.question3": "Are you sure you want to convert **{display_name}** to a private channel?", "convert_channel.question3": "Are you sure you want to convert **{display_name}** to a private channel?",
"convert_channel.title": "Convert {display_name} to a Private Channel?", "convert_channel.title": "Convert {display_name} to a Private Channel?",
"copied.message": "Copied", "copied.message": "Copied",
"copy_url_context_menu.getChannelLink": "Copy Link",
"copy.code.message": "Copy code", "copy.code.message": "Copy code",
"copy.text.message": "Copy text", "copy.text.message": "Copy text",
"create_category_modal.create": "Create", "create_category_modal.create": "Create",

View File

@ -1141,6 +1141,7 @@ $sidebarOpacityAnimationDuration: 0.15s;
height: 18px; height: 18px;
line-height: 18px; line-height: 18px;
text-align: justify; text-align: justify;
user-select: none;
white-space: nowrap; white-space: nowrap;
} }