import React, {ReactElement, useEffect, useState} from 'react' import {Domain, getTrackedDomainList} from '../../../utils/api' import {Button, Empty, Result, Skeleton, Table, Tag, Tooltip} from 'antd' import {t} from 'ttag' import {ColumnType} from 'antd/es/table' import {rdapStatusCodeDetailTranslation} from '../../../utils/functions/rdapTranslation' import {eppStatusCodeToColor} from '../../../utils/functions/eppStatusCodeToColor' import {Link} from 'react-router-dom' import {ExceptionOutlined, MonitorOutlined} from '@ant-design/icons' import {DomainToTag} from '../DomainToTag' export function TrackedDomainTable() { const REDEMPTION_NOTICE = ( redemption period ) const PENDING_DELETE_NOTICE = ( pending delete ) interface TableRow { key: string ldhName: ReactElement expirationDate: string status: ReactElement[] updatedAt: string domain: Domain } const [dataTable, setDataTable] = useState([]) const [total, setTotal] = useState() const [specialNotice, setSpecialNotice] = useState([]) const rdapStatusCodeDetailTranslated = rdapStatusCodeDetailTranslation() const fetchData = (params: { page: number, itemsPerPage: number }) => { getTrackedDomainList(params).then(data => { setTotal(data['hydra:totalItems']) const notices: ReactElement[] = [] setDataTable(data['hydra:member'].map((d: Domain) => { const expirationDate = d.events.find(e => e.action === 'expiration' && !e.deleted)?.date if (d.status.includes('redemption period')) { if (!notices.includes(REDEMPTION_NOTICE)) notices.push(REDEMPTION_NOTICE) } else if (d.status.includes('pending delete')) { if (!notices.includes(PENDING_DELETE_NOTICE)) notices.push(PENDING_DELETE_NOTICE) } return { key: d.ldhName, ldhName: , expirationDate: expirationDate ? new Date(expirationDate).toLocaleString() : '-', status: d.status.map(s => {s} ), updatedAt: new Date(d.updatedAt).toLocaleString(), domain: d } })) setSpecialNotice(notices) }) } useEffect(() => { fetchData({page: 1, itemsPerPage: 30}) }, []) interface RecordType { domain: Domain } const columns: Array> = [ { title: t`Domain`, dataIndex: 'ldhName' }, { title: t`Expiration date`, dataIndex: 'expirationDate', sorter: (a: RecordType, b: RecordType) => { const expirationDate1 = a.domain.events.find(e => e.action === 'expiration' && !e.deleted)?.date const expirationDate2 = b.domain.events.find(e => e.action === 'expiration' && !e.deleted)?.date if (expirationDate1 === undefined || expirationDate2 === undefined) return 0 return new Date(expirationDate1).getTime() - new Date(expirationDate2).getTime() } }, { title: t`Updated at`, dataIndex: 'updatedAt', sorter: (a: RecordType, b: RecordType) => new Date(a.domain.updatedAt).getTime() - new Date(b.domain.updatedAt).getTime() }, { title: t`Status`, dataIndex: 'status', showSorterTooltip: {target: 'full-header'}, filters: [...new Set(dataTable.map((d: RecordType) => d.domain.status).flat())].map(s => ({ text: {s} , value: s })), onFilter: (value, record: RecordType) => record.domain.status.includes(value as string) } ] return ( <> { total === 0 ? : 0 ? { icon: , status: 'warning', title: t`At least one domain name you are tracking requires special attention`, extra: specialNotice } : { icon: , status: 'info', title: t`The domain names below are subject to special monitoring` })} /> { fetchData({page, itemsPerPage}) } }} scroll={{y: '50vh'}} /> } ) }