@@ -5,6 +5,9 @@ import axios from 'axios';
55import Autocomplete from '@material-ui/lab/Autocomplete' ;
66import TextField from '@material-ui/core/TextField' ;
77import CircularProgress from '@material-ui/core/CircularProgress' ;
8+ import IconButton from '@material-ui/core/IconButton' ;
9+ import FileCopy from '@material-ui/icons/FileCopy' ;
10+ import Check from '@material-ui/icons/Check' ;
811import Tooltip from '@material-ui/core/Tooltip' ;
912import { withStyles } from '@material-ui/core' ;
1013
@@ -255,7 +258,10 @@ function Option({ name, ids, categories }) {
255258 title = { (
256259 < div className = "node-option-tooltip-wrapper" >
257260 { Array . isArray ( ids ) && ids . length > 0 && (
258- < span > { ids [ 0 ] } </ span >
261+ < div >
262+ < span > { ids [ 0 ] } </ span >
263+ < CopyButton textToCopy = { ids [ 0 ] } />
264+ </ div >
259265 ) }
260266 { Array . isArray ( categories ) && categories . length > 0 && (
261267 < span > { categories [ 0 ] } </ span >
@@ -270,3 +276,27 @@ function Option({ name, ids, categories }) {
270276 </ CustomTooltip >
271277 ) ;
272278}
279+
280+ function CopyButton ( { textToCopy } ) {
281+ const [ hasCopied , setHasCopied ] = useState ( false ) ;
282+
283+ const handleCopy = ( e ) => {
284+ e . stopPropagation ( ) ;
285+ navigator . clipboard . writeText ( textToCopy ) ;
286+ setHasCopied ( true ) ;
287+ } ;
288+
289+ if (
290+ navigator . clipboard === 'undefined' ||
291+ typeof navigator . clipboard . writeText !== 'function' ||
292+ typeof textToCopy !== 'string'
293+ ) {
294+ return null ;
295+ }
296+
297+ return (
298+ < IconButton color = "inherit" size = "small" onClick = { handleCopy } >
299+ { hasCopied ? < Check /> : < FileCopy /> }
300+ </ IconButton >
301+ ) ;
302+ }
0 commit comments