[MM-57708] Convert ./components/copy_url_context_menu/copy_url_context_menu.tsx from Class Component to Function Component (#26716)
* Convert `./components/copy_url_context_menu/copy_url_context_menu.tsx` from Class Component to Function Component
* 🎨 Improve code quality
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3dae305dc7
Коммит
7b90b7c2e0
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import React from 'react';
|
import React, {memo, useCallback} from 'react';
|
||||||
import {ContextMenu, ContextMenuTrigger, MenuItem} from 'react-contextmenu';
|
import {ContextMenu, ContextMenuTrigger, MenuItem} from 'react-contextmenu';
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
|
|
||||||
@@ -29,46 +29,52 @@ type Props = {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CopyUrlContextMenu extends React.PureComponent<Props> {
|
const CopyUrlContextMenu = ({
|
||||||
copy = () => {
|
link,
|
||||||
let link = this.props.link;
|
siteURL,
|
||||||
|
actions,
|
||||||
|
menuId,
|
||||||
|
children,
|
||||||
|
}: Props) => {
|
||||||
|
const copy = useCallback(() => {
|
||||||
|
let siteLink = link;
|
||||||
|
|
||||||
// Transform relative links to absolute ones for copy and paste.
|
// Transform relative links to absolute ones for copy and paste.
|
||||||
if (link.indexOf('http://') === -1 && link.indexOf('https://') === -1) {
|
if (siteLink.indexOf('http://') === -1 && siteLink.indexOf('https://') === -1) {
|
||||||
link = this.props.siteURL + link;
|
siteLink = siteURL + link;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.actions.copyToClipboard(link);
|
actions.copyToClipboard(siteLink);
|
||||||
};
|
}, [actions, link, siteURL]);
|
||||||
|
|
||||||
render(): JSX.Element {
|
const contextMenu = (
|
||||||
const contextMenu = (
|
<ContextMenu id={`copy-url-context-menu${menuId}`}>
|
||||||
<ContextMenu id={'copy-url-context-menu' + this.props.menuId}>
|
<MenuItem
|
||||||
<MenuItem
|
onClick={copy}
|
||||||
onClick={this.copy}
|
|
||||||
>
|
|
||||||
<FormattedMessage
|
|
||||||
id='copy_url_context_menu.getChannelLink'
|
|
||||||
defaultMessage='Copy Link'
|
|
||||||
/>
|
|
||||||
</MenuItem>
|
|
||||||
</ContextMenu>
|
|
||||||
);
|
|
||||||
|
|
||||||
const contextMenuTrigger = (
|
|
||||||
<ContextMenuTrigger
|
|
||||||
id={'copy-url-context-menu' + this.props.menuId}
|
|
||||||
holdToDisplay={-1}
|
|
||||||
>
|
>
|
||||||
{this.props.children}
|
<FormattedMessage
|
||||||
</ContextMenuTrigger>
|
id='copy_url_context_menu.getChannelLink'
|
||||||
);
|
defaultMessage='Copy Link'
|
||||||
|
/>
|
||||||
|
</MenuItem>
|
||||||
|
</ContextMenu>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
const contextMenuTrigger = (
|
||||||
<span>
|
<ContextMenuTrigger
|
||||||
{contextMenu}
|
id={`copy-url-context-menu${menuId}`}
|
||||||
{contextMenuTrigger}
|
holdToDisplay={-1}
|
||||||
</span>
|
>
|
||||||
);
|
{children}
|
||||||
}
|
</ContextMenuTrigger>
|
||||||
}
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
{contextMenu}
|
||||||
|
{contextMenuTrigger}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(CopyUrlContextMenu);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user