WhiteNightsAdminPanel/src/pages/station/list.tsx
2025-04-06 23:16:24 +03:00

127 lines
3.1 KiB
TypeScript

import React from 'react'
import {type GridColDef} from '@mui/x-data-grid'
import {DeleteButton, EditButton, List, ShowButton, useDataGrid} from '@refinedev/mui'
import {Stack} from '@mui/material'
import {CustomDataGrid} from '../../components/CustomDataGrid'
import {localeText} from '../../locales/ru/localeText'
export const StationList = () => {
const {dataGridProps} = useDataGrid({resource: 'station/'})
const columns = React.useMemo<GridColDef[]>(
() => [
{
field: 'id',
headerName: 'ID',
type: 'number',
minWidth: 70,
display: 'flex',
align: 'left',
headerAlign: 'left',
},
{
field: 'name',
headerName: 'Название',
type: 'string',
minWidth: 300,
display: 'flex',
align: 'left',
headerAlign: 'left',
},
{
field: 'system_name',
headerName: 'Системное название',
type: 'string',
minWidth: 200,
display: 'flex',
align: 'left',
headerAlign: 'left',
},
{
field: 'latitude',
headerName: 'Широта',
type: 'number',
minWidth: 150,
display: 'flex',
align: 'left',
headerAlign: 'left',
},
{
field: 'longitude',
headerName: 'Долгота',
type: 'number',
minWidth: 150,
display: 'flex',
align: 'left',
headerAlign: 'left',
},
{
field: 'city_id',
headerName: 'ID города',
type: 'number',
minWidth: 120,
display: 'flex',
align: 'left',
headerAlign: 'left',
},
{
field: 'offset_x',
headerName: 'Смещение (X)',
type: 'number',
minWidth: 120,
display: 'flex',
align: 'left',
headerAlign: 'left',
},
{
field: 'offset_y',
headerName: 'Смещение (Y)',
type: 'number',
minWidth: 120,
display: 'flex',
align: 'left',
headerAlign: 'left',
},
{
field: 'description',
headerName: 'Описание',
type: 'string',
display: 'flex',
align: 'left',
headerAlign: 'left',
flex: 1,
},
{
field: 'actions',
headerName: 'Действия',
cellClassName: 'station-actions',
align: 'right',
headerAlign: 'center',
minWidth: 120,
display: 'flex',
sortable: false,
filterable: false,
disableColumnMenu: true,
renderCell: function render({row}) {
return (
<>
<EditButton hideText recordItemId={row.id} />
<ShowButton hideText recordItemId={row.id} />
<DeleteButton hideText confirmTitle="Вы уверены?" recordItemId={row.id} />
</>
)
},
},
],
[],
)
return (
<List>
<Stack gap={2.5}>
<CustomDataGrid {...dataGridProps} columns={columns} localeText={localeText} getRowId={(row: any) => row.id} hasCoordinates />
</Stack>
</List>
)
}