Skip to content

Commit 1d93aa4

Browse files
committed
chore: Biome check --fix + manual amends
1 parent 419bfd1 commit 1d93aa4

31 files changed

Lines changed: 211 additions & 183 deletions

File tree

docker/dd-extension/ui/eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import globals from "globals";
21
import pluginJs from "@eslint/js";
3-
import tseslint from "typescript-eslint";
42
import pluginReact from "eslint-plugin-react";
3+
import globals from "globals";
4+
import tseslint from "typescript-eslint";
55

66
export default [
77
{

docker/dd-extension/ui/src/components/ShowCommand.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ export default function ShowCommand({
1616
curlPort,
1717
}: ShowCommandProps) {
1818
const [isRunningCommand, setRunningCommand] = useState(false);
19-
20-
if (!validated) {
21-
return null;
22-
}
2319
const ddClient = useDockerDesktopClient();
2420

21+
if (!validated) return null;
22+
2523
function copyToClipboard() {
2624
navigator.clipboard
2725
.writeText(command)

docker/dd-extension/ui/src/components/Snapshot.tsx

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type React from "react";
2-
import { useEffect, useState } from "react";
2+
import { useCallback, useEffect, useState } from "react";
33
import { Button, Col, Row } from "react-bootstrap";
44
import Form from "react-bootstrap/Form";
55
import { openBrowserUrl } from "../helpers";
@@ -48,13 +48,13 @@ export default function Snapshot() {
4848
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
4949
setTokenValidated(false);
5050
const { name, value } = e.target;
51-
if (name == "license") {
51+
if (name === "license") {
5252
setLicenseKey(value);
53-
} else if (name == "token") {
53+
} else if (name === "token") {
5454
setToken(value);
55-
} else if (name == "port") {
55+
} else if (name === "port") {
5656
setCurlPort(value);
57-
} else if (name == "restart-policy") {
57+
} else if (name === "restart-policy") {
5858
setRestartPolicy(value);
5959
}
6060
};
@@ -64,13 +64,7 @@ export default function Snapshot() {
6464
setArchitecture(e.target.value);
6565
};
6666

67-
// type SnapshotData = {
68-
// port: string;
69-
// license: string;
70-
// token: string;
71-
// image: string;
72-
// }
73-
const generateDockerImage = () => {
67+
const generateDockerImage = useCallback(() => {
7468
let dockerImage = "platerecognizer/";
7569
if (
7670
country === "Global" ||
@@ -83,45 +77,49 @@ export default function Snapshot() {
8377
}
8478
setDockerimage(dockerImage);
8579
return dockerImage;
86-
};
87-
const generateDockerRunCommand = (dockerImage: string) => {
88-
let restartOption;
89-
switch (restartPolicy) {
90-
case "no":
91-
restartOption = "";
92-
break;
93-
default:
94-
restartOption = `--restart=${restartPolicy} `;
95-
break;
96-
}
97-
const baseCommand = `docker run ${restartOption}-t -p ${curlPort}:8080 -v license:/license`;
98-
let platformSpecificCommand = "";
80+
}, [country, architecture]);
9981

100-
switch (architecture) {
101-
case "alpr-jetson":
102-
case "alpr-jetson:r35":
103-
platformSpecificCommand = ` --runtime nvidia -e LICENSE_KEY=${licenseKey} -e TOKEN=${token} ${dockerImage}`;
104-
break;
105-
case "alpr-gpu":
106-
platformSpecificCommand = ` --gpus all -e LICENSE_KEY=${licenseKey} -e TOKEN=${token} ${dockerImage}`;
107-
break;
108-
case "alpr":
109-
case "alpr-no-avx":
110-
case "alpr-arm":
111-
case "alpr-zcu104":
112-
platformSpecificCommand = ` -e LICENSE_KEY=${licenseKey} -e TOKEN=${token} ${dockerImage}`;
113-
break;
114-
default:
115-
break;
116-
}
82+
const generateDockerRunCommand = useCallback(
83+
(dockerImage: string) => {
84+
let restartOption: string;
85+
switch (restartPolicy) {
86+
case "no":
87+
restartOption = "";
88+
break;
89+
default:
90+
restartOption = `--restart=${restartPolicy} `;
91+
break;
92+
}
93+
const baseCommand = `docker run ${restartOption}-t -p ${curlPort}:8080 -v license:/license`;
94+
let platformSpecificCommand = "";
11795

118-
setCommand(`${baseCommand} ${platformSpecificCommand}`);
119-
};
96+
switch (architecture) {
97+
case "alpr-jetson":
98+
case "alpr-jetson:r35":
99+
platformSpecificCommand = ` --runtime nvidia -e LICENSE_KEY=${licenseKey} -e TOKEN=${token} ${dockerImage}`;
100+
break;
101+
case "alpr-gpu":
102+
platformSpecificCommand = ` --gpus all -e LICENSE_KEY=${licenseKey} -e TOKEN=${token} ${dockerImage}`;
103+
break;
104+
case "alpr":
105+
case "alpr-no-avx":
106+
case "alpr-arm":
107+
case "alpr-zcu104":
108+
platformSpecificCommand = ` -e LICENSE_KEY=${licenseKey} -e TOKEN=${token} ${dockerImage}`;
109+
break;
110+
default:
111+
break;
112+
}
113+
114+
setCommand(`${baseCommand} ${platformSpecificCommand}`);
115+
},
116+
[restartPolicy, curlPort, architecture, licenseKey, token],
117+
);
120118

121119
useEffect(() => {
122120
const imagem = generateDockerImage();
123121
generateDockerRunCommand(imagem);
124-
}, [country, architecture, token, curlPort, licenseKey, restartPolicy]);
122+
}, [generateDockerImage, generateDockerRunCommand]);
125123

126124
// Load any existing data from local storage on component mount
127125
useEffect(() => {
@@ -148,8 +146,8 @@ export default function Snapshot() {
148146

149147
ddClient.extension.vm?.service?.post("/verify-token", data).then((res: any) => {
150148
console.debug(res);
151-
const valid = res["valid"];
152-
const message = res["message"];
149+
const valid = res.valid;
150+
const message = res.message;
153151
if (valid) {
154152
localStorage.setItem(
155153
"snapshot",
@@ -241,7 +239,7 @@ export default function Snapshot() {
241239
label="No (Docker Default)"
242240
id="rps1"
243241
value="no"
244-
checked={restartPolicy == "no"}
242+
checked={restartPolicy === "no"}
245243
onChange={handleInputChange}
246244
/>
247245
<Form.Check
@@ -250,7 +248,7 @@ export default function Snapshot() {
250248
label="Unless Stopped"
251249
id="rps2"
252250
value="unless-stopped"
253-
checked={restartPolicy == "unless-stopped"}
251+
checked={restartPolicy === "unless-stopped"}
254252
onChange={handleInputChange}
255253
/>
256254
<Form.Check
@@ -259,7 +257,7 @@ export default function Snapshot() {
259257
label="Always"
260258
id="rps3"
261259
value="always"
262-
checked={restartPolicy == "always"}
260+
checked={restartPolicy === "always"}
263261
onChange={handleInputChange}
264262
/>
265263
<Form.Check
@@ -268,7 +266,7 @@ export default function Snapshot() {
268266
label="On Failure"
269267
id="rps4"
270268
value="on-failure"
271-
checked={restartPolicy == "on-failure"}
269+
checked={restartPolicy === "on-failure"}
272270
onChange={handleInputChange}
273271
/>
274272
</Col>
@@ -306,9 +304,9 @@ export default function Snapshot() {
306304
architecture === "alpr-jetson:r35" || architecture === "alpr-no-avx"
307305
}
308306
>
309-
{countryOptions.map((option, index) => (
310-
<option key={index} value={option.value}>
311-
{option.label}
307+
{countryOptions.map(({ value, label }) => (
308+
<option key={label} value={value}>
309+
{label}
312310
</option>
313311
))}
314312
</Form.Select>
@@ -320,9 +318,9 @@ export default function Snapshot() {
320318
name="image"
321319
defaultValue={architecture}
322320
>
323-
{architectureOptionsSnapshot.map((option, index) => (
324-
<option key={index} value={option.value}>
325-
{option.label}
321+
{architectureOptionsSnapshot.map(({ value, label }) => (
322+
<option key={value} value={value}>
323+
{label}
326324
</option>
327325
))}
328326
</Form.Select>
@@ -333,12 +331,15 @@ export default function Snapshot() {
333331

334332
<Form.Group as={Row} className="mb-3">
335333
<div className="col-2">
336-
<Button className="btn btn-primary" type="submit">
334+
<Button className="btn btn-primary" type="submit" id="validateSnapshotBtn">
337335
<Loader isLoading={isLoading} />
338336
Show Docker Command
339337
</Button>
340338
</div>
341-
<label className="col-auto align-self-center form-label">
339+
<label
340+
className="col-auto align-self-center form-label"
341+
htmlFor="validateSnapshotBtn"
342+
>
342343
Confirm settings and show docker command.
343344
</label>
344345
</Form.Group>

docker/dd-extension/ui/src/components/Stream.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ export default function Stream() {
2828

2929
const handleConfigureClick = () => {
3030
if (license) {
31-
const url = "https://app.platerecognizer.com/stream-config/" + license;
31+
const url = `https://app.platerecognizer.com/stream-config/${license}`;
3232
openBrowserUrl(ddClient, url);
3333
} else {
3434
ddClient.desktopUI.toast.error("License Key is required");
3535
}
3636
};
3737
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
3838
const { name, value } = e.target;
39-
if (name == "license") {
39+
if (name === "license") {
4040
setLicense(value);
41-
} else if (name == "restart-policy") {
41+
} else if (name === "restart-policy") {
4242
setRestartPolicy(value);
43-
} else if (name == "token") {
43+
} else if (name === "token") {
4444
setToken(value);
45-
} else if (name == "streamPath") {
45+
} else if (name === "streamPath") {
4646
setStreamPath(value);
4747
}
4848
setTokenValidated(false);
@@ -58,8 +58,8 @@ export default function Stream() {
5858
setLoading(true);
5959
ddClient.extension.vm?.service?.post("/verify-token", data).then((res: any) => {
6060
console.debug(res);
61-
const valid = res["valid"];
62-
const message = res["message"];
61+
const valid = res.valid;
62+
const message = res.message;
6363
if (valid) {
6464
localStorage.setItem(
6565
"stream",
@@ -74,7 +74,7 @@ export default function Stream() {
7474
ddClient.docker.cli.exec("pull", [STREAM_IMAGE]).then((result) => {
7575
console.debug(result);
7676
const autoBoot =
77-
restartPolicy != "no" ? " --restart " + restartPolicy : "--rm";
77+
restartPolicy !== "no" ? ` --restart ${restartPolicy}` : "--rm";
7878
const command = `docker run ${autoBoot} -t -v ${data.streamPath}:/user-data/ -e LICENSE_KEY=${data.license} -e TOKEN=${data.token} ${STREAM_IMAGE}`;
7979
setCommand(command);
8080
setTokenValidated(valid);
@@ -174,7 +174,7 @@ export default function Stream() {
174174
label="No (Docker Default)"
175175
id="rp1"
176176
value="no"
177-
checked={restartPolicy == "no"}
177+
checked={restartPolicy === "no"}
178178
onChange={handleInputChange}
179179
/>
180180
<Form.Check
@@ -183,7 +183,7 @@ export default function Stream() {
183183
label="Unless Stopped"
184184
id="rp2"
185185
value="unless-stopped"
186-
checked={restartPolicy == "unless-stopped"}
186+
checked={restartPolicy === "unless-stopped"}
187187
onChange={handleInputChange}
188188
/>
189189
<Form.Check
@@ -192,7 +192,7 @@ export default function Stream() {
192192
label="Always"
193193
id="rp3"
194194
value="always"
195-
checked={restartPolicy == "always"}
195+
checked={restartPolicy === "always"}
196196
onChange={handleInputChange}
197197
/>
198198
<Form.Check
@@ -201,7 +201,7 @@ export default function Stream() {
201201
label="On Failure"
202202
id="rp4"
203203
value="on-failure"
204-
checked={restartPolicy == "on-failure"}
204+
checked={restartPolicy === "on-failure"}
205205
onChange={handleInputChange}
206206
/>
207207
</Col>
@@ -229,12 +229,19 @@ export default function Stream() {
229229

230230
<Form.Group as={Row} className="mb-3">
231231
<div className="col-2">
232-
<Button className="btn btn-primary" type="submit">
232+
<Button
233+
className="btn btn-primary"
234+
type="submit"
235+
id="button-submit-docker-command"
236+
>
233237
<Loader isLoading={isLoading} />
234238
Show Docker Command
235239
</Button>
236240
</div>
237-
<label className="col-auto align-self-center form-label">
241+
<label
242+
className="col-auto align-self-center form-label"
243+
htmlFor="button-submit-docker-command"
244+
>
238245
Confirm settings and show docker command.
239246
</label>
240247
</Form.Group>

docker/dd-extension/ui/src/components/Uninstall.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import { useState } from "react";
22
import { Button, Row } from "react-bootstrap";
33
import Form from "react-bootstrap/Form";
44
import { useDockerDesktopClient } from "../hooks/useDockerDesktopClient";
@@ -10,12 +10,11 @@ interface UninstallProps {
1010
image: string;
1111
}
1212
export default function Uninstall({ isEnabled, image }: UninstallProps) {
13-
if (!isEnabled) {
14-
return null;
15-
}
1613
const [isLoading, setLoading] = useState(false);
1714
const ddClient = useDockerDesktopClient();
1815

16+
if (!isEnabled) return null;
17+
1918
const handleUninstall = () => {
2019
setLoading(true);
2120
ddClient.docker.cli
@@ -48,12 +47,20 @@ export default function Uninstall({ isEnabled, image }: UninstallProps) {
4847
return (
4948
<Form.Group as={Row} className="mb-3">
5049
<div className="col-2">
51-
<Button className="btn btn-danger" type="button" onClick={handleUninstall}>
50+
<Button
51+
className="btn btn-danger"
52+
type="button"
53+
onClick={handleUninstall}
54+
id="uninstall-button"
55+
>
5256
<Loader isLoading={isLoading} />
5357
Uninstall
5458
</Button>
5559
</div>
56-
<label className="col-auto align-self-center form-label">
60+
<label
61+
className="col-auto align-self-center form-label"
62+
htmlFor="uninstall-button"
63+
>
5764
Remove the Docker image and mark the product as uninstalled.
5865
</label>
5966
</Form.Group>

0 commit comments

Comments
 (0)