umami/components/pages/settings/websites/WebsitesTable.js

82 lines
2.2 KiB
JavaScript
Raw Normal View History

import Link from 'next/link';
import {
Table,
TableHeader,
TableBody,
TableRow,
TableCell,
TableColumn,
Button,
2023-01-31 06:44:07 +01:00
Text,
Icon,
Icons,
2023-01-25 16:42:46 +01:00
Flexbox,
} from 'react-basics';
2023-03-22 22:05:55 +01:00
import useMessages from 'hooks/useMessages';
import useConfig from 'hooks/useConfig';
2023-01-21 02:12:53 +01:00
export default function WebsitesTable({ data = [] }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, labels } = useMessages();
const { openExternal } = useConfig();
2023-01-25 16:42:46 +01:00
const columns = [
2023-01-31 06:44:07 +01:00
{ name: 'name', label: formatMessage(labels.name), style: { flex: 2 } },
{ name: 'domain', label: formatMessage(labels.domain) },
2023-01-25 16:42:46 +01:00
{ name: 'action', label: ' ' },
];
return (
2023-01-25 16:42:46 +01:00
<Table columns={columns} rows={data}>
<TableHeader>
{(column, index) => {
return (
<TableColumn key={index} style={{ ...column.style }}>
{column.label}
</TableColumn>
);
}}
</TableHeader>
<TableBody>
{(row, keys, rowIndex) => {
const { id } = row;
row.action = (
2023-01-25 16:42:46 +01:00
<Flexbox flex={1} justifyContent="end" gap={10}>
2023-01-10 08:59:26 +01:00
<Link href={`/settings/websites/${id}`}>
<Button>
<Icon>
<Icons.Edit />
</Icon>
<Text>{formatMessage(labels.edit)}</Text>
</Button>
</Link>
<Link href={`/websites/${id}`} target={openExternal ? '_blank' : null}>
<Button>
<Icon>
<Icons.External />
</Icon>
<Text>{formatMessage(labels.view)}</Text>
</Button>
</Link>
2023-01-25 16:42:46 +01:00
</Flexbox>
);
return (
<TableRow key={rowIndex} data={row} keys={keys}>
{(data, key, colIndex) => {
return (
2023-01-25 16:42:46 +01:00
<TableCell key={colIndex} style={{ ...columns[colIndex]?.style }}>
<Flexbox flex={1} alignItems="center">
{data[key]}
</Flexbox>
</TableCell>
);
}}
</TableRow>
);
}}
</TableBody>
</Table>
);
}