From 890b27b96d5402901fb74c3ca7428c2f44800fd5 Mon Sep 17 00:00:00 2001 From: phuongdm Date: Thu, 11 Dec 2025 14:29:06 +0700 Subject: [PATCH] yeah chay duoc roi --- src/components/forms/command-form.tsx | 102 ++++- .../forms/command-registry-form.tsx | 379 ++++++++++++++++ src/config/api.ts | 7 + src/routes/_authenticated/command/index.tsx | 365 +++++++++++++-- src/template/command-submit-template.tsx | 424 ++++++++++++++++++ 5 files changed, 1230 insertions(+), 47 deletions(-) create mode 100644 src/components/forms/command-registry-form.tsx create mode 100644 src/template/command-submit-template.tsx diff --git a/src/components/forms/command-form.tsx b/src/components/forms/command-form.tsx index f187809..3a63cea 100644 --- a/src/components/forms/command-form.tsx +++ b/src/components/forms/command-form.tsx @@ -3,23 +3,72 @@ import { useForm } from "@tanstack/react-form"; import { z } from "zod"; import { Textarea } from "@/components/ui/textarea"; +import { Label } from "@/components/ui/label"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Alert, AlertDescription } from "@/components/ui/alert"; +import { Info } from "lucide-react"; +import { useState } from "react"; + +export interface ShellCommandData { + command: string; + qos: 0 | 1 | 2; + isRetained: boolean; +} interface ShellCommandFormProps { command: string; onCommandChange: (value: string) => void; + qos?: 0 | 1 | 2; + onQoSChange?: (value: 0 | 1 | 2) => void; + isRetained?: boolean; + onIsRetainedChange?: (value: boolean) => void; disabled?: boolean; } +const QoSDescriptions = { + 0: { + name: "At Most Once (Fire and Forget)", + description: + "Gửi lệnh một lần mà không đảm bảo. Nhanh nhất, tiêu tốn ít tài nguyên.", + }, + 1: { + name: "At Least Once", + description: + "Đảm bảo lệnh sẽ được nhận ít nhất một lần. Cân bằng giữa tốc độ và độ tin cậy.", + }, + 2: { + name: "Exactly Once", + description: + "Đảm bảo lệnh được nhận chính xác một lần. Chậm nhất nhưng đáng tin cậy nhất.", + }, +}; + export function ShellCommandForm({ command, onCommandChange, + qos = 0, + onQoSChange, + isRetained = false, + onIsRetainedChange, disabled, }: ShellCommandFormProps) { + const [selectedQoS, setSelectedQoS] = useState<0 | 1 | 2>(qos); + const form = useForm({ defaultValues: { command }, onSubmit: () => {}, }); + const handleQoSChange = (value: string) => { + const newQoS = Number(value) as 0 | 1 | 2; + setSelectedQoS(newQoS); + onQoSChange?.(newQoS); + }; + + const handleRetainedChange = (checked: boolean) => { + onIsRetainedChange?.(checked); + }; + return (
{ @@ -28,6 +77,7 @@ export function ShellCommandForm({ }} className="space-y-5" > + {/* Command Input */} ( -
+
+