Skip to content

Commit

Permalink
fixed chain / rstudio button copy text to clipboard (#3036)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 29, 2023
1 parent 4f5df54 commit 13e9df4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions webapp/store/ui/chain/actions/openRStudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const _getRStudioCode = ({
`
}

const _copyRStudioCode = ({ rStudioCode }) => copyToClipboard(rStudioCode)
const _copyRStudioCode = async ({ rStudioCode }) => copyToClipboard(rStudioCode)

const isInstanceRunning = async () => {
const currentInstance = await API.getCurrentInstance()
Expand Down Expand Up @@ -117,8 +117,8 @@ export const openRStudio =
DialogConfirmActions.showDialogConfirm({
key: isLocal ? 'chainView.copyRStudioCodeLocal' : 'chainView.copyRStudioCode',
params: { rStudioCode },
onOk: () => {
_copyRStudioCode({ rStudioCode })
onOk: async () => {
await _copyRStudioCode({ rStudioCode })
if (!isLocal) {
window.open(rStudioUrl, 'rstudio')
}
Expand Down
13 changes: 6 additions & 7 deletions webapp/utils/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ export const dispatchWindowResize = () => {
window.dispatchEvent(new Event('resize'))
}

export const copyToClipboard = (text) => {
const input = document.body.appendChild(document.createElement('textarea'))
input.value = text
input.focus()
input.select()
document.execCommand('copy')
input.remove()
export const copyToClipboard = async (text) => {
try {
await navigator.clipboard.writeText(text)
} catch (error) {
// ignore it
}
}

0 comments on commit 13e9df4

Please sign in to comment.