@@ -5,6 +5,11 @@ 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' ;
11+ import Tooltip from '@material-ui/core/Tooltip' ;
12+ import { withStyles } from '@material-ui/core' ;
813
914import AlertContext from '~/context/alert' ;
1015import BiolinkContext from '~/context/biolink' ;
@@ -204,6 +209,7 @@ export default function NodeSelector({
204209 onOpen = { ( ) => toggleOpen ( true ) }
205210 onClose = { ( ) => toggleOpen ( false ) }
206211 onInputChange = { ( e , v ) => updateInputText ( v ) }
212+ renderOption = { ( props ) => < Option { ...props } /> }
207213 renderInput = { ( params ) => (
208214 < TextField
209215 { ...params }
@@ -237,3 +243,60 @@ export default function NodeSelector({
237243 />
238244 ) ;
239245}
246+
247+ const CustomTooltip = withStyles ( ( theme ) => ( {
248+ tooltip : {
249+ fontSize : theme . typography . pxToRem ( 14 ) ,
250+ } ,
251+ } ) ) ( Tooltip ) ;
252+
253+ function Option ( { name, ids, categories } ) {
254+ return (
255+ < CustomTooltip
256+ interactive
257+ arrow
258+ title = { (
259+ < div className = "node-option-tooltip-wrapper" >
260+ { Array . isArray ( ids ) && ids . length > 0 && (
261+ < div >
262+ < span > { ids [ 0 ] } </ span >
263+ < CopyButton textToCopy = { ids [ 0 ] } />
264+ </ div >
265+ ) }
266+ { Array . isArray ( categories ) && categories . length > 0 && (
267+ < span > { categories [ 0 ] } </ span >
268+ ) }
269+ </ div >
270+ ) }
271+ placement = "left"
272+ >
273+ < div >
274+ { name }
275+ </ div >
276+ </ CustomTooltip >
277+ ) ;
278+ }
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