Merge pull request #1838 from bluewave-labs/feat/status-table-onclick
feat: status table onclick
This commit is contained in:
2 files changed
+31
-3
No files matched your search
@@ -15,6 +15,8 @@ import { useTheme } from "@emotion/react";
|
|||||||
* @typedef {Object} Header
|
* @typedef {Object} Header
|
||||||
* @property {number|string} id - The unique identifier for the header.
|
* @property {number|string} id - The unique identifier for the header.
|
||||||
* @property {React.ReactNode} content - The content to display in the header cell.
|
* @property {React.ReactNode} content - The content to display in the header cell.
|
||||||
|
* @property {Function} onClick - A function to be called when this cell is clicked, receiving the event and row data as an argument.
|
||||||
|
* @property {Object} getCellSx - Function that takes a row and returns a style object for the table cell.
|
||||||
* @property {Function} render - A function to render the cell content for a given row.
|
* @property {Function} render - A function to render the cell content for a given row.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -107,6 +109,8 @@ const DataTable = ({
|
|||||||
<TableCell
|
<TableCell
|
||||||
align={index === 0 ? "left" : "center"}
|
align={index === 0 ? "left" : "center"}
|
||||||
key={header.id}
|
key={header.id}
|
||||||
|
onClick={header.onClick ? (e) => header.onClick(e, row) : null}
|
||||||
|
sx={header.getCellSx ? header.getCellSx(row) : {}}
|
||||||
>
|
>
|
||||||
{header.render(row)}
|
{header.render(row)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|||||||
@@ -17,16 +17,40 @@ const StatusPagesTable = ({ data }) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "url",
|
id: "url",
|
||||||
content: "URL",
|
content: "Public URL",
|
||||||
|
onClick: (e, row) => {
|
||||||
|
if (row.isPublished) {
|
||||||
|
e.stopPropagation();
|
||||||
|
const url =
|
||||||
|
row.type === "distributed"
|
||||||
|
? `/status/distributed/public/${row.url}`
|
||||||
|
: `/status/uptime/public/${row.url}`;
|
||||||
|
navigate(url);
|
||||||
|
}
|
||||||
|
},
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
|
const content = row.isPublished ? `/${row.url}` : "Unpublished";
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
|
justifyContent="center"
|
||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
|
paddingLeft={theme.spacing(2)}
|
||||||
|
paddingRight={theme.spacing(2)}
|
||||||
|
borderRadius={theme.spacing(4)}
|
||||||
|
sx={{
|
||||||
|
...(row.isPublished && {
|
||||||
|
":hover": {
|
||||||
|
backgroundColor: `${theme.palette.primary.light}`,
|
||||||
|
cursor: "pointer",
|
||||||
|
borderRadius: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Typography>{`/${row.url}`}</Typography>
|
<Typography>{content}</Typography>
|
||||||
<ArrowOutwardIcon />
|
{row.isPublished && <ArrowOutwardIcon />}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user