diff --git a/src/App.tsx b/src/App.tsx index d9ee7e69..89a7405d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -460,12 +460,7 @@ function App(props: RouteSectionProps) { }, logging: { icon: IconGraph, - label: "Logging", - disabled: false, - }, - logViewer: { - icon: IconDeviceAnalytics, - label: "Log Viewer", + label: "Driver Logger", disabled: false, }, vibrationLogger: { @@ -473,6 +468,11 @@ function App(props: RouteSectionProps) { label: "Vibration Logger", disabled: false, }, + logViewer: { + icon: IconDeviceAnalytics, + label: "Log Viewer", + disabled: false, + }, }; const navbarHeight = "2rem"; diff --git a/src/features/configuration/ConfigForm/DrivercomCommandButton.tsx b/src/components/workspace/port-connect-button/PortConnectButton.tsx similarity index 56% rename from src/features/configuration/ConfigForm/DrivercomCommandButton.tsx rename to src/components/workspace/port-connect-button/PortConnectButton.tsx index d7874bc9..06d6155e 100644 --- a/src/features/configuration/ConfigForm/DrivercomCommandButton.tsx +++ b/src/components/workspace/port-connect-button/PortConnectButton.tsx @@ -1,19 +1,24 @@ -import { createSignal, For, JSX, Show } from "solid-js"; +import { createSignal, For, Show } from "solid-js"; import { Text } from "~/components/ui/text"; import { Tooltip } from "~/components/ui/tooltip"; import { toaster } from "~/components/ui/toast.tsx"; import * as Menu from "~/components/ui/menu"; import { detectPort, getConfigFromPort } from "~/services/PortService"; import { Port } from "~/stores/ports"; +import { + IconPlugConnected, + IconPlugConnectedX, + IconX, +} from "@tabler/icons-solidjs"; +import { IconButton } from "~/components/ui/icon-button"; type PortInfo = { driverId?: number; stationId?: number } & Port; -export function DrivercomCommandButton( - props: { - onRunCommand?: (portId: string, version: string) => void; - tooltipContent?: string; - } & JSX.HTMLAttributes, -) { +export function PortConnectButton(props: { + isConnect: boolean; + onPortConnected?: (portId: string, version: string) => void; + size?: "2xs" | "xs" | "sm"; +}) { const [ports, setPorts] = createSignal([]); const [open, setOpen] = createSignal(false); @@ -28,7 +33,9 @@ export function DrivercomCommandButton( { + onClick={async (e) => { + e.stopPropagation(); + if (open()) return; const detectedPorts = await detectPort(); if (detectedPorts.length === 0) { toaster.create({ @@ -54,11 +61,14 @@ export function DrivercomCommandButton( setPorts(portInfos); }} > - - {props.children} + + + {props.isConnect ? : } + @@ -68,21 +78,36 @@ export function DrivercomCommandButton( {(port) => { return ( props.onRunCommand?.(port.id, port.version)} + onClick={() => + props.onPortConnected?.(port.id, port.version) + } value={port.id} display={"flex"} - flexDir={"column"} textAlign={"left"} gap="0" + paddingRight="0" > - - {port.id} - - - - {`CC-Link Station ID: ${port.stationId}`} +
+ + {port.id} - + + + {`CC-Link Station ID: ${port.stationId}`} + + +
+ { + e.stopPropagation(); + props.onPortConnected?.("", ""); + }} + > + +
); }} diff --git a/src/features/configuration/ConfigForm/DriverStatus.tsx b/src/features/configuration/ConfigForm/DriverStatus.tsx index 5a2c3885..cea54451 100644 --- a/src/features/configuration/ConfigForm/DriverStatus.tsx +++ b/src/features/configuration/ConfigForm/DriverStatus.tsx @@ -16,7 +16,6 @@ import { Tooltip } from "~/components/ui/tooltip"; import { IconButton } from "~/components/ui/icon-button"; import { Badge } from "~/components/ui/badge"; import { Button } from "~/components/ui/button"; -import { DrivercomCommandButton } from "./DrivercomCommandButton"; import { getConfigFromPort, toggleServo } from "~/services/PortService"; import { createStore, reconcile } from "solid-js/store"; import { toaster } from "~/components/ui/toast"; @@ -37,6 +36,7 @@ type DriverStatusProps = { id: string; driverStatus: StateType; accordionStatuses?: AccordionStates; + portId?: string; }; // Since the Driver status is immutable, It has a seperate components. @@ -95,6 +95,21 @@ export function DriverStatus(props: DriverStatusProps) { setDriverStatus(reconcile(newConfig.state)); } + const isConnected = () => { + if ( + typeof props.portId !== "string" || + (typeof props.portId === "string" && props.portId!.length === 0) + ) { + toaster.create({ + title: "Disconnected Port", + description: "Port is disconnected.", + type: "error", + }); + return false; + } + return true; + }; + return (
- { - if (isToggleButtonLoading()) return; - try { - setIsToggleButtonLoading(true); - await toggleServo(port, driverStatus.servo_enabled); - await refreshStatus(port, version); - setIsToggleButtonLoading(false); - } catch (e) { - setIsToggleButtonLoading(false); - toaster.create({ - title: "Toggle Servo Error", - description: e as string, - type: "error", - }); - } - }} - tooltipContent={"Enable or disable the servo."} - > + - - { - if (isReseting()) return; - try { - setIsReseting(true); - await refreshStatus(port, version); - setIsReseting(false); - } catch (e) { - setIsReseting(false); - toaster.create({ - title: "Refresh Driver status Error", - description: e as string, - type: "error", - }); - } - }} - tooltipContent={"Refresh Driver status"} - > - + + + + { + if (isReseting()) return; + if (!isConnected()) return; + try { + setIsReseting(true); + await refreshStatus(props.portId!); + setIsReseting(false); + } catch (e) { + setIsReseting(false); + toaster.create({ + title: "Refresh Driver status Error", + description: e as string, + type: "error", + }); + } + }} + variant="plain" + size="2xs" + loading={isReseting()} + > - +
- { + - + {"Start"} +
{DriverStatusReactiveTable()}
diff --git a/src/features/configuration/ConfigForm/GetFromPortButton.tsx b/src/features/configuration/ConfigForm/GetFromPortButton.tsx index a5c5bdd1..efb0cc80 100644 --- a/src/features/configuration/ConfigForm/GetFromPortButton.tsx +++ b/src/features/configuration/ConfigForm/GetFromPortButton.tsx @@ -1,18 +1,10 @@ import { IconFileDownload } from "@tabler/icons-solidjs"; import { IconButton } from "~/components/ui/icon-button"; -import { DrivercomCommandButton } from "./DrivercomCommandButton"; -export function GetFromPortButton(props: { - onGetFromPort: (portId: string, version: string) => void; -}) { +export function GetFromPortButton(props: { onGetFromPort: () => void }) { return ( - props.onGetFromPort(port, version)} - > - - - - + + + ); } diff --git a/src/features/configuration/ConfigForm/SaveToPort.tsx b/src/features/configuration/ConfigForm/SaveToPort.tsx index 650c0c58..4106f18f 100644 --- a/src/features/configuration/ConfigForm/SaveToPort.tsx +++ b/src/features/configuration/ConfigForm/SaveToPort.tsx @@ -1,16 +1,10 @@ import { IconSettingsShare } from "@tabler/icons-solidjs"; import { IconButton } from "~/components/ui/icon-button"; -import { DrivercomCommandButton } from "./DrivercomCommandButton"; -export function SaveToPort(props: { onSaveToPort: (portId: string) => void }) { +export function SaveToPort(props: { onSaveToPort: () => void }) { return ( - props.onSaveToPort(port)} - tooltipContent={"Save to port"} - > - - - - + + + ); } diff --git a/src/features/configuration/ConfigTabContent.tsx b/src/features/configuration/ConfigTabContent.tsx index cc606093..cdd83050 100644 --- a/src/features/configuration/ConfigTabContent.tsx +++ b/src/features/configuration/ConfigTabContent.tsx @@ -51,6 +51,7 @@ import { configFormFileFormat, configTabForm, } from "~/stores/config-format"; +import { PortConnectButton } from "~/components/workspace/port-connect-button/PortConnectButton"; export type ConfigTabPage = { filePath?: string; @@ -401,10 +402,10 @@ export function ConfigTabContent() { } }; - const getFromPort = async (portId: string, version: string) => { + const getFromPort = async (portId: string) => { try { setRender(false); - const config = await getConfigFromPort(portId, version); + const config = await getConfigFromPort(portId); setConfigForm(config); setFilePath(""); setTabName(portId); @@ -462,7 +463,7 @@ export function ConfigTabContent() { gap="0" background={"gray.2"} display={"grid"} - gridTemplateColumns={`minmax(0, 1fr) repeat(6, 2rem)`} + gridTemplateColumns={`minmax(0, 1fr) repeat(7, 2rem)`} > + {/*Port Connect Button */} +
+ 0 + } + onPortConnected={(port) => setPortId(port)} + /> +
{/*Get from port */} - await getFromPort(portId, version) - } + onGetFromPort={async () => { + if ( + typeof getPortId() === "undefined" || + (typeof getPortId() === "string" && getPortId()!.length === 0) + ) { + toaster.create({ + title: "Port Connection Error", + description: "Port is not connected", + type: "error", + }); + return; + } + await getFromPort(getPortId()!); + }} /> {/* Save to port */} await saveToPort(portId)} + onSaveToPort={async () => { + if ( + typeof getPortId() === "undefined" || + (typeof getPortId() === "string" && getPortId()!.length === 0) + ) { + toaster.create({ + title: "Port Connection Error", + description: "Port is not connected", + type: "error", + }); + return; + } + await saveToPort(getPortId()!); + }} />
diff --git a/src/features/logging/LoggingForm/LoggingSideBar.tsx b/src/features/logging/LoggingForm/LoggingSideBar.tsx index c959a250..4cf12fb4 100644 --- a/src/features/logging/LoggingForm/LoggingSideBar.tsx +++ b/src/features/logging/LoggingForm/LoggingSideBar.tsx @@ -3,13 +3,14 @@ import { createStore } from "solid-js/store"; import { FormNumberInput } from "~/components/form/FormNumberInput.tsx"; import { LoggingCommandTable } from "./LoggingCommandTable.tsx"; import * as Checkbox from "../../../components/ui/checkbox.tsx"; -import { DrivercomCommandButton } from "~/features/configuration/ConfigForm/DrivercomCommandButton.tsx"; import { For } from "solid-js"; import { Text } from "~/components/ui/text.tsx"; import { css } from "styled-system/css/css"; import { Button } from "~/components/ui/button.tsx"; import { AccordionStates } from "~/features/configuration/ConfigForm/ConfigForm.tsx"; import { HelpTooltip } from "~/components/HelpTooltip.tsx"; +import { PortConnectButton } from "~/components/workspace/port-connect-button/PortConnectButton.tsx"; +import { toaster } from "~/components/ui/toast.tsx"; type LoggingSideBar = { id: string; @@ -19,6 +20,8 @@ type LoggingSideBar = { accordionStates: AccordionStates; loadStartButton?: boolean; description?: object; + portId?: string; + onPortConnect?: (portId: string, version: string) => void; }; export function LoggingSideBar(props: LoggingSideBar) { @@ -143,15 +146,33 @@ export function LoggingSideBar(props: LoggingSideBar) {
- { - props.onStartLogging?.(portId); + 0 + } + onPortConnected={props.onPortConnect} + /> + - + {"Start Logging"} +
diff --git a/src/features/logging/LoggingTabContent.tsx b/src/features/logging/LoggingTabContent.tsx index 6d9182df..76040440 100644 --- a/src/features/logging/LoggingTabContent.tsx +++ b/src/features/logging/LoggingTabContent.tsx @@ -90,6 +90,22 @@ export function LoggingTabContent() { ); }; + const getPort = () => { + return tabStore.get(loggingTabProps.key)![0].tabContext[getTabIndex()] + .tabPage!.loggingTabPage!.portId; + }; + + const setPortId = (newPort: string) => { + return tabStore.get(loggingTabProps.key)![1]( + "tabContext", + getTabIndex(), + "tabPage", + "loggingTabPage", + "portId", + newPort, + ); + }; + const getTabId = () => { return tabStore.get(loggingTabProps.key)![0].tabContext[getTabIndex()].tab .id; @@ -276,6 +292,8 @@ export function LoggingTabContent() { accordionStates={getAccordionStates()} loadStartButton={loadStartLogButton()} description={logConfigDescription()} + portId={getPort()} + onPortConnect={setPortId} onStartLogging={async (portId) => { setLoadStartLogButton(true); try {