95 lines
3.9 KiB
TypeScript
Raw Normal View History

2024-08-15 22:58:15 +02:00
import {Card, Divider, Space, Table, Tag, Typography} from "antd";
import {t} from "ttag";
2024-08-15 22:58:15 +02:00
import {CalendarFilled, DisconnectOutlined, LinkOutlined} from "@ant-design/icons";
import React from "react";
2024-08-02 17:23:27 +02:00
import useBreakpoint from "../../hooks/useBreakpoint";
import {actionToColor, domainEvent} from "../search/EventTimeline";
2024-08-02 17:23:27 +02:00
import {Watchlist} from "../../pages/tracking/WatchlistPage";
2024-08-03 19:16:58 +02:00
import punycode from "punycode/punycode";
2024-08-15 03:04:31 +02:00
import {Connector} from "../../utils/api/connectors";
2024-08-15 22:58:15 +02:00
import {UpdateWatchlistButton} from "./UpdateWatchlistButton";
import {DeleteWatchlistButton} from "./DeleteWatchlistButton";
import {ViewDiagramWatchlistButton} from "./ViewDiagramWatchlistButton";
2024-07-31 02:55:20 +02:00
2024-08-15 03:04:31 +02:00
export function WatchlistsList({watchlists, onDelete, onUpdateWatchlist, connectors}: {
watchlists: Watchlist[],
onDelete: () => void,
2024-08-15 04:06:35 +02:00
onUpdateWatchlist: (values: { domains: string[], emailTriggers: string[], token: string }) => Promise<void>,
2024-08-15 03:04:31 +02:00
connectors: (Connector & { id: string })[]
}) {
2024-08-02 17:23:27 +02:00
const sm = useBreakpoint('sm')
const domainEventTranslated = domainEvent()
2024-08-15 22:58:15 +02:00
2024-08-02 17:23:27 +02:00
const columns = [
{
title: t`Domain names`,
dataIndex: 'domains'
},
{
title: t`Tracked events`,
dataIndex: 'events'
}
]
2024-07-31 02:55:20 +02:00
2024-08-15 03:04:31 +02:00
return <>
{watchlists.map(watchlist =>
<>
2024-08-02 17:23:27 +02:00
<Card
2024-08-08 14:00:21 +02:00
hoverable
title={<>
{
watchlist.connector ?
<Tag icon={<LinkOutlined/>} color="lime-inverse" title={watchlist.connector.id}/> :
<Tag icon={<DisconnectOutlined/>} color="default"
title={t`This Watchlist is not linked to a Connector.`}/>
}
<Typography.Text title={new Date(watchlist.createdAt).toLocaleString()}>
{t`Watchlist` + (watchlist.name ? ` (${watchlist.name})` : '')}
</Typography.Text>
</>
}
2024-08-02 17:23:27 +02:00
size='small'
style={{width: '100%'}}
2024-08-07 15:31:29 +02:00
extra={<Space size='middle'>
2024-08-15 22:58:15 +02:00
2024-08-16 03:54:48 +02:00
<ViewDiagramWatchlistButton token={watchlist.token}/>
2024-08-15 22:58:15 +02:00
<Typography.Link href={`/api/watchlists/${watchlist.token}/calendar`}>
<CalendarFilled title={t`Export events to iCalendar format`}
style={{color: 'limegreen'}}/>
2024-08-15 03:04:31 +02:00
</Typography.Link>
2024-08-15 22:58:15 +02:00
<UpdateWatchlistButton
watchlist={watchlist}
onUpdateWatchlist={onUpdateWatchlist}
connectors={connectors}
/>
<DeleteWatchlistButton watchlist={watchlist} onDelete={onDelete}/>
2024-08-15 03:04:31 +02:00
2024-08-07 15:31:29 +02:00
</Space>}
2024-08-02 21:32:24 +02:00
>
2024-07-31 12:37:43 +02:00
<Card.Meta description={watchlist.token} style={{marginBottom: '1em'}}/>
2024-08-02 17:23:27 +02:00
<Table
2024-08-03 02:08:30 +02:00
size='small'
2024-08-02 17:23:27 +02:00
columns={columns}
pagination={false}
style={{width: '100%'}}
2024-08-02 17:23:27 +02:00
dataSource={[{
2024-08-03 19:16:58 +02:00
domains: watchlist.domains.map(d => <Tag>{punycode.toUnicode(d.ldhName)}</Tag>),
2024-08-02 17:23:27 +02:00
events: watchlist.triggers?.filter(t => t.action === 'email')
.map(t => <Tag color={actionToColor(t.event)}>
{domainEventTranslated[t.event as keyof typeof domainEventTranslated]}
</Tag>
)
2024-08-02 17:23:27 +02:00
}]}
{...(sm ? {scroll: {y: 'max-content'}} : {scroll: {y: 240}})}
/>
</Card>
<Divider/>
</>
)}
</>
}