Add embedded active equipment view for Drill iframe

This commit is contained in:
MaKarin
2026-04-04 11:13:10 +03:00
parent 60e07e9c6e
commit c766b556fb
2 changed files with 103 additions and 1 deletions

View File

@@ -0,0 +1,90 @@
import Alert from '@mui/material/Alert';
import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import Paper from '@mui/material/Paper';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Typography from '@mui/material/Typography';
import { useGetList } from 'react-admin';
type EquipmentRecord = {
id: string;
name: string;
serialNumber: string;
dateOfInspection: string | null;
commissionedAt: string | null;
};
function formatDate(value: string | null) {
if (!value) {
return '-';
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return value;
}
return new Intl.DateTimeFormat('ru-RU').format(date);
}
export function EmbeddedActiveEquipmentPage() {
const { data, total, isPending, error } = useGetList<EquipmentRecord>('equipment', {
pagination: { page: 1, perPage: 100 },
sort: { field: 'name', order: 'ASC' },
filter: { status: ['Active'] },
});
return (
<Box sx={{ minHeight: '100vh', boxSizing: 'border-box', p: { xs: 2, md: 3 }, bgcolor: '#f3f6fa' }}>
<Paper elevation={0} sx={{ overflow: 'hidden', borderRadius: 3, border: '1px solid #d7e0ea' }}>
<Box sx={{ px: 3, py: 2, borderBottom: '1px solid #d7e0ea', bgcolor: '#fff' }}>
<Typography variant="h5" sx={{ fontWeight: 700, color: '#10233a' }}>
Оборудование в эксплуатации
</Typography>
<Typography variant="body2" sx={{ mt: 0.5, color: '#5b7087' }}>
Отображаются записи со статусом `Active`
{typeof total === 'number' ? `: ${total}` : ''}
</Typography>
</Box>
{isPending ? (
<Box sx={{ display: 'flex', justifyContent: 'center', py: 8 }}>
<CircularProgress />
</Box>
) : error ? (
<Box sx={{ p: 3 }}>
<Alert severity="error">Не удалось загрузить активное оборудование.</Alert>
</Box>
) : (
<TableContainer>
<Table size="small">
<TableHead>
<TableRow>
<TableCell sx={{ fontWeight: 700 }}>Наименование</TableCell>
<TableCell sx={{ fontWeight: 700 }}>Заводской номер</TableCell>
<TableCell sx={{ fontWeight: 700 }}>Дата изготовления</TableCell>
<TableCell sx={{ fontWeight: 700 }}>Дата поверки</TableCell>
</TableRow>
</TableHead>
<TableBody>
{(data ?? []).map((item) => (
<TableRow key={item.id} hover>
<TableCell>{item.name}</TableCell>
<TableCell>{item.serialNumber}</TableCell>
<TableCell>{formatDate(item.dateOfInspection)}</TableCell>
<TableCell>{formatDate(item.commissionedAt)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
)}
</Paper>
</Box>
);
}