Skip to content

Commit eb50315

Browse files
authored
feat: Allow to select and copy multiple cells in data browser (#2691)
1 parent 67685d0 commit eb50315

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/dashboard/Data/Browser/DataBrowser.react.js

+36
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,42 @@ export default class DataBrowser extends React.Component {
282282
if (this.props.disableKeyControls) {
283283
return;
284284
}
285+
if (e.keyCode === 67 && (e.ctrlKey || e.metaKey)) {
286+
// check if there is multiple selected cells
287+
const { rowStart, rowEnd, colStart, colEnd } = this.state.selectedCells;
288+
if (rowStart !== -1 && rowEnd !== -1 && colStart !== -1 && colEnd !== -1) {
289+
let copyableValue = '';
290+
291+
for (let rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
292+
const rowData = [];
293+
294+
for (let colIndex = colStart; colIndex <= colEnd; colIndex++) {
295+
const field = this.state.order[colIndex].name;
296+
const value = field === 'objectId'
297+
? this.props.data[rowIndex].id
298+
: this.props.data[rowIndex].attributes[field];
299+
300+
if (typeof value === 'number' && !isNaN(value)) {
301+
rowData.push(String(value));
302+
} else {
303+
rowData.push(value || '');
304+
}
305+
}
306+
307+
copyableValue += rowData.join('\t');
308+
if (rowIndex < rowEnd) {
309+
copyableValue += '\r\n';
310+
}
311+
}
312+
this.setCopyableValue(copyableValue);
313+
copy(copyableValue);
314+
315+
if (this.props.showNote) {
316+
this.props.showNote('Value copied to clipboard', false);
317+
}
318+
e.preventDefault();
319+
}
320+
}
285321
if (
286322
this.state.editing &&
287323
this.state.current &&

0 commit comments

Comments
 (0)