File size: 10,073 Bytes
7a0c9ff
a8d792f
f680c3f
7a0c9ff
 
 
 
 
 
 
 
 
 
 
f680c3f
 
 
 
 
 
 
 
 
 
7a0c9ff
 
f680c3f
7a0c9ff
a8d792f
 
7a0c9ff
 
 
 
 
 
 
 
a8d792f
 
 
 
 
 
 
 
 
 
 
 
f680c3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8d792f
f680c3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8d792f
 
f680c3f
 
 
 
 
 
 
 
 
 
 
a8d792f
 
f680c3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8d792f
f680c3f
 
 
 
 
 
 
 
 
 
 
a8d792f
f680c3f
 
 
 
 
 
 
 
 
 
 
 
 
a8d792f
f680c3f
 
 
 
 
 
 
 
 
a8d792f
 
 
f680c3f
 
 
 
 
 
 
 
 
a8d792f
f680c3f
 
 
 
 
 
 
7a0c9ff
a8d792f
 
 
f680c3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a0c9ff
a8d792f
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
"use client";

import { useState } from "react";
import {
  Settings,
  Gamepad2,
  Trash2,
  Pencil,
  Plus,
  ExternalLink,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { Card, CardFooter } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { cn } from "@/lib/utils";
import HudCorners from "@/components/hud-corners";
import { getUnifiedRobotData } from "@/lib/unified-storage";
import type { RobotConnection } from "@/types/robot";

interface DeviceDashboardProps {
  robots: RobotConnection[];
  onCalibrate: (robot: RobotConnection) => void;
  onTeleoperate: (robot: RobotConnection) => void;
  onRemove: (robotId: string) => void;
  onEdit: (robot: RobotConnection) => void;
  onFindNew: () => void;
  isConnecting: boolean;
  onScrollToHardware: () => void;
}

export function DeviceDashboard({
  robots,
  onCalibrate,
  onTeleoperate,
  onRemove,
  onEdit,
  onFindNew,
  isConnecting,
  onScrollToHardware,
}: DeviceDashboardProps) {
  const [robotToRemove, setRobotToRemove] = useState<RobotConnection | null>(
    null
  );

  const handleRemoveClick = (robot: RobotConnection) => {
    setRobotToRemove(robot);
  };

  const handleConfirmRemove = () => {
    if (robotToRemove) {
      onRemove(
        robotToRemove.robotId || robotToRemove.serialNumber || "unknown"
      );
      setRobotToRemove(null);
    }
  };

  const handleCancelRemove = () => {
    setRobotToRemove(null);
  };
  return (
    <>
      <Card className="border-0 rounded-none">
        <div className="p-4 border-b border-white/10 flex items-center justify-between">
          <div className="flex items-center gap-4">
            <div className="w-1 h-8 bg-primary"></div>
            <div>
              <h3 className="text-xl font-bold text-foreground font-mono tracking-wider uppercase">
                device registry
              </h3>
              <div className="flex items-center gap-2 mt-1">
                <span className="text-xs text-muted-foreground font-mono">
                  currently supports SO-100{" "}
                </span>
                <button
                  onClick={onScrollToHardware}
                  className="text-xs text-primary hover:text-accent transition-colors underline font-mono flex items-center gap-1"
                >
                  <ExternalLink className="w-3 h-3" />
                  add more devices
                </button>
              </div>
            </div>
          </div>
          {robots.length > 0 && (
            <Button
              onClick={onFindNew}
              disabled={isConnecting}
              size="lg"
              className="font-mono uppercase"
            >
              <Plus className="w-4 h-4 mr-2" />
              add unit
            </Button>
          )}
        </div>

        <div className="pt-6 p-6">
          {robots.length === 0 ? (
            <div className="relative">
              <HudCorners className="p-16">
                <div className="text-center font-mono">
                  <div className="mb-6">
                    {isConnecting ? (
                      <>
                        <div className="w-16 h-16 mx-auto mb-4 border-2 border-primary/50 rounded-lg flex items-center justify-center animate-pulse">
                          <Plus className="w-8 h-8 text-primary animate-spin" />
                        </div>
                        <h4 className="text-xl text-primary mb-2 tracking-wider uppercase">
                          scanning for units
                        </h4>
                        <p className="text-sm text-muted-foreground mb-8">
                          searching for available devices...
                        </p>
                      </>
                    ) : (
                      <>
                        <div className="w-16 h-16 mx-auto mb-4 border-2 border-dashed border-primary/50 rounded-lg flex items-center justify-center">
                          <Plus className="w-8 h-8 text-primary/50" />
                        </div>
                        <h4 className="text-xl text-primary mb-2 tracking-wider uppercase">
                          no units detected
                        </h4>

                        <Button
                          onClick={onFindNew}
                          size="lg"
                          className="font-mono uppercase"
                        >
                          <Plus className="w-4 h-4 mr-2" />
                          add unit
                        </Button>
                      </>
                    )}
                  </div>
                </div>
              </HudCorners>
            </div>
          ) : (
            <div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
              {robots.map((robot) => (
                <HudCorners key={robot.robotId}>
                  <Card className="flex flex-col h-full">
                    <div className="p-4 border-b border-white/10">
                      <div className="flex items-center justify-between">
                        <div className="flex-1">
                          <h4 className="text-2xl font-bold text-primary font-mono tracking-wider">
                            {robot.name}
                          </h4>
                        </div>
                        <Badge
                          variant="outline"
                          className={cn(
                            "border-primary/50 bg-primary/20 text-primary font-mono text-xs",
                            robot.isConnected && "animate-pulse-slow"
                          )}
                        >
                          {robot.isConnected ? "ONLINE" : "OFFLINE"}
                        </Badge>
                      </div>
                    </div>

                    <div className="flex-grow p-4">
                      <div className="grid grid-cols-2 gap-4 text-xs font-mono">
                        <div>
                          <span className="text-muted-foreground/40 uppercase">
                            serial number
                          </span>
                          <div className="text-muted-foreground uppercase/70">
                            {robot.serialNumber}
                          </div>
                        </div>
                        <div>
                          <span className="text-muted-foreground/40 uppercase">
                            type
                          </span>
                          <div className="text-muted-foreground uppercase/70">
                            {robot.robotType}
                          </div>
                        </div>
                      </div>
                    </div>

                    <CardFooter className="p-4 border-t border-white/10 flex flex-wrap gap-2">
                      <Button
                        variant="outline"
                        size="sm"
                        onClick={() => onEdit(robot)}
                        className="font-mono text-xs uppercase px-2"
                      >
                        <Pencil className="w-3 h-3 mr-0.5" /> edit
                      </Button>
                      <Button
                        variant="outline"
                        size="sm"
                        onClick={() => onCalibrate(robot)}
                        className="font-mono text-xs uppercase px-2"
                      >
                        <Settings className="w-3 h-3 mr-0.5" />
                        {robot.serialNumber &&
                        getUnifiedRobotData(robot.serialNumber)?.calibration
                          ? "re-calibrate"
                          : "calibrate"}
                      </Button>
                      <Button
                        variant="outline"
                        size="sm"
                        onClick={() => onTeleoperate(robot)}
                        className="font-mono text-xs uppercase px-2"
                      >
                        <Gamepad2 className="w-3 h-3 mr-0.5" /> control
                      </Button>
                      <Button
                        variant="destructive"
                        size="sm"
                        onClick={() => handleRemoveClick(robot)}
                        className="font-mono text-xs uppercase px-2"
                      >
                        <Trash2 className="w-3 h-3 mr-0.5" /> remove
                      </Button>
                    </CardFooter>
                  </Card>
                </HudCorners>
              ))}
            </div>
          )}
        </div>
      </Card>

      <AlertDialog
        open={!!robotToRemove}
        onOpenChange={() => setRobotToRemove(null)}
      >
        <AlertDialogContent>
          <AlertDialogHeader>
            <AlertDialogTitle>Remove Robot</AlertDialogTitle>
            <AlertDialogDescription>
              Are you sure you want to remove{" "}
              <strong>{robotToRemove?.name || robotToRemove?.robotId}</strong>{" "}
              from the device registry?
              <br />
              <br />
              This will permanently delete all stored calibration data and
              settings for this robot. This action cannot be undone.
            </AlertDialogDescription>
          </AlertDialogHeader>
          <AlertDialogFooter>
            <AlertDialogCancel onClick={handleCancelRemove}>
              Cancel
            </AlertDialogCancel>
            <AlertDialogAction
              onClick={handleConfirmRemove}
              className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
            >
              Remove Robot
            </AlertDialogAction>
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
    </>
  );
}