Skip to content

Commit 9b01e90

Browse files
committed
add copy button for curie
1 parent eaaa777 commit 9b01e90

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/pages/queryBuilder/textEditor/textEditorRow/NodeSelector.jsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import axios from 'axios';
55
import Autocomplete from '@material-ui/lab/Autocomplete';
66
import TextField from '@material-ui/core/TextField';
77
import 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';
811
import Tooltip from '@material-ui/core/Tooltip';
912
import { 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

Comments
 (0)