73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import {type GridColDef} from '@mui/x-data-grid'
|
|
import {CustomDataGrid} from '../../components/CustomDataGrid'
|
|
import {DeleteButton, EditButton, List, ShowButton, useDataGrid} from '@refinedev/mui'
|
|
import React from 'react'
|
|
import {MEDIA_TYPES} from '../../lib/constants'
|
|
|
|
import {localeText} from '../../locales/ru/localeText'
|
|
|
|
export const MediaList = () => {
|
|
const {dataGridProps} = useDataGrid({})
|
|
|
|
const columns = React.useMemo<GridColDef[]>(
|
|
() => [
|
|
{
|
|
field: 'id',
|
|
headerName: 'ID',
|
|
type: 'number',
|
|
minWidth: 350,
|
|
display: 'flex',
|
|
align: 'left',
|
|
headerAlign: 'left',
|
|
},
|
|
{
|
|
field: 'filename',
|
|
headerName: 'Название',
|
|
type: 'string',
|
|
minWidth: 250,
|
|
display: 'flex',
|
|
align: 'left',
|
|
headerAlign: 'left',
|
|
},
|
|
{
|
|
field: 'media_type',
|
|
headerName: 'Тип',
|
|
type: 'string',
|
|
display: 'flex',
|
|
align: 'left',
|
|
headerAlign: 'left',
|
|
flex: 1,
|
|
renderCell: (params) => {
|
|
const value = params.row.media_type
|
|
return MEDIA_TYPES.find((type) => type.value === value)?.label || value
|
|
},
|
|
},
|
|
{
|
|
field: 'actions',
|
|
headerName: 'Действия',
|
|
minWidth: 120,
|
|
display: 'flex',
|
|
align: 'right',
|
|
headerAlign: 'center',
|
|
sortable: false,
|
|
renderCell: function render({row}) {
|
|
return (
|
|
<>
|
|
<EditButton hideText recordItemId={row.id} />
|
|
<ShowButton hideText recordItemId={row.id} />
|
|
<DeleteButton hideText recordItemId={row.id} />
|
|
</>
|
|
)
|
|
},
|
|
},
|
|
],
|
|
[],
|
|
)
|
|
|
|
return (
|
|
<List>
|
|
<CustomDataGrid {...dataGridProps} columns={columns} localeText={localeText} getRowId={(row: any) => row.id} />
|
|
</List>
|
|
)
|
|
}
|