Skip to content

Commit ae42cb9

Browse files
committed
fix: Use navigator.clipboard instead of copy-text-to-clipboard
copy-text-to-clipboard use deprecated command.exec which does not work anymore on some desktop browser.
1 parent e8943fd commit ae42cb9

File tree

6 files changed

+8
-20
lines changed

6 files changed

+8
-20
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
"bundlemon": "^1.3.2",
162162
"chart.js": "3.7.1",
163163
"classnames": "^2.2.5",
164-
"copy-text-to-clipboard": "3.2.0",
165164
"cozy-interapp": "^0.5.4",
166165
"date-fns": "^1.28.5",
167166
"filesize": "8.0.7",

react/ListItem/ExpandedAttributes/helpers.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import get from 'lodash/get'
2-
import copy from 'copy-text-to-clipboard'
32

43
import { formatDate } from '../../Viewer/helpers'
54

@@ -68,15 +67,15 @@ export const makeDefaultExpandedAttributes = (doc, expandedAttributes) => {
6867
.filter(x => x)
6968
}
7069

71-
export const copyToClipboard = ({ value, setAlertProps, t }) => () => {
72-
const hasCopied = copy(value)
73-
if (hasCopied) {
70+
export const copyToClipboard = ({ value, setAlertProps, t }) => async () => {
71+
try {
72+
await navigator.clipboard.writeText(value)
7473
setAlertProps({
7574
open: true,
7675
severity: 'success',
7776
message: t(`ListItem.snackbar.copyToClipboard.success`)
7877
})
79-
} else {
78+
} catch (error) {
8079
setAlertProps({
8180
open: true,
8281
severity: 'error',

react/ListItem/ExpandedAttributes/helpers.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
import { I18nContext } from '../../jestLib/I18n'
88
import en from '../locales/en'
99

10-
jest.mock('copy-text-to-clipboard', () => ({ copy: jest.fn() }))
11-
1210
const i18nContext = I18nContext({
1311
locale: en
1412
})

react/Viewer/Panel/ActionMenuWrapper.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { forwardRef } from 'react'
22
import PropTypes from 'prop-types'
3-
import copy from 'copy-text-to-clipboard'
43

54
import { useAppLinkWithStoreFallback, useClient } from 'cozy-client'
65

@@ -40,14 +39,14 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
4039
)
4140
const isAppLinkLoaded = fetchStatus === 'loaded'
4241

43-
const handleCopy = () => {
44-
const hasCopied = copy(value)
45-
if (hasCopied) {
42+
const handleCopy = async () => {
43+
try {
44+
await navigator.clipboard.writeText(value)
4645
showViewerSnackbar(
4746
'success',
4847
t(`Viewer.snackbar.copiedToClipboard.success`)
4948
)
50-
} else {
49+
} catch (error) {
5150
showViewerSnackbar('error', t(`Viewer.snackbar.copiedToClipboard.error`))
5251
}
5352
onClose()

react/Viewer/Panel/getPanelBlocks.spec.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ jest.mock('cozy-harvest-lib/dist/components/KonnectorBlock', () => jest.fn())
44
const block1Component = jest.fn()
55
const block2Component = jest.fn()
66

7-
jest.mock('copy-text-to-clipboard', () => ({ copy: jest.fn() }))
8-
97
describe('getPanelBlocks', () => {
108
it('should return only blocks with truthy condition', () => {
119
// with two truthy component

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5909,11 +5909,6 @@ copy-descriptor@^0.1.0:
59095909
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
59105910
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=
59115911

5912-
copy-text-to-clipboard@3.2.0:
5913-
version "3.2.0"
5914-
resolved "https://registry.yarnpkg.com/copy-text-to-clipboard/-/copy-text-to-clipboard-3.2.0.tgz#0202b2d9bdae30a49a53f898626dcc3b49ad960b"
5915-
integrity sha512-RnJFp1XR/LOBDckxTib5Qjr/PMfkatD0MUCQgdpqS8MdKiNUzBjAQBEN6oUy+jW7LI93BBG3DtMB2KOOKpGs2Q==
5916-
59175912
copy-text-to-clipboard@^2.1.1:
59185913
version "2.2.0"
59195914
resolved "https://registry.yarnpkg.com/copy-text-to-clipboard/-/copy-text-to-clipboard-2.2.0.tgz#329dd6daf8c42034c763ace567418401764579ae"

0 commit comments

Comments
 (0)