Skip to content

copy row #803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 29 additions & 34 deletions frontend/src/components/FileTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const FileTable = forwardRef<ChildRef, FileTableProps>((props, ref) => {
const skipPageResetRef = useRef<boolean>(false);
const [_, copy] = useCopyToClipboard();
const { colorMode } = useContext(ThemeWrapperContext);
const [copyRow, setCopyRow] = useState<boolean>(false);

const tableRef = useRef(null);

Expand All @@ -83,8 +84,13 @@ const FileTable = forwardRef<ChildRef, FileTableProps>((props, ref) => {
}
);

const handleCopy = (message: string) => {
copy(message);
const handleCopy = (rowData: any) => {
const rowString = JSON.stringify(rowData, null, 2);
copy(rowString);
setCopyRow(true);
setTimeout(() => {
setCopyRow(false);
}, 5000);
};
const columns = useMemo(
() => [
Expand Down Expand Up @@ -154,18 +160,14 @@ const FileTable = forwardRef<ChildRef, FileTableProps>((props, ref) => {
cell: (info) => {
if (info.getValue() != 'Processing') {
return (
<Tip allowedPlacements={['left']}>
<div
className='cellClass'
title={info.row.original?.status === 'Failed' ? info.row.original?.errorMessage : ''}
>
<Tip.Trigger>
<StatusIndicator type={statusCheck(info.getValue())} />
{info.getValue()}
</Tip.Trigger>
{(info.getValue() === 'Completed' ||
info.getValue() === 'Failed' ||
(info.getValue() === 'Cancelled' && !isReadOnlyUser)) && (
<div
className='cellClass'
title={info.row.original?.status === 'Failed' ? info.row.original?.errorMessage : ''}
>
<StatusIndicator type={statusCheck(info.getValue())} />
{info.getValue()}
{(info.getValue() === 'Completed' || info.getValue() === 'Failed' || info.getValue() === 'Cancelled') &&
!isReadOnlyUser && (
<span className='mx-1'>
<IconButtonWithToolTip
placement='right'
Expand All @@ -179,25 +181,7 @@ const FileTable = forwardRef<ChildRef, FileTableProps>((props, ref) => {
</IconButtonWithToolTip>
</span>
)}
</div>

{info.row.original?.status === 'Failed' && (
<Tip.Content>
<IconButton
aria-label='error copy'
clean
label='copy error'
size='small'
onClick={() => handleCopy(info.row.original?.errorMessage ?? '')}
>
<ClipboardDocumentIconOutline
color={colorMode === 'light' ? 'white' : ''}
className='w-4 h-4 inline-block'
/>
</IconButton>
</Tip.Content>
)}
</Tip>
</div>
);
} else if (info.getValue() === 'Processing' && info.row.original.processingProgress === undefined) {
return (
Expand Down Expand Up @@ -531,9 +515,20 @@ const FileTable = forwardRef<ChildRef, FileTableProps>((props, ref) => {
>
<MagnifyingGlassCircleIconSolid />
</IconButtonWithToolTip>
<IconButtonWithToolTip
placement='left'
text='copy'
size='large'
label='Copy Row'
disabled={info.getValue() === 'Uploading'}
clean
onClick={() => handleCopy(info.row.original)}
>
<ClipboardDocumentIconOutline className={`${copyRow} ? 'cursor-wait': 'cursor`} />
</IconButtonWithToolTip>
</>
),
header: () => <span>View</span>,
header: () => <span>Actions</span>,
footer: (info) => info.column.id,
}),
],
Expand Down