mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-27 09:58:14 +00:00
feat(ui): add copy function for stats table sample value (#5331)
This commit is contained in:
parent
558a65a3c3
commit
3a169c2a5f
@ -1,10 +1,11 @@
|
||||
import { Tag, Typography } from 'antd';
|
||||
import { Typography } from 'antd';
|
||||
import { ColumnsType, ColumnType } from 'antd/lib/table';
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { DatasetFieldProfile } from '../../../../../../../types.generated';
|
||||
import { StyledTable } from '../../../../components/styled/StyledTable';
|
||||
import { ANTD_GRAY } from '../../../../constants';
|
||||
import SampleValueTag from './SampleValueTag';
|
||||
|
||||
type Props = {
|
||||
columnStats: Array<DatasetFieldProfile>;
|
||||
@ -128,7 +129,7 @@ export default function ColumnStats({ columnStats }: Props) {
|
||||
(sampleValues &&
|
||||
sampleValues
|
||||
.slice(0, sampleValues.length < 3 ? sampleValues?.length : 3)
|
||||
.map((value) => <Tag>{value}</Tag>)) ||
|
||||
.map((value) => <SampleValueTag value={value} />)) ||
|
||||
unknownValue()
|
||||
);
|
||||
},
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Tag, Tooltip } from 'antd';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const StyledTag = styled(Tag)`
|
||||
cursor: pointer;
|
||||
max-width: 250px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
&&:hover {
|
||||
color: ${(props) => props.theme.styles['primary-color']};
|
||||
border-color: ${(props) => props.theme.styles['primary-color']};
|
||||
}
|
||||
`;
|
||||
|
||||
type Props = {
|
||||
value: string;
|
||||
};
|
||||
|
||||
export default function SampleValueTag({ value }: Props) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const onClick = () => {
|
||||
setCopied(true);
|
||||
navigator.clipboard.writeText(value);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
};
|
||||
|
||||
return (
|
||||
<Tooltip title={copied ? 'Copied' : 'Click to copy'}>
|
||||
<StyledTag onClick={onClick}>{value}</StyledTag>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user