2024-01-31 04:08:20 +00:00
|
|
|
import type { TableColumnsType } from 'antd';
|
|
|
|
import { Button, Table } from 'antd';
|
|
|
|
import { ReportDetail } from 'models';
|
|
|
|
import { useReportList } from 'queries/report';
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { useNavigate } from 'react-router-dom';
|
2024-01-31 11:57:42 +00:00
|
|
|
import { downloadReport } from 'request/report';
|
2024-01-31 04:08:20 +00:00
|
|
|
|
|
|
|
const ReportTable: React.FC = () => {
|
|
|
|
const { isLoading, data: reportData } = useReportList({
|
|
|
|
page_size: 100,
|
|
|
|
});
|
|
|
|
const report_data: any = reportData;
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
const [pagination, setPagination] = useState(() => ({
|
2024-01-31 09:54:39 +00:00
|
|
|
page: report_data?.page.total_pages || 1,
|
2024-01-31 04:08:20 +00:00
|
|
|
page_size: 10,
|
|
|
|
}));
|
|
|
|
|
2024-01-31 11:57:42 +00:00
|
|
|
const handleDownloadReport = async (report_id: string) => {
|
2024-02-02 07:14:46 +00:00
|
|
|
const {file, filename} = await downloadReport(report_id);
|
2024-01-31 11:57:42 +00:00
|
|
|
const anchorElement = document.createElement('a');
|
2024-02-02 07:14:46 +00:00
|
|
|
anchorElement.href = URL.createObjectURL(file);
|
|
|
|
anchorElement.download = filename;
|
2024-01-31 11:57:42 +00:00
|
|
|
|
|
|
|
document.body.appendChild(anchorElement);
|
|
|
|
anchorElement.click();
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
document.body.removeChild(anchorElement);
|
|
|
|
URL.revokeObjectURL(anchorElement.href);
|
|
|
|
};
|
|
|
|
|
2024-01-31 04:08:20 +00:00
|
|
|
const columns: TableColumnsType<ReportDetail> = [
|
|
|
|
{
|
|
|
|
title: 'ID',
|
|
|
|
dataIndex: 'ID',
|
|
|
|
key: 'ID',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Created Date',
|
|
|
|
dataIndex: 'Created Date',
|
|
|
|
key: 'Created Date',
|
2024-02-02 06:42:56 +00:00
|
|
|
render: (_, record) => {
|
|
|
|
return <span>{record['Created Date'].toString().split('T')[0]}</span>;
|
|
|
|
},
|
2024-01-31 04:08:20 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'No. Requests',
|
|
|
|
dataIndex: 'No. Requests',
|
|
|
|
key: 'No. Requests',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Status',
|
|
|
|
dataIndex: 'status',
|
|
|
|
key: 'status',
|
2024-01-31 11:57:42 +00:00
|
|
|
render: (_, record) => {
|
|
|
|
return <>{record.Status}</>;
|
|
|
|
},
|
2024-01-31 04:08:20 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Purchase Date Acc',
|
|
|
|
dataIndex: 'Purchase Date Acc',
|
|
|
|
key: 'Purchase Date Acc',
|
|
|
|
render: (_, record) => {
|
2024-02-02 09:41:47 +00:00
|
|
|
const isAbnormal = record['Purchase Date Acc'] * 100 < 98;
|
2024-01-31 04:08:20 +00:00
|
|
|
return (
|
2024-02-02 09:41:47 +00:00
|
|
|
<span style={{ color: isAbnormal ? 'red' : '' }}>
|
|
|
|
{record['Purchase Date Acc'] &&
|
|
|
|
(Number(record['Purchase Date Acc']) * 100)?.toFixed(2)}
|
|
|
|
</span>
|
2024-01-31 04:08:20 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
title: 'Retailer Acc',
|
|
|
|
dataIndex: 'Retailer Acc',
|
|
|
|
key: 'Retailer Acc',
|
|
|
|
render: (_, record) => {
|
2024-02-02 09:41:47 +00:00
|
|
|
const isAbnormal = record['Retailer Acc'] * 100 < 98;
|
2024-01-31 04:08:20 +00:00
|
|
|
return (
|
2024-02-02 09:41:47 +00:00
|
|
|
<span style={{ color: isAbnormal ? 'red' : '' }}>
|
|
|
|
{record['Retailer Acc'] &&
|
|
|
|
(Number(record['Retailer Acc']) * 100)?.toFixed(2)}
|
|
|
|
</span>
|
2024-01-31 04:08:20 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'IMEI Acc',
|
|
|
|
dataIndex: 'IMEI Acc',
|
|
|
|
key: 'IMEI Acc',
|
|
|
|
render: (_, record) => {
|
2024-02-02 09:41:47 +00:00
|
|
|
const isAbnormal = record['IMEI Acc'] * 100 < 98;
|
|
|
|
return (
|
|
|
|
<span style={{ color: isAbnormal ? 'red' : '' }}>
|
|
|
|
{record['IMEI Acc'] &&
|
|
|
|
(Number(record['IMEI Acc']) * 100)?.toFixed(2)}
|
|
|
|
</span>
|
|
|
|
);
|
2024-01-31 04:08:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Avg Accuracy',
|
|
|
|
dataIndex: 'Avg Accuracy',
|
|
|
|
key: 'Avg Accuracy',
|
|
|
|
render: (_, record) => {
|
2024-02-02 09:41:47 +00:00
|
|
|
const isAbnormal = record['Avg Accuracy'] * 100 < 98;
|
2024-01-31 04:08:20 +00:00
|
|
|
return (
|
2024-02-02 09:41:47 +00:00
|
|
|
<span style={{ color: isAbnormal ? 'red' : '' }}>
|
|
|
|
{record['Avg Accuracy'] &&
|
|
|
|
(Number(record['Avg Accuracy']) * 100)?.toFixed(2)}
|
|
|
|
</span>
|
2024-01-31 04:08:20 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Avg Client Request Time',
|
|
|
|
dataIndex: 'Avg. Client Request Time',
|
|
|
|
key: 'Avg. Client Request Time',
|
|
|
|
render: (_, record) => {
|
2024-02-02 09:41:47 +00:00
|
|
|
const isAbnormal = record['Avg Client Request Time'] > 2;
|
2024-01-31 04:08:20 +00:00
|
|
|
return (
|
2024-02-02 09:41:47 +00:00
|
|
|
<span style={{ color: isAbnormal ? 'red' : '' }}>
|
|
|
|
{record['Avg Client Request Time'] &&
|
|
|
|
Number(record['Avg Client Request Time'])?.toFixed(2)}
|
|
|
|
</span>
|
2024-01-31 04:08:20 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Avg. OCR Processing Time',
|
|
|
|
dataIndex: 'Avg. OCR Processing Time',
|
|
|
|
key: 'Avg. OCR Processing Time',
|
|
|
|
render: (_, record) => {
|
2024-02-02 09:41:47 +00:00
|
|
|
const isAbnormal = record['Avg. OCR Processing Time'] > 2;
|
2024-01-31 04:08:20 +00:00
|
|
|
return (
|
2024-02-02 09:41:47 +00:00
|
|
|
<span style={{ color: isAbnormal ? 'red' : '' }}>
|
|
|
|
{record['Avg. OCR Processing Time'] &&
|
|
|
|
Number(record['Avg. OCR Processing Time'])?.toFixed(2)}
|
|
|
|
</span>
|
2024-01-31 04:08:20 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Actions',
|
|
|
|
dataIndex: 'actions',
|
|
|
|
key: 'actions',
|
2024-02-05 07:31:18 +00:00
|
|
|
width: 210,
|
2024-01-31 04:08:20 +00:00
|
|
|
render: (_, record) => {
|
|
|
|
return (
|
|
|
|
<div style={{ flexDirection: 'row' }}>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
navigate(`/reports/${record.report_id}/detail`);
|
|
|
|
}}
|
|
|
|
style={{ marginRight: 10 }}
|
|
|
|
>
|
2024-02-05 07:31:18 +00:00
|
|
|
Details
|
2024-01-31 04:08:20 +00:00
|
|
|
</Button>
|
2024-01-31 11:57:42 +00:00
|
|
|
<Button onClick={() => handleDownloadReport(record.report_id)}>
|
|
|
|
Download
|
|
|
|
</Button>
|
2024-01-31 04:08:20 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Table
|
|
|
|
loading={isLoading}
|
|
|
|
columns={columns}
|
|
|
|
dataSource={(report_data && report_data?.report_detail) || []}
|
|
|
|
bordered
|
|
|
|
size='small'
|
|
|
|
pagination={{
|
|
|
|
current: pagination.page,
|
|
|
|
pageSize: pagination.page_size,
|
|
|
|
total: report_data?.count || 0,
|
|
|
|
onChange: (page, pageSize) => {
|
|
|
|
setPagination({ page, page_size: pageSize || 10 });
|
|
|
|
},
|
|
|
|
showSizeChanger: false,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ReportTable;
|