Restore copy on text

Summary:
Some folks were missing the copy as text ManagedTable used to have, so introduced both the options to either copy as text (visible columns or custom copy handler) or as JSON

Changelog: It is now possible to both copy as text or as JSON from data tables

Reviewed By: jknoxville

Differential Revision: D29712096

fbshipit-source-id: 27bd2e869a247bd0896ce2774c08651123fd531d
This commit is contained in:
Michel Weststrate
2021-07-16 03:42:14 -07:00
committed by Facebook GitHub Bot
parent 1e93055eb5
commit d23ccfcd44
13 changed files with 116 additions and 44 deletions

View File

@@ -10,7 +10,7 @@
import React, {CSSProperties, memo} from 'react';
import styled from '@emotion/styled';
import {theme} from '../theme';
import type {TableRowRenderContext} from './DataTable';
import {DataTableColumn, TableRowRenderContext} from './DataTable';
import {Width} from '../../utils/widthUtils';
import {DataFormatter} from '../DataFormatter';
import {Dropdown} from 'antd';
@@ -121,9 +121,12 @@ export const TableRow = memo(function TableRow<T>({
{config.columns
.filter((col) => col.visible)
.map((col) => {
const value = col.onRender
? (col as any).onRender(record, highlighted, itemIndex)
: DataFormatter.format((record as any)[col.key], col.formatters);
const value = renderColumnValue<T>(
col,
record,
highlighted,
itemIndex,
);
return (
<TableBodyColumnContainer
@@ -147,3 +150,14 @@ export const TableRow = memo(function TableRow<T>({
return row;
}
});
export function renderColumnValue<T>(
col: DataTableColumn<any>,
record: T,
highlighted: boolean,
itemIndex: number,
) {
return col.onRender
? col.onRender(record, highlighted, itemIndex)
: DataFormatter.format((record as any)[col.key], col.formatters);
}