From 7467779ea9af9397c71c56b75bfc71518f923931 Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 2 Jun 2021 09:32:59 -0400 Subject: [PATCH] Remove clipboard copy button component --- .../ClipboardCopyButton.jsx | 90 ------------------- .../ClipboardCopyButton.test.jsx | 61 ------------- .../components/ClipboardCopyButton/index.js | 1 - 3 files changed, 152 deletions(-) delete mode 100644 awx/ui_next/src/components/ClipboardCopyButton/ClipboardCopyButton.jsx delete mode 100644 awx/ui_next/src/components/ClipboardCopyButton/ClipboardCopyButton.test.jsx delete mode 100644 awx/ui_next/src/components/ClipboardCopyButton/index.js diff --git a/awx/ui_next/src/components/ClipboardCopyButton/ClipboardCopyButton.jsx b/awx/ui_next/src/components/ClipboardCopyButton/ClipboardCopyButton.jsx deleted file mode 100644 index 2563ca5b15..0000000000 --- a/awx/ui_next/src/components/ClipboardCopyButton/ClipboardCopyButton.jsx +++ /dev/null @@ -1,90 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import { Button, Tooltip } from '@patternfly/react-core'; -import { CopyIcon } from '@patternfly/react-icons'; - -export const clipboardCopyFunc = (event, text) => { - const clipboard = event.currentTarget.parentElement; - const el = document.createElement('input'); - el.value = text; - clipboard.appendChild(el); - el.select(); - document.execCommand('copy'); - clipboard.removeChild(el); -}; - -class ClipboardCopyButton extends React.Component { - constructor(props) { - super(props); - - this.state = { - copied: false, - }; - - this.handleCopyClick = this.handleCopyClick.bind(this); - } - - handleCopyClick = event => { - const { stringToCopy, switchDelay } = this.props; - if (this.timer) { - window.clearTimeout(this.timer); - this.setState({ copied: false }); - } - clipboardCopyFunc(event, stringToCopy); - this.setState({ copied: true }, () => { - this.timer = window.setTimeout(() => { - this.setState({ copied: false }); - this.timer = null; - }, switchDelay); - }); - }; - - render() { - const { - copyTip, - entryDelay, - exitDelay, - copiedSuccessTip, - isDisabled, - ouiaId, - } = this.props; - const { copied } = this.state; - - return ( - - - - ); - } -} - -ClipboardCopyButton.propTypes = { - copyTip: PropTypes.string.isRequired, - entryDelay: PropTypes.number, - exitDelay: PropTypes.number, - copiedSuccessTip: PropTypes.string.isRequired, - stringToCopy: PropTypes.string.isRequired, - switchDelay: PropTypes.number, - isDisabled: PropTypes.bool.isRequired, -}; - -ClipboardCopyButton.defaultProps = { - entryDelay: 100, - exitDelay: 1600, - switchDelay: 2000, -}; - -export default ClipboardCopyButton; diff --git a/awx/ui_next/src/components/ClipboardCopyButton/ClipboardCopyButton.test.jsx b/awx/ui_next/src/components/ClipboardCopyButton/ClipboardCopyButton.test.jsx deleted file mode 100644 index 5daaeb81e5..0000000000 --- a/awx/ui_next/src/components/ClipboardCopyButton/ClipboardCopyButton.test.jsx +++ /dev/null @@ -1,61 +0,0 @@ -import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; -import ClipboardCopyButton from './ClipboardCopyButton'; - -describe('ClipboardCopyButton', () => { - beforeEach(() => { - document.execCommand = jest.fn(); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - - test('renders the expected content', () => { - const wrapper = mountWithContexts( - - ); - expect(wrapper).toHaveLength(1); - }); - test('clicking button calls execCommand to copy to clipboard', async () => { - const mockDelay = 1; - const wrapper = mountWithContexts( - - ).find('ClipboardCopyButton'); - expect(wrapper.state('copied')).toBe(false); - wrapper.find('Button').simulate('click'); - expect(document.execCommand).toBeCalledWith('copy'); - expect(wrapper.state('copied')).toBe(true); - await new Promise(resolve => setTimeout(resolve, mockDelay)); - wrapper.update(); - expect(wrapper.state('copied')).toBe(false); - }); - test('should render disabled button', () => { - const wrapper = mountWithContexts( - - ); - expect(wrapper.find('Button').prop('isDisabled')).toBe(true); - }); -}); diff --git a/awx/ui_next/src/components/ClipboardCopyButton/index.js b/awx/ui_next/src/components/ClipboardCopyButton/index.js deleted file mode 100644 index 45adfe436e..0000000000 --- a/awx/ui_next/src/components/ClipboardCopyButton/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './ClipboardCopyButton';