2024-03-17 12:58:25 +01:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { FC } from "react";
|
|
|
|
|
import { Grid, Box } from "@mui/material";
|
|
|
|
|
import { DataGridPro, GridColDef } from "@mui/x-data-grid-pro";
|
2024-04-24 21:44:05 +02:00
|
|
|
import { typography, colors } from "../styles/theme";
|
2024-03-17 12:58:25 +01:00
|
|
|
|
|
|
|
|
interface ListProps {
|
|
|
|
|
title: string;
|
|
|
|
|
rows: any;
|
|
|
|
|
columns: GridColDef<any>[];
|
2024-04-21 20:47:55 +02:00
|
|
|
onRowClick?: (id: string) => void;
|
2024-05-09 07:42:44 +02:00
|
|
|
getRowID?: (row: any) => any;
|
2024-03-17 12:58:25 +01:00
|
|
|
buttons?: React.ReactNode;
|
2024-04-24 21:44:05 +02:00
|
|
|
paginate?: boolean;
|
2024-03-17 12:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-21 20:47:55 +02:00
|
|
|
export const List: FC<ListProps> = ({
|
|
|
|
|
title,
|
|
|
|
|
rows,
|
|
|
|
|
columns,
|
2024-04-23 13:36:51 +02:00
|
|
|
onRowClick,
|
2024-05-09 07:42:44 +02:00
|
|
|
getRowID,
|
2024-04-21 20:47:55 +02:00
|
|
|
buttons,
|
2024-04-24 21:44:05 +02:00
|
|
|
paginate = false,
|
2024-04-21 20:47:55 +02:00
|
|
|
}) => {
|
2024-03-17 12:58:25 +01:00
|
|
|
const { h3 } = typography;
|
2024-04-24 21:44:05 +02:00
|
|
|
const { mediumGray, lightGray, veryLightGray, mediumBlue, white, darkGray } =
|
|
|
|
|
colors;
|
2024-05-09 07:42:44 +02:00
|
|
|
const getRowIDInternal = (row: any) => {
|
|
|
|
|
if (getRowID) {
|
|
|
|
|
return getRowID(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return row.id;
|
|
|
|
|
};
|
2024-03-17 12:58:25 +01:00
|
|
|
|
|
|
|
|
return (
|
2024-09-09 10:19:36 +02:00
|
|
|
<Box sx={{ height: "100%", p: 3 }}>
|
|
|
|
|
<Grid container direction="column" sx={{ height: "100%", flexWrap: "nowrap" }}>
|
2024-04-24 21:44:05 +02:00
|
|
|
<Grid
|
|
|
|
|
item
|
|
|
|
|
container
|
|
|
|
|
direction="row"
|
|
|
|
|
justifyContent="space-between"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
>
|
|
|
|
|
<Grid item xs="auto">
|
2024-03-17 12:58:25 +01:00
|
|
|
<Box sx={h3}>{title}</Box>
|
|
|
|
|
</Grid>
|
2024-04-24 21:44:05 +02:00
|
|
|
<Grid item xs="auto">
|
|
|
|
|
{buttons}
|
|
|
|
|
</Grid>
|
2024-03-17 12:58:25 +01:00
|
|
|
</Grid>
|
2024-09-09 10:19:36 +02:00
|
|
|
<Grid item sx={{flexGrow: 1}}>
|
2024-03-17 12:58:25 +01:00
|
|
|
<Box
|
|
|
|
|
sx={{
|
2024-04-23 13:36:51 +02:00
|
|
|
mt: 2,
|
2024-04-24 21:44:05 +02:00
|
|
|
backgroundColor: "transparent",
|
2024-03-17 12:58:25 +01:00
|
|
|
border: 0,
|
|
|
|
|
width: "100%",
|
|
|
|
|
".MuiDataGrid-row": {
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
"&:hover": {
|
2024-04-24 21:44:05 +02:00
|
|
|
backgroundColor: `${mediumBlue}22 !important`,
|
2024-03-17 12:58:25 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
".MuiDataGrid-row:nth-of-type(1n)": {
|
2024-04-24 21:44:05 +02:00
|
|
|
backgroundColor: white,
|
2024-03-17 12:58:25 +01:00
|
|
|
},
|
|
|
|
|
".MuiDataGrid-row:nth-of-type(2n)": {
|
2024-04-24 21:44:05 +02:00
|
|
|
backgroundColor: veryLightGray,
|
2024-03-17 12:58:25 +01:00
|
|
|
},
|
|
|
|
|
".MuiDataGrid-columnHeaderTitle": {
|
2024-04-24 21:44:05 +02:00
|
|
|
color: darkGray,
|
2024-03-17 12:58:25 +01:00
|
|
|
fontWeight: "bold",
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
margin: "0 auto",
|
|
|
|
|
},
|
|
|
|
|
".MuiDataGrid-columnHeader": {
|
2024-04-24 21:44:05 +02:00
|
|
|
backgroundColor: mediumGray,
|
2024-03-17 12:58:25 +01:00
|
|
|
border: 0,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DataGridPro
|
|
|
|
|
rows={rows}
|
|
|
|
|
columns={columns}
|
|
|
|
|
density="compact"
|
2024-04-24 21:44:05 +02:00
|
|
|
pagination={paginate}
|
|
|
|
|
hideFooterRowCount={!paginate}
|
|
|
|
|
hideFooter={!paginate}
|
2024-03-17 12:58:25 +01:00
|
|
|
initialState={{
|
|
|
|
|
pagination: { paginationModel: { pageSize: 25 } },
|
|
|
|
|
}}
|
|
|
|
|
pageSizeOptions={[5, 10, 25]}
|
|
|
|
|
paginationMode="client"
|
2024-04-23 13:36:51 +02:00
|
|
|
sx={{ height: "100%" }}
|
2024-03-17 12:58:25 +01:00
|
|
|
rowHeight={46}
|
|
|
|
|
scrollbarSize={0}
|
|
|
|
|
disableVirtualization
|
|
|
|
|
disableColumnMenu
|
2024-05-09 07:42:44 +02:00
|
|
|
onRowClick={({ row }: any) => onRowClick?.(getRowIDInternal(row))}
|
2024-03-17 12:58:25 +01:00
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|