mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
fix: identify tld type
This commit is contained in:
83
assets/components/StickyHeadTable.tsx
Normal file
83
assets/components/StickyHeadTable.tsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import React from "react";
|
||||||
|
import {Paper, Table, TableBody, TableCell, TableContainer, TableHead, TablePagination, TableRow} from "@mui/material";
|
||||||
|
|
||||||
|
interface Column {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
minWidth?: number;
|
||||||
|
align?: 'right';
|
||||||
|
format?: (value: number) => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Data {
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
population: number;
|
||||||
|
size: number;
|
||||||
|
density: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function StickyHeadTable({columns, rows}: { rows: Data[], columns: Column[] }) {
|
||||||
|
const [page, setPage] = React.useState(0);
|
||||||
|
const [rowsPerPage, setRowsPerPage] = React.useState(10);
|
||||||
|
|
||||||
|
const handleChangePage = (event: unknown, newPage: number) => {
|
||||||
|
setPage(newPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setRowsPerPage(+event.target.value);
|
||||||
|
setPage(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Paper sx={{width: '100%', overflow: 'hidden'}}>
|
||||||
|
<TableContainer sx={{maxHeight: 440}}>
|
||||||
|
<Table stickyHeader aria-label="sticky table">
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
{columns.map((column) => (
|
||||||
|
<TableCell
|
||||||
|
key={column.id}
|
||||||
|
align={column.align}
|
||||||
|
style={{minWidth: column.minWidth}}
|
||||||
|
>
|
||||||
|
{column.label}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
{rows
|
||||||
|
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
||||||
|
.map((row: Data) => {
|
||||||
|
return (
|
||||||
|
<TableRow hover role="checkbox" tabIndex={-1} key={row.code}>
|
||||||
|
{columns.map((column) => {
|
||||||
|
const value = row[column.id as keyof typeof row]
|
||||||
|
return (
|
||||||
|
<TableCell key={column.id} align={column.align}>
|
||||||
|
{column.format && typeof value === 'number'
|
||||||
|
? column.format(value)
|
||||||
|
: value}
|
||||||
|
</TableCell>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableContainer>
|
||||||
|
<TablePagination
|
||||||
|
rowsPerPageOptions={[10, 25, 100]}
|
||||||
|
component="div"
|
||||||
|
count={rows.length}
|
||||||
|
rowsPerPage={rowsPerPage}
|
||||||
|
page={page}
|
||||||
|
onPageChange={handleChangePage}
|
||||||
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
||||||
|
/>
|
||||||
|
</Paper>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -67,7 +67,7 @@ security:
|
|||||||
# Easy way to control access for large sections of your site
|
# Easy way to control access for large sections of your site
|
||||||
# Note: Only the *first* access control that matches will be used
|
# Note: Only the *first* access control that matches will be used
|
||||||
access_control:
|
access_control:
|
||||||
- { path: ^/api/$, roles: PUBLIC_ACCESS }
|
- { path: ^/api$, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/api/docs, roles: PUBLIC_ACCESS }
|
- { path: ^/api/docs, roles: PUBLIC_ACCESS }
|
||||||
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
|
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ controllers:
|
|||||||
|
|
||||||
api_login:
|
api_login:
|
||||||
path: /api/login
|
path: /api/login
|
||||||
# methods: [ 'POST' ]
|
methods: [ 'POST' ]
|
||||||
|
|
||||||
oauth_connect_check:
|
oauth_connect_check:
|
||||||
path: /login/oauth/check
|
path: /login/oauth/check
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
operations: [
|
operations: [
|
||||||
new GetCollection(
|
new GetCollection(
|
||||||
uriTemplate: '/tld',
|
uriTemplate: '/tld',
|
||||||
|
paginationItemsPerPage: 200,
|
||||||
normalizationContext: ['groups' => ['tld:list']]
|
normalizationContext: ['groups' => ['tld:list']]
|
||||||
),
|
),
|
||||||
new Get(
|
new Get(
|
||||||
@@ -56,7 +57,7 @@ class Tld
|
|||||||
private ?DateTimeImmutable $delegationDate = null;
|
private ?DateTimeImmutable $delegationDate = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
#[Groups(["tld:item"])]
|
#[Groups(["tld:list", "tld:item"])]
|
||||||
private ?string $registryOperator = null;
|
private ?string $registryOperator = null;
|
||||||
|
|
||||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||||
@@ -64,7 +65,7 @@ class Tld
|
|||||||
private ?DateTimeImmutable $removalDate = null;
|
private ?DateTimeImmutable $removalDate = null;
|
||||||
|
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
#[Groups(["tld:item"])]
|
#[Groups(["tld:list", "tld:item"])]
|
||||||
private ?bool $specification13 = null;
|
private ?bool $specification13 = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 10, nullable: true, enumType: TldType::class)]
|
#[ORM\Column(length: 10, nullable: true, enumType: TldType::class)]
|
||||||
@@ -195,10 +196,8 @@ class Tld
|
|||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setType(TldType $type): static
|
public function setType(?TldType $type): void
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ use DateTimeImmutable;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Exception\ORMException;
|
use Doctrine\ORM\Exception\ORMException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Symfony\Component\Intl\Countries;
|
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
@@ -340,8 +339,16 @@ readonly class RDAPService
|
|||||||
$tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]);
|
$tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]);
|
||||||
if ($tldEntity === null) $tldEntity = new Tld();
|
if ($tldEntity === null) $tldEntity = new Tld();
|
||||||
|
|
||||||
$tldEntity->setTld($tld)->setType($this->getTldType($tld));
|
if ($tldEntity->getType() === null) {
|
||||||
if ($tldEntity->getRegistryOperator() === NULL) $tldEntity->setType(TldType::ccTLD);
|
$type = $this->getTldType($tld);
|
||||||
|
if ($type !== null) {
|
||||||
|
$tldEntity->setType($type);
|
||||||
|
} elseif ($tldEntity->isContractTerminated() === null) {
|
||||||
|
$tldEntity->setType(TldType::ccTLD);
|
||||||
|
} else {
|
||||||
|
$tldEntity->setType(TldType::gTLD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->em->persist($tldEntity);
|
$this->em->persist($tldEntity);
|
||||||
}
|
}
|
||||||
@@ -351,12 +358,12 @@ readonly class RDAPService
|
|||||||
private function getTldType(string $tld): ?TldType
|
private function getTldType(string $tld): ?TldType
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Countries::exists(strtoupper($tld)) || in_array($tld, self::ISO_TLD_EXCEPTION)) return TldType::ccTLD;
|
if (in_array($tld, self::ISO_TLD_EXCEPTION)) return TldType::ccTLD;
|
||||||
if (in_array(strtolower($tld), self::INFRA_TLD)) return TldType::iTLD;
|
if (in_array(strtolower($tld), self::INFRA_TLD)) return TldType::iTLD;
|
||||||
if (in_array(strtolower($tld), self::SPONSORED_TLD)) return TldType::sTLD;
|
if (in_array(strtolower($tld), self::SPONSORED_TLD)) return TldType::sTLD;
|
||||||
if (in_array(strtolower($tld), self::TEST_TLD)) return TldType::tTLD;
|
if (in_array(strtolower($tld), self::TEST_TLD)) return TldType::tTLD;
|
||||||
|
|
||||||
return TldType::gTLD;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,7 +386,8 @@ readonly class RDAPService
|
|||||||
/** @var Tld $gtTldEntity */
|
/** @var Tld $gtTldEntity */
|
||||||
$gtTldEntity = $this->em->getReference(Tld::class, $gTld['gTLD']);
|
$gtTldEntity = $this->em->getReference(Tld::class, $gTld['gTLD']);
|
||||||
|
|
||||||
$gtTldEntity->setContractTerminated($gTld['contractTerminated'])
|
$gtTldEntity
|
||||||
|
->setContractTerminated($gTld['contractTerminated'])
|
||||||
->setRegistryOperator($gTld['registryOperator'])
|
->setRegistryOperator($gTld['registryOperator'])
|
||||||
->setSpecification13($gTld['specification13']);
|
->setSpecification13($gTld['specification13']);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user