diff --git a/src/client/views/settings/VRM.tsx b/src/client/views/settings/VRM.tsx index 6e7c3fe..42e53fd 100644 --- a/src/client/views/settings/VRM.tsx +++ b/src/client/views/settings/VRM.tsx @@ -17,6 +17,8 @@ import { CNavLink, CTabPane, CTabContent, + CCol, + CRow, } from "@coreui/react" import { useGetConfig, usePutConfig, useVRMLogin, useVRMLogout, useVRMRefresh } from "../../hooks/useAdminApi" @@ -24,9 +26,10 @@ import { useFormValidation, extractParameterNameAndValue } from "../../hooks/use import { DeviceList } from "./DeviceList" import { AppConfig, AppVRMConfig, AppVRMConfigKey } from "../../../shared/types" import { AppState } from "../../store" -import { VRMLoginMethod, VRMLoginRequest } from "../../../shared/api" +import { VRMDeviceType, VRMLoginMethod, VRMLoginRequest } from "../../../shared/api" import { VRMStatus } from "../../../shared/state" import { WebSocketStatus } from "./WebsocketStatus" +import { EditableHostList } from "./EditableDeviceList" function VRM() { const [{ data: config, loading: _isLoading, error: _loadError }, loadConfig, _cancelLoadConfig] = useGetConfig() @@ -55,7 +58,9 @@ function VRM() { ] = useVRMRefresh() const isSaveEnabled = useFormValidation(() => { - return temporaryConfig !== undefined + return ( + temporaryConfig !== undefined && temporaryConfig.vrm.manualPortalIds.filter((x) => x.portalId === "").length === 0 + ) }) function handleEnableChange(event: React.ChangeEvent) { @@ -136,7 +141,43 @@ function VRM() { }) } + function handleAddPortal(_event: React.MouseEvent) { + const clone = { ...temporaryConfig!! } + clone.vrm.manualPortalIds.push({ portalId: "", enabled: true }) + setTemporaryConfig(clone) + } + + function handleDeletePortal( + _event: React.MouseEvent, + index: number, + ) { + const clone = { ...temporaryConfig!! } + clone.vrm.manualPortalIds.splice(index, 1) + setTemporaryConfig(clone) + } + + function handlePortalIdChange(event: React.ChangeEvent, index: number) { + const clone = { ...temporaryConfig!! } + clone.vrm.manualPortalIds[index].portalId = event.target.value + setTemporaryConfig(clone) + } + + function handleEnableHostChange(event: React.ChangeEvent, index: number) { + const clone = { ...temporaryConfig!! } + clone.vrm.manualPortalIds[index].enabled = event.target.checked + setTemporaryConfig(clone) + } + + function handleEnableAllHostsChange(event: React.ChangeEvent) { + const clone = { ...temporaryConfig!! } + clone.vrm.manualPortalIds = clone.vrm.manualPortalIds.map((element) => { + return { portalId: element.portalId, enabled: event.target.checked } + }) + setTemporaryConfig(clone) + } + const [loginMethod, setLoginMethod] = useState("credentials") + const [displayedDevices, setDisplayedDevices] = useState("discovered") const [showStatusPane, setShowStatusPane] = useState(false) const websocketStatus = useSelector((state: AppState) => state.websocketStatus) @@ -199,37 +240,88 @@ function VRM() { vrmStatus={vrmStatus} loginMethod={loginMethod} /> - handleVRMRefresh()} - hidden={!temporaryConfig.vrm.hasToken} - disabled={isVRMRefreshInProgress} - > - {isVRMRefreshInProgress ? "Working..." : "Refresh"} - {" "} - handleVRMLogout()} - hidden={!temporaryConfig.vrm.hasToken} - disabled={!temporaryConfig.vrm.hasToken} - > - {isVRMLogoutInProgress ? "Working..." : "Logout"} - -