File size: 5,033 Bytes
fc9bd9f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | import React, { useState } from "react";
import { Settings, Trash2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { RobotRecord } from "@/hooks/useRobots";
import RobotSelector from "./RobotSelector";
interface RobotTileProps {
robot: RobotRecord | null;
selectedName: string | null;
availableNames: string[];
isLoading: boolean;
onSelect: (name: string) => void;
onCreateNew: (name: string) => Promise<boolean>;
onConfigure: (name: string) => void;
onTeleop: (robot: RobotRecord) => void;
onDelete: (name: string) => void;
}
const RobotTile: React.FC<RobotTileProps> = ({
robot,
selectedName,
availableNames,
isLoading,
onSelect,
onCreateNew,
onConfigure,
onTeleop,
onDelete,
}) => {
const [confirmDelete, setConfirmDelete] = useState(false);
const status = robot ? (robot.is_clean ? "Ready" : "Needs configuration") : null;
const teleopDisabled = !robot || !robot.is_clean;
return (
<div className="bg-gray-800 rounded-lg border border-gray-700 p-3 flex flex-col gap-2 relative">
<div className="flex items-center gap-2">
<div className="flex-1 min-w-0">
<RobotSelector
selectedName={selectedName}
availableNames={availableNames}
onSelect={onSelect}
onCreateNew={onCreateNew}
isLoading={isLoading}
/>
</div>
{status && (
<p
className={`text-xs truncate shrink-0 ${
robot!.is_clean ? "text-green-400" : "text-amber-400"
}`}
>
{status}
</p>
)}
{robot && (
<div className="flex items-center gap-1 shrink-0">
<Tooltip>
<TooltipTrigger asChild>
<Button
size="icon"
variant="ghost"
className="h-8 w-8 text-gray-300 hover:text-white"
onClick={() => onConfigure(robot.name)}
aria-label="Configure"
>
<Settings className="w-4 h-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Configure (calibrate)</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
size="icon"
variant="ghost"
className="h-8 w-8 text-red-400 hover:text-red-300 hover:bg-red-900/20"
onClick={() => setConfirmDelete(true)}
aria-label="Delete robot"
>
<Trash2 className="w-4 h-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Delete robot config</TooltipContent>
</Tooltip>
</div>
)}
</div>
{robot && (
<Tooltip>
<TooltipTrigger asChild>
<div className="w-full">
<Button
onClick={() => onTeleop(robot)}
disabled={teleopDisabled}
className={`w-full ${
teleopDisabled
? "bg-red-500/30 hover:bg-red-500/30 text-red-200 cursor-not-allowed"
: "bg-yellow-500 hover:bg-yellow-600 text-white"
}`}
>
Teleoperation
</Button>
</div>
</TooltipTrigger>
{teleopDisabled && (
<TooltipContent>Configure the robot first.</TooltipContent>
)}
</Tooltip>
)}
{robot && (
<Dialog open={confirmDelete} onOpenChange={setConfirmDelete}>
<DialogContent className="bg-gray-900 border-gray-800 text-white">
<DialogHeader>
<DialogTitle>Delete robot config?</DialogTitle>
<DialogDescription className="text-gray-400">
This deletes the robot config file from disk. Calibration files
are not removed. This cannot be undone.
</DialogDescription>
</DialogHeader>
<DialogFooter className="flex gap-2 justify-end">
<Button
variant="outline"
className="border-gray-600 text-gray-300"
onClick={() => setConfirmDelete(false)}
>
Cancel
</Button>
<Button
className="bg-red-500 hover:bg-red-600 text-white"
onClick={async () => {
setConfirmDelete(false);
await onDelete(robot.name);
}}
>
Delete
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)}
</div>
);
};
export default RobotTile;
|