copy virtualized rows
Summary: Rows that were virtualized and currently not rendered weren't copied, because we were using the DOM to get their content. This changes this to use out `textContent` utility to get the value of a row and therefore enables copying rows that are not rendered. Reviewed By: jknoxville Differential Revision: D15898935 fbshipit-source-id: c372bc4e77477214860f0513b442374da8f72416
This commit is contained in:
committed by
Facebook Github Bot
parent
48b690169e
commit
8bc26378f0
@@ -31,6 +31,7 @@ import createPaste from '../../../fb-stubs/createPaste.js';
|
|||||||
import debounceRender from 'react-debounce-render';
|
import debounceRender from 'react-debounce-render';
|
||||||
import debounce from 'lodash.debounce';
|
import debounce from 'lodash.debounce';
|
||||||
import {DEFAULT_ROW_HEIGHT} from './types';
|
import {DEFAULT_ROW_HEIGHT} from './types';
|
||||||
|
import textContent from '../../../utils/textContent.js';
|
||||||
|
|
||||||
export type ManagedTableProps = {|
|
export type ManagedTableProps = {|
|
||||||
/**
|
/**
|
||||||
@@ -146,12 +147,6 @@ const Container = styled(FlexColumn)(props => ({
|
|||||||
|
|
||||||
const globalTableState: {[string]: TableColumnSizes} = {};
|
const globalTableState: {[string]: TableColumnSizes} = {};
|
||||||
|
|
||||||
function getTextContentOfRow(rowId: string) {
|
|
||||||
return Array.from(
|
|
||||||
document.querySelectorAll(`[data-key='${rowId}'] > *`) || [],
|
|
||||||
).map(node => node.textContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
class ManagedTable extends React.Component<
|
class ManagedTable extends React.Component<
|
||||||
ManagedTableProps,
|
ManagedTableProps,
|
||||||
ManagedTableState,
|
ManagedTableState,
|
||||||
@@ -489,7 +484,7 @@ class ManagedTable extends React.Component<
|
|||||||
};
|
};
|
||||||
|
|
||||||
onCopyCell = (rowId: string, index: number) => {
|
onCopyCell = (rowId: string, index: number) => {
|
||||||
const cellText = getTextContentOfRow(rowId)[index];
|
const cellText = this.getTextContentOfRow(rowId)[index];
|
||||||
clipboard.writeText(cellText);
|
clipboard.writeText(cellText);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -564,11 +559,21 @@ class ManagedTable extends React.Component<
|
|||||||
.filter(row => highlightedRows.has(row.key))
|
.filter(row => highlightedRows.has(row.key))
|
||||||
.map(
|
.map(
|
||||||
(row: TableBodyRow) =>
|
(row: TableBodyRow) =>
|
||||||
row.copyText || getTextContentOfRow(row.key).join('\t'),
|
row.copyText || this.getTextContentOfRow(row.key).join('\t'),
|
||||||
)
|
)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getTextContentOfRow = (key: string): Array<string> => {
|
||||||
|
const row = this.props.rows.find(row => row.key === key);
|
||||||
|
if (!row) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return this.state.columnOrder
|
||||||
|
.filter(({visible}) => visible)
|
||||||
|
.map(({key}) => textContent(row.columns[key].value));
|
||||||
|
};
|
||||||
|
|
||||||
onScroll = debounce(
|
onScroll = debounce(
|
||||||
({
|
({
|
||||||
scrollDirection,
|
scrollDirection,
|
||||||
|
|||||||
Reference in New Issue
Block a user