import React from 'react'; import { Link } from '@tanstack/react-router'; import { useServerDetail } from '@/components/admin/servers/useServerDetail'; import type { AdminServer } from '@/api/admin/servers/queries'; import TitledGreyBox from '@/components/elements/TitledGreyBox'; import Code from '@/components/elements/Code'; import CopyOnClick from '@/components/elements/CopyOnClick'; import { relationshipAttributes, relationshipData } from '@/api/relationships'; type ServerAttributes = AdminServer['attributes']; type AllocationAttributes = { id: number; ip: string; port: number; alias?: string | null; }; type NamedRef = { id: number; name: string }; type UserRef = { id: number; username: string; email: string; first_name?: string; last_name?: string }; type NodeRef = { id: number; name: string; fqdn: string; relationships?: { location?: { attributes: LocationRef | null } | undefined }; }; type LocationRef = { id: number; short: string; long?: string | null }; const Row = ({ label, children }: { label: string; children: React.ReactNode }) => (
{unlimited} : {`${value}${unit}`};
const getDefaultAllocation = (
relationships: ServerAttributes['relationships'],
allocationId: number
): AllocationAttributes | undefined =>
relationshipData(relationships?.allocations)
.map((allocation) => allocation.attributes)
.find((allocation) => allocation.id === allocationId);
const getOwnerDisplayName = (user: UserRef | undefined): string =>
user ? [user.first_name, user.last_name].filter(Boolean).join(' ') : '';
const hasConnectionAlias = (allocation: AllocationAttributes | undefined): allocation is AllocationAttributes =>
!!allocation?.alias && allocation.alias !== allocation.ip;
function ExternalIdentifierValue({ externalId }: { externalId: string | null | undefined }) {
if (!externalId) {
return Not Set;
}
return {externalId};
}
function EggValue({ egg }: { egg: NamedRef | undefined }) {
if (!egg) {
return Unknown;
}
return (
{egg.name}
);
}
function CpuPinningValue({ threads }: { threads: string | null | undefined }) {
if (!threads) {
return Not Set;
}
return {threads};
}
function SwapValue({ swap }: { swap: number }) {
if (swap === 0) {
return Not Set;
}
if (swap === -1) {
return Unlimited;
}
return {`${swap}MiB`};
}
function DefaultConnectionValue({ allocation }: { allocation: AllocationAttributes | undefined }) {
if (!allocation) {
return Unknown;
}
return {`${allocation.ip}:${allocation.port}`};
}
function ConnectionAliasValue({ allocation }: { allocation: AllocationAttributes | undefined }) {
if (!hasConnectionAlias(allocation)) {
return No Alias Assigned;
}
return {`${allocation.alias}:${allocation.port}`};
}
function InformationCard({
attributes,
allocation,
egg,
}: {
attributes: ServerAttributes;
allocation: AllocationAttributes | undefined;
egg: NamedRef | undefined;
}) {
return (
{attributes.id}
{attributes.uuid}
{attributes.limits.io}
This server is currently suspended.
} {attributes.container.installed === 0 && (This server is currently installing.
)} {attributes.status === 'install_failed' && (This server failed to install.
)}{user.email}
> ); } function NodeValue({ node }: { node: NodeRef | undefined }) { if (!node) { return Unknown; } return ( <> {node.name}{node.fqdn}
> ); } function LocationValue({ location }: { location: LocationRef | undefined }) { if (!location) { return Unknown; } return ( <> {location.short} {location.long &&{location.long}
} > ); } function AssignmentCard({ user, node, location, ownerName, }: { user: UserRef | undefined; node: NodeRef | undefined; location: LocationRef | undefined; ownerName: string; }) { return (