67 lines
2.6 KiB
TypeScript
Raw Normal View History

import {Card, Divider, Popconfirm, Table, Tag, theme} from "antd";
import {t} from "ttag";
2024-08-02 17:23:27 +02:00
import {deleteWatchlist} from "../../utils/api";
import {DeleteFilled} 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-07-31 12:37:43 +02:00
const {useToken} = theme;
2024-07-31 02:55:20 +02:00
export function WatchlistsList({watchlists, onDelete}: { watchlists: Watchlist[], onDelete: () => void }) {
2024-07-31 12:37:43 +02:00
const {token} = useToken()
2024-08-02 17:23:27 +02:00
const sm = useBreakpoint('sm')
const domainEventTranslated = domainEvent()
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
return <>
{watchlists.map(watchlist =>
<>
2024-08-02 17:23:27 +02:00
<Card
2024-08-03 19:16:58 +02:00
title={t`Watchlist` + (watchlist.name ? ` (${watchlist.name})` : '')}
2024-08-02 17:23:27 +02:00
size='small'
extra={<Popconfirm
title={t`Delete the Watchlist`}
description={t`Are you sure to delete this Watchlist?`}
onConfirm={() => deleteWatchlist(watchlist.token).then(onDelete)}
okText={t`Yes`}
cancelText={t`No`}
2024-08-02 21:32:24 +02:00
okButtonProps={{danger: true}}>
<DeleteFilled style={{color: token.colorError}}/>
</Popconfirm>}
>
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}
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/>
</>
)}
</>
}