fix: copy to Clipboard order (#16299)

* copy to Clipboard order

* centralized copyToClipboard

* fixed table order

* fixed tests

* added colnames to all viz types

* added colnames to all viz types

* added colnames to all viz types
This commit is contained in:
AAfghahi
2021-08-24 17:47:09 -04:00
committed by GitHub
parent e71c6e60e4
commit 631ad02a76
10 changed files with 84 additions and 38 deletions

View File

@@ -55,11 +55,15 @@ const CopyNode = (
export const CopyToClipboardButton = ({
data,
columns,
}: {
data?: Record<string, any>;
columns?: string[];
}) => (
<CopyToClipboard
text={data ? prepareCopyToClipboardTabularData(data) : ''}
text={
data && columns ? prepareCopyToClipboardTabularData(data, columns) : ''
}
wrapped={false}
copyNode={CopyNode}
/>
@@ -113,29 +117,32 @@ export const useFilteredTableData = (
}, [data, filterText]);
export const useTableColumns = (
colnames?: string[],
data?: Record<string, any>[],
moreConfigs?: { [key: string]: Partial<Column> },
) =>
useMemo(
() =>
data?.length
? Object.keys(data[0]).map(
key =>
({
accessor: row => row[key],
Header: key,
Cell: ({ value }) => {
if (value === true) {
return BOOL_TRUE_DISPLAY;
}
if (value === false) {
return BOOL_FALSE_DISPLAY;
}
return String(value);
},
...moreConfigs?.[key],
} as Column),
)
colnames && data?.length
? colnames
.filter((column: string) => Object.keys(data[0]).includes(column))
.map(
key =>
({
accessor: row => row[key],
Header: key,
Cell: ({ value }) => {
if (value === true) {
return BOOL_TRUE_DISPLAY;
}
if (value === false) {
return BOOL_FALSE_DISPLAY;
}
return String(value);
},
...moreConfigs?.[key],
} as Column),
)
: [],
[data, moreConfigs],
);