From 592bd2671fb0a67080546089c9685f4a05271868 Mon Sep 17 00:00:00 2001 From: John Knox Date: Wed, 29 May 2019 08:40:32 -0700 Subject: [PATCH] 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 --- src/ui/components/table/ManagedTable.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/ui/components/table/ManagedTable.js b/src/ui/components/table/ManagedTable.js index d483c5bbc..078c28c62 100644 --- a/src/ui/components/table/ManagedTable.js +++ b/src/ui/components/table/ManagedTable.js @@ -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); + }, + })), }, ] : [];