feat: paginated and responsive TLD tables

This commit is contained in:
vinceh121 2024-07-30 23:32:22 +02:00
parent 712293ee2b
commit 34b4838a72
No known key found for this signature in database
GPG Key ID: 780725DCACF96F16
3 changed files with 41 additions and 25 deletions

View File

@ -3,49 +3,65 @@ import {Collapse, Divider, Table, Typography} from "antd";
import {getTldList, Tld} from "../../utils/api"; import {getTldList, Tld} from "../../utils/api";
import {t} from 'ttag' import {t} from 'ttag'
import {regionNames} from "../../i18n"; import {regionNames} from "../../i18n";
import useBreakpoint from "../../hooks/useBreakpoint";
import { ColumnType } from "antd/es/table";
const {Text, Paragraph} = Typography const {Text, Paragraph} = Typography
type TldType = 'iTLD' | 'sTLD' | 'gTLD' | 'ccTLD' type TldType = 'iTLD' | 'sTLD' | 'gTLD' | 'ccTLD'
type FiltersType = { type: TldType, contractTerminated?: boolean, specification13?: boolean } type FiltersType = { type: TldType, contractTerminated?: boolean, specification13?: boolean }
const toEmoji = (tld: string) => {
if (tld.startsWith('xn--')) return '-'
const toEmoji = (tld: string) => String.fromCodePoint( return String.fromCodePoint(
...getCountryCode(tld) ...getCountryCode(tld)
.toUpperCase() .toUpperCase()
.split('') .split('')
.map((char) => 127397 + char.charCodeAt(0) .map((char) => 127397 + char.charCodeAt(0))
) )
) }
const getCountryCode = (tld: string): string => { const getCountryCode = (tld: string): string => {
const exceptions = {uk: 'gb', su: 'ru', tp: 'tl'} const exceptions = {uk: 'gb', su: 'ru', tp: 'tl'}
if (tld in exceptions) return exceptions[tld as keyof typeof exceptions] if (tld in exceptions) return exceptions[tld as keyof typeof exceptions]
return tld return tld.toUpperCase()
} }
function TldTable(filters: FiltersType) { function TldTable(filters: FiltersType) {
const sm = useBreakpoint('sm')
const [dataTable, setDataTable] = useState<Tld[]>([]) const [dataTable, setDataTable] = useState<Tld[]>([])
const [total, setTotal] = useState(0) const [total, setTotal] = useState(0)
const fetchData = (params: FiltersType & { page: number }) => { const fetchData = (params: FiltersType & { page: number, itemsPerPage: number }) => {
getTldList(params).then((data) => { getTldList(params).then((data) => {
setTotal(data['hydra:totalItems']) setTotal(data['hydra:totalItems'])
setDataTable(data['hydra:member'].map((tld: Tld) => { setDataTable(data['hydra:member'].map((tld: Tld) => {
switch (filters.type) { switch (filters.type) {
case 'ccTLD': case 'ccTLD':
let countryName
try {
countryName = regionNames.of(getCountryCode(tld.tld))
} catch(e) {
countryName = '-'
}
return { return {
key: tld.tld,
TLD: tld.tld, TLD: tld.tld,
Flag: toEmoji(tld.tld), Flag: toEmoji(tld.tld),
Country: regionNames.of(getCountryCode(tld.tld)) ?? '-' Country: countryName
} }
case 'gTLD': case 'gTLD':
return { return {
key: tld.tld,
TLD: tld.tld, TLD: tld.tld,
Operator: tld.registryOperator Operator: tld.registryOperator
} }
default: default:
return { return {
key: tld.tld,
TLD: tld.tld TLD: tld.tld
} }
} }
@ -54,31 +70,27 @@ function TldTable(filters: FiltersType) {
} }
useEffect(() => { useEffect(() => {
fetchData({...filters, page: 1}) fetchData({...filters, page: 1, itemsPerPage: 30})
}, []) }, [])
let columns = [ let columns: ColumnType<any>[] = [
{ {
title: t`TLD`, title: t`TLD`,
dataIndex: "TLD", dataIndex: "TLD"
width: 20
} }
] ]
if (filters.type === 'ccTLD') columns = [...columns, { if (filters.type === 'ccTLD') columns = [...columns, {
title: t`Flag`, title: t`Flag`,
dataIndex: "Flag", dataIndex: "Flag",
width: 20
}, { }, {
title: t`Country`, title: t`Country`,
dataIndex: "Country", dataIndex: "Country"
width: 200
}] }]
if (filters.type === 'gTLD') columns = [...columns, { if (filters.type === 'gTLD') columns = [...columns, {
title: t`Registry Operator`, title: t`Registry Operator`,
dataIndex: "Operator", dataIndex: "Operator"
width: 50
}] }]
@ -87,18 +99,21 @@ function TldTable(filters: FiltersType) {
dataSource={dataTable} dataSource={dataTable}
pagination={{ pagination={{
total, total,
pageSize: 30,
hideOnSinglePage: true, hideOnSinglePage: true,
onChange: (page, pageSize) => { defaultPageSize: 30,
fetchData({...filters, page}) onChange: (page, itemsPerPage) => {
fetchData({...filters, page, itemsPerPage})
} }
}} }}
scroll={{y: 240}}
{...(sm ? {scroll: {y: 'mex-content'}} : {scroll: {y: 240}})}
/> />
} }
export default function TldPage() { export default function TldPage() {
const sm = useBreakpoint('sm')
return <> return <>
<Paragraph> <Paragraph>
{t`This page presents all active TLDs in the root zone database.`} {t`This page presents all active TLDs in the root zone database.`}
@ -111,7 +126,7 @@ export default function TldPage() {
</Paragraph> </Paragraph>
<Divider/> <Divider/>
<Collapse <Collapse
size="large" size={sm ? 'small' : 'large'}
items={[ items={[
{ {
key: 'sTLD', key: 'sTLD',

View File

@ -1,6 +1,7 @@
api_platform: api_platform:
title: Domain Watchdog API title: Domain Watchdog API
version: 1.0.0 version: 1.0.0
formats: formats:
jsonld: [ 'application/ld+json' ] jsonld: [ 'application/ld+json' ]
xml: [ 'application/xml' ] xml: [ 'application/xml' ]
@ -13,6 +14,7 @@ api_platform:
stateless: true stateless: true
cache_headers: cache_headers:
vary: [ 'Content-Type', 'Authorization', 'Origin' ] vary: [ 'Content-Type', 'Authorization', 'Origin' ]
pagination_client_items_per_page: true
extra_properties: extra_properties:
standard_put: true standard_put: true
rfc_7807_compliant_errors: true rfc_7807_compliant_errors: true

View File

@ -2,7 +2,6 @@
"name": "Domain Watchdog", "name": "Domain Watchdog",
"short_name": "Domain Watch", "short_name": "Domain Watch",
"start_url": ".", "start_url": ".",
"orientation": "landscape",
"display": "standalone", "display": "standalone",
"background_color": "#fff", "background_color": "#fff",
"description": "A standalone app that collects open access information about domain names, helping users track the history and changes associated with domain names. " "description": "A standalone app that collects open access information about domain names, helping users track the history and changes associated with domain names. "