Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/lib/nodes/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,26 @@ dayjs.extend(utc);
dayjs.extend(advanced);
dayjs.extend(timezone);

// Extended VM type to include zone field for auto-reserved nodes
type VMWithZone = NonNullable<SFCNodes.Node["vms"]>["data"][number] & {
zone?: string | null;
};

// Helper component to display VMs in a table format using Ink
function VMTable({ vms }: { vms: NonNullable<SFCNodes.Node["vms"]>["data"] }) {
function VMTable({
vms,
nodeZone
}: {
vms: VMWithZone[];
nodeZone?: string | null;
}) {
const sortedVms = vms.sort((a, b) => b.updated_at - a.updated_at);
const vmsToShow = sortedVms.slice(0, 5);
const remainingVms = sortedVms.length - 5;

// Show zone column only when node doesn't have a zone (auto-reserved nodes)
const showZoneColumn = !nodeZone;

return (
<Box flexDirection="column" padding={0}>
{/* Header */}
Expand All @@ -57,6 +71,11 @@ function VMTable({ vms }: { vms: NonNullable<SFCNodes.Node["vms"]>["data"] }) {
<Box width={15} padding={0}>
<Text bold color="cyan">Status</Text>
</Box>
{showZoneColumn && (
<Box width={20} padding={0}>
<Text bold color="cyan">Zone</Text>
</Box>
)}
<Box width={30} padding={0}>
<Text bold color="cyan">Start/End</Text>
</Box>
Expand All @@ -76,6 +95,11 @@ function VMTable({ vms }: { vms: NonNullable<SFCNodes.Node["vms"]>["data"] }) {
<Box width={15} padding={0}>
<Text>{getVMStatusColor(vm.status)}</Text>
</Box>
{showZoneColumn && (
<Box width={20} padding={0}>
<Text>{vm.zone ?? "N/A"}</Text>
</Box>
)}
<Box width={30} padding={0}>
<Text>{startEnd}</Text>
</Box>
Expand Down Expand Up @@ -383,7 +407,7 @@ function NodeVerboseDisplay({ node }: { node: SFCNodes.Node }) {
<Text color="cyan" bold>💿</Text>
</Box>
<Box marginTop={1}>
<VMTable vms={node.vms.data} />
<VMTable vms={node.vms.data as VMWithZone[]} nodeZone={node.zone} />
</Box>
</Box>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,8 @@ export interface components {
* @example 1640995200
*/
updated_at: number;
/** @example hayesvalley */
zone?: string | null;
};
"node-api_VmList": {
data: components["schemas"]["node-api_Vm"][];
Expand Down
Loading