Files
Alberto-Audrix 32a36cceff
CI / lint-and-test (push) Canceled after 0s
first commit
2026-07-28 08:55:05 +07:00

125 lines
4.8 KiB
TypeScript

import React from 'react';
import { BatchService, BatchJob, BatchJobStatus, BatchServiceType } from '../../types';
const serviceTypeConfig: { [key in BatchServiceType]: { icon: string; color: string } } = {
[BatchServiceType.DATA_INGESTION]: { icon: 'fa-database', color: 'text-blue-500' },
[BatchServiceType.CCTV_CHICKEN_COUNT]: { icon: 'fa-calculator', color: 'text-cyan-500' },
[BatchServiceType.CCTV_SACK_COUNT]: { icon: 'fa-sack-dollar', color: 'text-amber-600' },
[BatchServiceType.BEHAVIOR_ANALYSIS]: { icon: 'fa-chart-simple', color: 'text-pink-500' },
[BatchServiceType.WEIGHT_ANALYSIS]: { icon: 'fa-chart-line', color: 'text-teal-500' },
[BatchServiceType.AI_TRAINING]: { icon: 'fa-robot', color: 'text-purple-500' },
[BatchServiceType.REPORTING]: { icon: 'fa-file-alt', color: 'text-green-600' },
[BatchServiceType.DATABASE_MAINTENANCE]: { icon: 'fa-broom', color: 'text-orange-500' },
[BatchServiceType.ERP_SYNC]: { icon: 'fa-shuffle', color: 'text-slate-500' },
};
const jobStatusConfig: { [key in BatchJobStatus]: { text: string; color: string; icon: string } } =
{
[BatchJobStatus.COMPLETED]: {
text: 'Selesai',
color: 'bg-green-100 text-green-700',
icon: 'fa-check-circle',
},
[BatchJobStatus.RUNNING]: {
text: 'Berjalan',
color: 'bg-blue-100 text-blue-700',
icon: 'fa-spin fa-spinner',
},
[BatchJobStatus.FAILED]: {
text: 'Gagal',
color: 'bg-red-100 text-red-700',
icon: 'fa-times-circle',
},
[BatchJobStatus.PENDING]: {
text: 'Tertunda',
color: 'bg-yellow-100 text-yellow-700',
icon: 'fa-clock',
},
};
const formatDuration = (start: Date, end: Date | null): string => {
if (!end) return '-';
const duration = end.getTime() - start.getTime();
if (duration < 1000) return `${duration} ms`;
const seconds = duration / 1000;
if (seconds < 60) return `${seconds.toFixed(1)} detik`;
const minutes = seconds / 60;
return `${minutes.toFixed(2)} menit`;
};
interface ServiceCardProps {
service: BatchService;
jobs: BatchJob[];
}
const ServiceCard: React.FC<ServiceCardProps> = ({ service, jobs }) => {
const lastJob = jobs[0];
const config = serviceTypeConfig[service.type];
const lastRunStatus = lastJob
? jobStatusConfig[lastJob.status]
: jobStatusConfig[BatchJobStatus.PENDING];
return (
<div className="border border-gray-200 rounded-lg">
<div className="p-4 bg-gray-50/70 rounded-t-lg border-b">
<div className="flex flex-col sm:flex-row justify-between sm:items-center gap-2">
<div className="flex items-center gap-3">
<i className={`fa-solid ${config.icon} text-2xl ${config.color}`}></i>
<div>
<h3 className="font-bold text-gray-800">{service.name}</h3>
<p className="text-xs text-gray-500 font-medium">
{service.type} &bull; {service.schedule}
</p>
</div>
</div>
<div
className={`flex items-center space-x-2 px-3 py-1 text-sm font-semibold rounded-full ${lastRunStatus.color}`}
>
<i className={`fa-solid ${lastRunStatus.icon}`}></i>
<span>Status Terakhir: {lastRunStatus.text}</span>
</div>
</div>
</div>
<div className="overflow-x-auto">
<table className="min-w-full text-sm">
<thead className="text-left text-gray-500">
<tr>
<th className="p-3 font-semibold">ID Pekerjaan</th>
<th className="p-3 font-semibold">Status</th>
<th className="p-3 font-semibold">Waktu Mulai</th>
<th className="p-3 font-semibold">Durasi</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-100">
{jobs.slice(0, 5).map((job) => {
const status = jobStatusConfig[job.status];
return (
<tr key={job.id}>
<td className="p-3 font-mono text-gray-600">{job.id}</td>
<td className="p-3">
<span
className={`inline-flex items-center space-x-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${status.color}`}
>
<i className={`fa-solid ${status.icon}`}></i>
<span>{status.text}</span>
</span>
</td>
<td className="p-3 text-gray-700">{job.startTime.toLocaleString('id-ID')}</td>
<td className="p-3 font-semibold text-gray-800">
{formatDuration(job.startTime, job.endTime)}
</td>
</tr>
);
})}
</tbody>
</table>
{jobs.length === 0 && (
<p className="p-4 text-center text-gray-500">Tidak ada riwayat pekerjaan.</p>
)}
</div>
</div>
);
};
export default ServiceCard;