add preview for images in tanstak-table

This commit is contained in:
smanylov
2026-04-24 12:08:43 +07:00
parent e09cd3a77c
commit 47bf0b3e77
2 changed files with 37 additions and 3 deletions
@@ -12,7 +12,7 @@ import {
ColumnFiltersState, ColumnFiltersState,
PaginationState PaginationState
} from '@tanstack/react-table'; } from '@tanstack/react-table';
import { IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter, IconFileDownload, IconInfo, IconEye, IconCheck } from '@/app/ui/icons/icons'; import { IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter, IconFileDownload, IconInfo, IconEye, IconCheck, IconImageFile } from '@/app/ui/icons/icons';
import { useTranslations, useLocale } from 'next-intl'; import { useTranslations, useLocale } from 'next-intl';
import DropDownList from '@/app/components/DropDownList'; import DropDownList from '@/app/components/DropDownList';
import { useQuery, useQueryClient } from '@tanstack/react-query'; import { useQuery, useQueryClient } from '@tanstack/react-query';
@@ -31,6 +31,7 @@ import { downloadFile } from '@/app/actions/fileEntity';
import { useDebouncedCallback } from 'use-debounce'; import { useDebouncedCallback } from 'use-debounce';
import Link from 'next/link'; import Link from 'next/link';
import { SelectedFilesAction } from '@/app/components/tanstak-table/SelectedFilesActions'; import { SelectedFilesAction } from '@/app/components/tanstak-table/SelectedFilesActions';
import Image from 'next/image';
export type FileItem = { export type FileItem = {
id: string; id: string;
@@ -44,6 +45,7 @@ export type FileItem = {
protectStatus: string; protectStatus: string;
_original?: ApiFile; _original?: ApiFile;
supportId: number; supportId: number;
thumbnailFileUrl: string
}; };
type ApiFile = { type ApiFile = {
@@ -58,6 +60,7 @@ type ApiFile = {
protectStatus: string; protectStatus: string;
supportId: number; supportId: number;
fileName: string; fileName: string;
thumbnailFileUrl: string;
}; };
type ApiResponse = { type ApiResponse = {
@@ -175,6 +178,8 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
return { items: [], total_count: 0, page: 1, pageSize: pagination.pageSize }; return { items: [], total_count: 0, page: 1, pageSize: pagination.pageSize };
} }
/* console.log(data.files) */;
const items = data.files.map((item: ApiFile) => ({ const items = data.files.map((item: ApiFile) => ({
id: item.id, id: item.id,
fileName: item.originalFileName, fileName: item.originalFileName,
@@ -186,7 +191,8 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
monitoring: item.monitoring, monitoring: item.monitoring,
protectStatus: item.protectStatus, protectStatus: item.protectStatus,
supportId: item.supportId, supportId: item.supportId,
_original: item _original: item,
thumbnailFileUrl: item.thumbnailFileUrl
})); }));
return { return {
@@ -392,7 +398,25 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
), ),
cell: ({ row }) => ( cell: ({ row }) => (
<div className="flex items-center space-x-2 table-item table-item-file-name"> <div className="flex items-center space-x-2 table-item table-item-file-name">
<FileTypeIcon type={row.original.fileType} /> {row.original.fileType === 'image' && row.original?.thumbnailFileUrl.length !== 0 ? (
<span
className="table-item-file-name-image-wrapper"
>
<Image
sizes="40px"
src={row.original?.thumbnailFileUrl}
alt={row.original?.fileName}
unoptimized
fill
onError={(e) => {
const target = e.target as HTMLImageElement;
target.src = '/images/no-image.png';
}}
/>
</span>
) : (
<FileTypeIcon type={row.original.fileType} />
)}
<div> <div>
<div className="font-medium w-full truncate" title={row.original.fileName}> <div className="font-medium w-full truncate" title={row.original.fileName}>
<span className="font-semibold"> <span className="font-semibold">
+10
View File
@@ -901,6 +901,16 @@
padding: 15px 16px; padding: 15px 16px;
} }
} }
.table-item-file-name-image-wrapper {
width: 40px;
height: 40px;
position: relative;
img {
object-fit: contain;
}
}
} }
.table-item { .table-item {