File size: 11,640 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | import React from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { NumberInput } from "@/components/ui/number-input";
import { Label } from "@/components/ui/label";
import { Checkbox } from "@/components/ui/checkbox";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
} from "@/components/ui/dialog";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { AlertTriangle, CheckCircle, ChevronDown } from "lucide-react";
import CameraConfiguration, {
CameraConfig,
} from "@/components/recording/CameraConfiguration";
import { useHfAuth } from "@/contexts/HfAuthContext";
import { RobotRecord } from "@/hooks/useRobots";
interface RecordingModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
robot: RobotRecord | null;
datasetName: string;
setDatasetName: (value: string) => void;
singleTask: string;
setSingleTask: (value: string) => void;
numEpisodes: number;
setNumEpisodes: (value: number) => void;
episodeTimeS: number;
setEpisodeTimeS: (value: number) => void;
resetTimeS: number;
setResetTimeS: (value: number) => void;
streamingEncoding: boolean;
setStreamingEncoding: (value: boolean) => void;
cameras: CameraConfig[];
setCameras: (cameras: CameraConfig[]) => void;
onStart: () => void;
releaseStreamsRef?: React.MutableRefObject<(() => void) | null>;
}
const RecordingModal: React.FC<RecordingModalProps> = ({
open,
onOpenChange,
robot,
datasetName,
setDatasetName,
singleTask,
setSingleTask,
numEpisodes,
setNumEpisodes,
episodeTimeS,
setEpisodeTimeS,
resetTimeS,
setResetTimeS,
streamingEncoding,
setStreamingEncoding,
cameras,
setCameras,
onStart,
releaseStreamsRef,
}) => {
const { auth } = useHfAuth();
const canStart = !!robot && robot.is_clean;
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="bg-gray-900 border-gray-800 text-white sm:max-w-[600px] p-8 max-h-[90vh] overflow-y-auto">
<DialogHeader>
<div className="flex justify-center items-center mb-4">
<div className="w-8 h-8 bg-red-500 rounded-full flex items-center justify-center">
<span className="text-white font-bold text-sm">REC</span>
</div>
</div>
<DialogTitle className="text-white text-center text-2xl font-bold">
Configure Recording
</DialogTitle>
</DialogHeader>
<div className="space-y-6 py-4">
<DialogDescription className="text-gray-400 text-base leading-relaxed text-center">
Pick a configured robot and dataset parameters for recording.
</DialogDescription>
<div className="grid grid-cols-1 gap-6">
<div className="space-y-4">
<h3 className="text-lg font-semibold text-white border-b border-gray-700 pb-2">
Robot Configuration
</h3>
{!robot ? (
<Alert className="bg-amber-900/40 border-amber-700 text-amber-100">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>
Select and configure a robot on the Landing page before
recording.
</AlertDescription>
</Alert>
) : !robot.is_clean ? (
<Alert className="bg-amber-900/40 border-amber-700 text-amber-100">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>
<strong>{robot.name}</strong> is missing a calibration.
Configure it before recording.
</AlertDescription>
</Alert>
) : (
<div className="flex items-center gap-2 text-sm">
<CheckCircle className="w-4 h-4 text-green-400" />
<span className="text-slate-200">
Recording with <strong>{robot.name}</strong>
</span>
</div>
)}
</div>
<div className="space-y-4">
<h3 className="text-lg font-semibold text-white border-b border-gray-700 pb-2">
Dataset Configuration
</h3>
<div className="grid grid-cols-1 gap-4">
<div className="space-y-2">
<Label
htmlFor="datasetName"
className="text-sm font-medium text-gray-300"
>
Dataset Name *
</Label>
<Input
id="datasetName"
value={datasetName}
onChange={(e) =>
setDatasetName(
e.target.value.replace(/[^A-Za-z0-9._-]/g, "_")
)
}
placeholder="my_dataset"
className="bg-gray-800 border-gray-700 text-white"
/>
<p className="text-xs text-gray-500">
Letters, numbers, <code>.</code> <code>_</code>{" "}
<code>-</code> only — other characters become{" "}
<code>_</code>.
</p>
{datasetName &&
(auth.status === "authenticated" ? (
<p className="text-xs text-gray-500">
Will be saved as{" "}
<span className="text-gray-300 font-mono">
{auth.username}/{datasetName}
</span>
</p>
) : auth.status === "unauthenticated" ? (
<p className="text-xs text-amber-400/80">
Log in to Hugging Face to set the repository owner.
</p>
) : null)}
</div>
<div className="space-y-2">
<Label
htmlFor="singleTask"
className="text-sm font-medium text-gray-300"
>
Task Description *
</Label>
<Input
id="singleTask"
value={singleTask}
onChange={(e) => setSingleTask(e.target.value)}
placeholder="e.g., pick up the red block and place it on the blue square"
className="bg-gray-800 border-gray-700 text-white"
/>
</div>
<div className="space-y-2">
<Label
htmlFor="numEpisodes"
className="text-sm font-medium text-gray-300"
>
Number of Episodes
</Label>
<NumberInput
id="numEpisodes"
min="1"
max="100"
value={numEpisodes}
onChange={(v) => {
if (v !== undefined) setNumEpisodes(v);
}}
className="bg-gray-800 border-gray-700 text-white"
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label
htmlFor="episodeTimeS"
className="text-sm font-medium text-gray-300"
>
Episode duration (seconds)
</Label>
<NumberInput
id="episodeTimeS"
min="1"
value={episodeTimeS}
onChange={(v) => {
if (v !== undefined) setEpisodeTimeS(v);
}}
className="bg-gray-800 border-gray-700 text-white"
/>
</div>
<div className="space-y-2">
<Label
htmlFor="resetTimeS"
className="text-sm font-medium text-gray-300"
>
Reset duration (seconds)
</Label>
<NumberInput
id="resetTimeS"
min="1"
value={resetTimeS}
onChange={(v) => {
if (v !== undefined) setResetTimeS(v);
}}
className="bg-gray-800 border-gray-700 text-white"
/>
</div>
</div>
</div>
</div>
<div className="space-y-4">
<CameraConfiguration
cameras={cameras}
onCamerasChange={setCameras}
releaseStreamsRef={releaseStreamsRef}
/>
</div>
<Collapsible className="space-y-4 group">
<CollapsibleTrigger className="flex items-center justify-between w-full text-lg font-semibold text-white border-b border-gray-700 pb-2">
<span>Advanced Parameters</span>
<ChevronDown className="w-4 h-4 transition-transform group-data-[state=open]:rotate-180" />
</CollapsibleTrigger>
<CollapsibleContent className="space-y-3">
<div className="flex items-start gap-3">
<Checkbox
id="streamingEncoding"
checked={streamingEncoding}
onCheckedChange={(value) =>
setStreamingEncoding(value === true)
}
className="mt-0.5 border-gray-500 data-[state=checked]:bg-red-500 data-[state=checked]:border-red-500"
/>
<div className="space-y-1">
<Label
htmlFor="streamingEncoding"
className="text-sm font-medium text-gray-200 cursor-pointer"
>
Streaming video encoding
</Label>
<p className="text-xs text-gray-500">
Encodes frames in real time during capture so each
episode saves almost instantly. Uncheck to fall back to
the slower PNG-then-encode flow.
</p>
</div>
</div>
</CollapsibleContent>
</Collapsible>
</div>
<div className="flex flex-col sm:flex-row gap-4 justify-center pt-4">
<Button
onClick={onStart}
disabled={!canStart}
className="w-full sm:w-auto bg-red-500 hover:bg-red-600 text-white px-10 py-6 text-lg transition-all shadow-md shadow-red-500/30 hover:shadow-lg hover:shadow-red-500/40 disabled:opacity-40 disabled:cursor-not-allowed"
>
Start Recording
</Button>
<Button
onClick={() => onOpenChange(false)}
variant="outline"
className="w-full sm:w-auto border-gray-500 hover:border-gray-200 px-10 py-6 text-lg text-zinc-500 bg-zinc-900 hover:bg-zinc-800"
>
Cancel
</Button>
</div>
</div>
</DialogContent>
</Dialog>
);
};
export default RecordingModal;
|