-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathContextMenu.jsx
More file actions
34 lines (29 loc) · 948 Bytes
/
ContextMenu.jsx
File metadata and controls
34 lines (29 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from 'react';
import copyToClipboard from 'copy-to-clipboard';
function handleCopy(info) {
const objects = info.objects ? info.objects : [info.object];
// make csv style data
const headers = [];
const firstObject = objects[0];
if (firstObject) {
headers.push('Latitude', 'Longitude');
firstObject.tooltips.forEach(t => headers.push(t.key));
}
const contents = objects.map(data => {
const { coordinates } = data;
const tooltips = data.tooltips.map(t => t.value);
const row = [coordinates[1], coordinates[0], ...tooltips];
return row.join(',');
});
const text = [headers.join(','), ...contents].join('\n');
copyToClipboard(text);
}
export function renderContextMenu(info) {
if (!info) return null;
const { x, y } = info;
return (
<ul className="contextMenu" style={{position: 'fixed', left: x, top: y}}>
<li onClick={() => handleCopy(info)}>Copy data</li>
</ul>
)
}