Files

181 lines
7.9 KiB
TypeScript
Raw Permalink Normal View History

2026-10-08 16:53:20 -04:00
import type { ReactNode } from 'react';
import { bytesRatioToString, mbToBytes } from '@/lib/formatters';
2026-10-05 18:10:18 -04:00
import { useNavigate } from '@tanstack/react-router';
import { deleteAdminNodeInput, type NodeUtilization } from '@/api/admin/nodes/queries';
import { useAdminVersion } from '@/api/admin/version/queries';
import { useAdminNodeSystemInformation, useAdminNodeUtilization, useDeleteAdminNode } from '@/api/admin/nodes/queries';
import { useNodeDetail } from '@/components/admin/nodes/useNodeDetail';
import TitledGreyBox from '@/components/elements/TitledGreyBox';
import Code from '@/components/elements/Code';
2026-10-12 09:04:03 -04:00
import ProgressBar from '@/components/elements/ProgressBar';
import type { UiTone } from '@/themes/skins';
2026-10-05 18:10:18 -04:00
import Spinner from '@/components/elements/Spinner';
import Button from '@/components/elements/Button';
import { Dialog } from '@/components/elements/dialog';
2026-10-12 09:04:03 -04:00
const usageTone = (metric: NodeUtilization['memory'] | undefined): UiTone => {
2026-10-08 16:53:20 -04:00
if (!metric) {
2026-10-12 09:04:03 -04:00
return 'neutral';
2026-10-08 16:53:20 -04:00
}
if (metric.css === 'red') {
2026-10-12 09:04:03 -04:00
return 'danger';
2026-10-08 16:53:20 -04:00
}
if (metric.css === 'yellow') {
2026-10-12 09:04:03 -04:00
return 'warning';
2026-10-08 16:53:20 -04:00
}
2026-10-12 09:04:03 -04:00
return 'success';
2026-10-08 16:53:20 -04:00
};
type SystemInformation = NonNullable<ReturnType<typeof useAdminNodeSystemInformation>['data']>;
interface SystemInformationValueProps {
info: SystemInformation | undefined;
error: unknown;
children: (info: SystemInformation) => ReactNode;
}
const SystemInformationValue = ({ info, error, children }: SystemInformationValueProps) => {
if (error) {
return <span className='text-destructive'>Unavailable</span>;
}
if (!info) {
return <Spinner size='small' />;
}
return children(info);
};
const megabytes = (formatted: string): number => Number(formatted.replaceAll(',', ''));
2026-10-05 18:10:18 -04:00
const UsageBox = ({ title, metric }: { title: string; metric: NodeUtilization['memory'] | undefined }) => {
const percent = metric ? Math.min(metric.percent, 100) : 0;
return (
<TitledGreyBox title={title}>
2026-10-09 13:23:04 +01:00
<p className='text-sm text-foreground'>
{metric ? (
bytesRatioToString(mbToBytes(megabytes(metric.value)), mbToBytes(megabytes(metric.max)))
) : (
<Spinner size='small' />
)}
</p>
2026-10-12 09:04:03 -04:00
<ProgressBar value={percent} tone={usageTone(metric)} label={`${title} usage`} className='mt-2' />
2026-10-05 18:10:18 -04:00
</TitledGreyBox>
);
};
export default function NodeAboutTab() {
const { node } = useNodeDetail();
const { attributes } = node;
const navigate = useNavigate();
const { data: version } = useAdminVersion();
const deleteNode = useDeleteAdminNode();
const { data: utilization } = useAdminNodeUtilization(attributes.id);
const { data: info, error: infoError } = useAdminNodeSystemInformation(attributes.id, {
refetchInterval: 10000,
});
const canDelete = attributes.servers_count === 0;
const onDelete = (close: () => void) => {
deleteNode
.mutateAsync(deleteAdminNodeInput(attributes.id, attributes.name))
.then(() => navigate({ to: '/panel/nodes' }))
.catch(close);
};
return (
2026-10-08 16:53:20 -04:00
<div className='grid grid-cols-1 lg:grid-cols-3 gap-6'>
<div className='lg:col-span-2 space-y-6'>
<TitledGreyBox title='Information'>
<div className='text-sm text-foreground space-y-3'>
<div className='flex justify-between items-center'>
<span className='text-muted-foreground'>Daemon Version</span>
2026-10-05 18:10:18 -04:00
<span>
2026-10-08 16:53:20 -04:00
<SystemInformationValue info={info} error={infoError}>
{(value) => <Code>{value.version}</Code>}
</SystemInformationValue>
2026-10-05 18:10:18 -04:00
{version && (
2026-10-08 16:53:20 -04:00
<span className='text-xs text-muted-foreground ml-2'>Latest: {version.daemon}</span>
2026-10-05 18:10:18 -04:00
)}
</span>
</div>
2026-10-08 16:53:20 -04:00
<div className='flex justify-between items-center'>
<span className='text-muted-foreground'>System Information</span>
<span className='text-right'>
<SystemInformationValue info={info} error={infoError}>
{(value) => `${value.os} (${value.architecture}) ${value.kernel_version}`}
</SystemInformationValue>
2026-10-05 18:10:18 -04:00
</span>
</div>
2026-10-08 16:53:20 -04:00
<div className='flex justify-between items-center'>
<span className='text-muted-foreground'>Total CPU Threads</span>
2026-10-05 18:10:18 -04:00
<span>
2026-10-08 16:53:20 -04:00
<SystemInformationValue info={info} error={infoError}>
{(value) => value.cpu_count}
</SystemInformationValue>
2026-10-05 18:10:18 -04:00
</span>
</div>
</div>
</TitledGreyBox>
{attributes.description && (
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='Description'>
<pre className='text-sm text-foreground whitespace-pre-wrap wrap-break-word'>
2026-10-05 18:10:18 -04:00
{attributes.description}
</pre>
</TitledGreyBox>
)}
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='Delete Node'>
<p className='text-sm text-muted-foreground'>
2026-10-05 18:10:18 -04:00
Deleting a node is irreversible and immediately removes it from the Panel. There must be no
servers associated with this node to continue.
</p>
{!canDelete && (
2026-10-08 16:53:20 -04:00
<p className='mt-3 text-sm text-warning'>
2026-10-05 18:10:18 -04:00
Move or delete all servers on this node before deleting it.
</p>
)}
2026-10-08 16:53:20 -04:00
<div className='mt-4 text-right'>
2026-10-05 18:10:18 -04:00
<Dialog.ConfirmTrigger
2026-10-08 16:53:20 -04:00
title='Delete node'
confirm='Delete Node'
2026-10-05 18:10:18 -04:00
pending={deleteNode.isPending}
onConfirmed={(_event, close) => onDelete(close)}
trigger={({ onClick }) => (
<Button
2026-10-08 16:53:20 -04:00
type='button'
color='red'
2026-10-05 18:10:18 -04:00
disabled={!canDelete || deleteNode.isPending}
onClick={onClick}
>
Delete Node
</Button>
)}
>
Deleting <strong>{attributes.name}</strong> is permanent and cannot be undone.
</Dialog.ConfirmTrigger>
</div>
</TitledGreyBox>
</div>
2026-10-08 16:53:20 -04:00
<div className='space-y-6'>
2026-10-05 18:10:18 -04:00
{attributes.maintenance_mode && (
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='Maintenance'>
<p className='text-sm text-warning'>This node is currently under maintenance.</p>
2026-10-05 18:10:18 -04:00
</TitledGreyBox>
)}
2026-10-08 16:53:20 -04:00
<UsageBox title='Disk Space Allocated' metric={utilization?.disk} />
<UsageBox title='Memory Allocated' metric={utilization?.memory} />
<TitledGreyBox title='Total Servers'>
<p className='text-2xl text-foreground font-medium'>{attributes.servers_count}</p>
<p className='text-sm text-muted-foreground'>See the Servers tab for the full server list.</p>
2026-10-05 18:10:18 -04:00
</TitledGreyBox>
</div>
</div>
);
}