Fix copy cell wrong cell bug

Summary:
It was relying on hash keys to be in order, which obviously won't work. Logs plugin, on "copy message" was copying a timestamp instead.
Fixed by using the columnOrder state instead.

Reviewed By: danielbuechele

Differential Revision: D15535281

fbshipit-source-id: 2d7db95c16cc4f75c0d9cf14806fcc80cc8e4bd9
This commit is contained in:
John Knox
2019-05-29 08:40:32 -07:00
committed by Facebook Github Bot
parent 6aa3457fb4
commit 592bd2671f

View File

@@ -462,10 +462,8 @@ class ManagedTable extends React.Component<
}
};
onCopyCell = (rowId: string, column: string) => {
const cellText = getTextContentOfRow(rowId)[
Object.keys(this.props.columns).indexOf(column)
];
onCopyCell = (rowId: string, index: number) => {
const cellText = getTextContentOfRow(rowId)[index];
clipboard.writeText(cellText);
};
@@ -481,14 +479,17 @@ class ManagedTable extends React.Component<
{
click: this.onCopy,
label: 'Copy cell',
submenu: Object.keys(this.props.columns).map((column, index) => ({
label: this.props.columns[column].value,
click: () => {
const rowId = this.state.highlightedRows.values().next()
.value;
rowId && this.onCopyCell(rowId, column);
},
})),
submenu: this.state.columnOrder
.filter(c => c.visible)
.map(c => c.key)
.map((column, index) => ({
label: this.props.columns[column].value,
click: () => {
const rowId = this.state.highlightedRows.values().next()
.value;
rowId && this.onCopyCell(rowId, index);
},
})),
},
]
: [];