edit tanstak-table
This commit is contained in:
@@ -19,6 +19,7 @@ import { getUserFilesData, removeUserFile } from '@/app/actions/fileEntity';
|
|||||||
import ModalWindow from '@/app/components/modalWindow';
|
import ModalWindow from '@/app/components/modalWindow';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { pluralize } from '@/app/lib/pluralize';
|
import { pluralize } from '@/app/lib/pluralize';
|
||||||
|
import { convertBytes } from '@/app/lib/convertBytes';
|
||||||
|
|
||||||
type FileType = 'image' | 'video' | 'audio';
|
type FileType = 'image' | 'video' | 'audio';
|
||||||
|
|
||||||
@@ -27,8 +28,9 @@ type FileItem = {
|
|||||||
fileName: string;
|
fileName: string;
|
||||||
fileType: string;
|
fileType: string;
|
||||||
violations?: number | undefined;
|
violations?: number | undefined;
|
||||||
checks?: number | undefined;
|
size?: number | undefined;
|
||||||
lastCheck?: number;
|
uploadDate?: number;
|
||||||
|
status?: string;
|
||||||
_original?: ApiFile;
|
_original?: ApiFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -37,8 +39,9 @@ type ApiFile = {
|
|||||||
originalFileName: string;
|
originalFileName: string;
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
violations: number;
|
violations: number;
|
||||||
checks: number;
|
fileSize: number;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
|
status: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ApiResponse = {
|
type ApiResponse = {
|
||||||
@@ -95,16 +98,22 @@ const cutFileName = (fileName: string) => {
|
|||||||
const extension = fileName.substring(lastDotIndex);
|
const extension = fileName.substring(lastDotIndex);
|
||||||
|
|
||||||
if (fileName.length <= MAX_FILE_NAME_LENGTH) {
|
if (fileName.length <= MAX_FILE_NAME_LENGTH) {
|
||||||
return fileName;
|
return nameWithoutExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxNameLength = MAX_FILE_NAME_LENGTH - extension.length - 3;
|
const maxNameLength = MAX_FILE_NAME_LENGTH - extension.length - 3;
|
||||||
|
|
||||||
if (maxNameLength <= 0) {
|
if (maxNameLength <= 0) {
|
||||||
return '...' + extension;
|
return '...' /* + extension */;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nameWithoutExtension.substring(0, maxNameLength) + '...' + extension;
|
return nameWithoutExtension.substring(0, maxNameLength) + '...' /* + extension */;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cutFileExtension = (fileName: string) => {
|
||||||
|
const lastDotIndex = fileName.lastIndexOf('.');
|
||||||
|
const extension = fileName.substring(lastDotIndex + 1);
|
||||||
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
||||||
@@ -131,8 +140,9 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
fileName: item.originalFileName,
|
fileName: item.originalFileName,
|
||||||
fileType: item.mimeType.toLocaleLowerCase(),
|
fileType: item.mimeType.toLocaleLowerCase(),
|
||||||
violations: item.violations,
|
violations: item.violations,
|
||||||
checks: item.checks,
|
size: item.fileSize,
|
||||||
lastCheck: newDate,
|
uploadDate: newDate,
|
||||||
|
status: item.status,
|
||||||
_original: item
|
_original: item
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -195,48 +205,15 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
<div className="font-medium w-full truncate" title={row.original.fileName}>
|
<div className="font-medium w-full truncate" title={row.original.fileName}>
|
||||||
{/* {row.original.fileName} */}
|
{/* {row.original.fileName} */}
|
||||||
{cutFileName(row.original.fileName)}
|
{cutFileName(row.original.fileName)}
|
||||||
|
<br />
|
||||||
|
{cutFileExtension(row.original.fileName)} • <span className="text-[#10b981]">{row.original?.status}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
},
|
},
|
||||||
{
|
/* {
|
||||||
accessorKey: 'status',
|
|
||||||
header: ({ column }) => (
|
|
||||||
<div className="column">
|
|
||||||
<span>
|
|
||||||
{t('status')}
|
|
||||||
</span>
|
|
||||||
<button
|
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
||||||
className="sort-button"
|
|
||||||
>
|
|
||||||
{
|
|
||||||
column.getIsSorted() === 'asc' ?
|
|
||||||
<span>
|
|
||||||
<IconArrowUp />
|
|
||||||
</span>
|
|
||||||
: column.getIsSorted() === 'desc' ?
|
|
||||||
<span>
|
|
||||||
<IconArrowDown />
|
|
||||||
</span>
|
|
||||||
: <span>
|
|
||||||
<IconFilter />
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
cell: ({ row }) => {
|
|
||||||
return (
|
|
||||||
<div className={`text-center font-semibold`}>
|
|
||||||
{t('status')}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'violations',
|
accessorKey: 'violations',
|
||||||
header: ({ column }) => (
|
header: ({ column }) => (
|
||||||
<div className="column">
|
<div className="column">
|
||||||
@@ -277,13 +254,13 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
}, */
|
||||||
{
|
{
|
||||||
accessorKey: 'checks',
|
accessorKey: 'size',
|
||||||
header: ({ column }) => (
|
header: ({ column }) => (
|
||||||
<div className="column">
|
<div className="column">
|
||||||
<span>
|
<span>
|
||||||
{t('checks')}
|
{t('size')}
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
@@ -307,16 +284,16 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
),
|
),
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
{row.original.checks !== undefined ? row.original.checks : '-'}
|
{row.original.size !== undefined ? convertBytes(row.original.size) : '-'}
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'lastCheck',
|
accessorKey: 'uploadDate',
|
||||||
header: ({ column }) => (
|
header: ({ column }) => (
|
||||||
<div className="column">
|
<div className="column">
|
||||||
<span>
|
<span>
|
||||||
{t('last-check')}
|
{t('upload-date')}
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
@@ -341,11 +318,11 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return (
|
return (
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
{row.original.lastCheck ? (
|
{row.original.uploadDate ? (
|
||||||
<>
|
<>
|
||||||
{formatDate(row.original.lastCheck)}
|
{formatDate(row.original.uploadDate)}
|
||||||
<br />
|
<br />
|
||||||
{formatDateTime(row.original.lastCheck)}
|
{formatDateTime(row.original.uploadDate)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<div>-</div>
|
<div>-</div>
|
||||||
@@ -355,6 +332,41 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
},
|
},
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'status',
|
||||||
|
header: ({ column }) => (
|
||||||
|
<div className="column">
|
||||||
|
<span>
|
||||||
|
{t('status')}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
className="sort-button"
|
||||||
|
>
|
||||||
|
{
|
||||||
|
column.getIsSorted() === 'asc' ?
|
||||||
|
<span>
|
||||||
|
<IconArrowUp />
|
||||||
|
</span>
|
||||||
|
: column.getIsSorted() === 'desc' ?
|
||||||
|
<span>
|
||||||
|
<IconArrowDown />
|
||||||
|
</span>
|
||||||
|
: <span>
|
||||||
|
<IconFilter />
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div className={`text-center font-semibold`}>
|
||||||
|
{t('status')}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => {
|
header: () => {
|
||||||
@@ -535,8 +547,8 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
case 'today':
|
case 'today':
|
||||||
const todayStart = new Date().setHours(0, 0, 0, 0);
|
const todayStart = new Date().setHours(0, 0, 0, 0);
|
||||||
result = result.filter(item => {
|
result = result.filter(item => {
|
||||||
if (item.lastCheck) {
|
if (item.uploadDate) {
|
||||||
return item.lastCheck >= todayStart
|
return item.uploadDate >= todayStart
|
||||||
} else {
|
} else {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -545,24 +557,24 @@ export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
|||||||
case 'week':
|
case 'week':
|
||||||
const weekAgo = now - sevenDays;
|
const weekAgo = now - sevenDays;
|
||||||
result = result.filter(item => {
|
result = result.filter(item => {
|
||||||
if (item.lastCheck) {
|
if (item.uploadDate) {
|
||||||
return item.lastCheck >= weekAgo;
|
return item.uploadDate >= weekAgo;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'month':
|
case 'month':
|
||||||
const monthAgo = now - thirtyDays;
|
const monthAgo = now - thirtyDays;
|
||||||
result = result.filter(item => {
|
result = result.filter(item => {
|
||||||
if (item.lastCheck) {
|
if (item.uploadDate) {
|
||||||
return item.lastCheck >= monthAgo;
|
return item.uploadDate >= monthAgo;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'older':
|
case 'older':
|
||||||
const monthAgo2 = now - thirtyDays;
|
const monthAgo2 = now - thirtyDays;
|
||||||
result = result.filter(item => {
|
result = result.filter(item => {
|
||||||
if (item.lastCheck) {
|
if (item.uploadDate) {
|
||||||
return item.lastCheck < monthAgo2;
|
return item.uploadDate < monthAgo2;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -173,7 +173,8 @@
|
|||||||
"my-content-description": "Managing protected files and copyright control",
|
"my-content-description": "Managing protected files and copyright control",
|
||||||
"monitoring-copyright-infringements": "Monitoring copyright infringements",
|
"monitoring-copyright-infringements": "Monitoring copyright infringements",
|
||||||
"monitoring-copyright-infringements-description": "Monitor and manage copyright infringement of your protected content online",
|
"monitoring-copyright-infringements-description": "Monitor and manage copyright infringement of your protected content online",
|
||||||
"referral-program-description": "Invite your friends and earn up to 25% commission on every purchase! Share the link and get rewarded."
|
"referral-program-description": "Invite your friends and earn up to 25% commission on every purchase! Share the link and get rewarded.",
|
||||||
|
"upload-date": "Upload date"
|
||||||
},
|
},
|
||||||
"Login-register-form": {
|
"Login-register-form": {
|
||||||
"and": "and",
|
"and": "and",
|
||||||
|
|||||||
@@ -173,7 +173,8 @@
|
|||||||
"my-content-description": "Управление защищенными файлами и контролем авторских прав",
|
"my-content-description": "Управление защищенными файлами и контролем авторских прав",
|
||||||
"monitoring-copyright-infringements": "Мониторинг нарушений авторских прав",
|
"monitoring-copyright-infringements": "Мониторинг нарушений авторских прав",
|
||||||
"monitoring-copyright-infringements-description": "Отслеживание и управление нарушениями авторских прав на ваш защищенный контент в интернете",
|
"monitoring-copyright-infringements-description": "Отслеживание и управление нарушениями авторских прав на ваш защищенный контент в интернете",
|
||||||
"referral-program-description": "Приглашайте друзей и зарабатывайте до 25% комиссии с каждой их покупки! Делитесь ссылкой, получайте вознаграждение."
|
"referral-program-description": "Приглашайте друзей и зарабатывайте до 25% комиссии с каждой их покупки! Делитесь ссылкой, получайте вознаграждение.",
|
||||||
|
"upload-date": "Дата загрузки"
|
||||||
},
|
},
|
||||||
"Login-register-form": {
|
"Login-register-form": {
|
||||||
"and": "и",
|
"and": "и",
|
||||||
|
|||||||
Reference in New Issue
Block a user