diff --git a/package.json b/package.json index 2e618fc6..dce0d36d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "0.25.6", + "version": "0.25.7", "private": true, "scripts": { "dev": "react-scripts start", diff --git a/src/components/Connections/Connections.tsx b/src/components/Connections/Connections.tsx index b47b5576..163dbefb 100644 --- a/src/components/Connections/Connections.tsx +++ b/src/components/Connections/Connections.tsx @@ -54,7 +54,7 @@ export default function Connections(): ReactElement { /> { }); } + async function getPhysicalInstance( + values: IgetPhysicalInstance, + parameters?: ImultipleGetParameters, + ) { + await dispatch( + getAllPhysicalInstances({ + organizationId: values?.organizationId, + roboticsCloudName: values?.roboticsCloudName, + instanceId: values?.instanceId, + region: values?.region, + }), + ).then((responsePhysicalInstances: any) => { + if ( + responsePhysicalInstances?.payload?.data?.[0]?.roboticsClouds?.[0] + ?.cloudInstances?.[0]?.robolaunchPhysicalInstances + ) { + parameters?.setResponse && + parameters?.setResponse( + responsePhysicalInstances?.payload?.data[0]?.roboticsClouds[0]?.cloudInstances[0]?.robolaunchPhysicalInstances?.find( + (physicalInstance: any) => + physicalInstance?.name === values?.physicalInstanceName, + ) || {}, + ); + } else { + parameters?.ifErrorNavigateTo404 && navigateTo404(); + parameters?.setResponse && parameters?.setResponse({}); + } + }); + } + async function getInstance( values: IgetInstance, parameters?: IsingleGetParameters, @@ -1327,6 +1358,7 @@ export default ({ children }: any) => { getRoboticsCloud, getInstances, getPhysicalInstances, + getPhysicalInstance, getInstance, getFleets, getFleet, diff --git a/src/contexts/RobotContext.tsx b/src/contexts/RobotContext.tsx index c8cfd0e3..c6b5c95e 100644 --- a/src/contexts/RobotContext.tsx +++ b/src/contexts/RobotContext.tsx @@ -1,12 +1,10 @@ import { useEffect, createContext, useState, useReducer } from "react"; import { IrobotTab } from "../interfaces/robotInterfaces"; -import { envApplication, isProduction } from "../helpers/envProvider"; +import { envApplication } from "../helpers/envProvider"; import useFunctions from "../hooks/useFunctions"; import { useParams } from "react-router-dom"; import useMain from "../hooks/useMain"; import ROSLIB from "roslib"; -import { AxiosResponse } from "axios"; -import axiosInterceptorOpenApi from "../middlewares/axios.interceptor.openapi"; export const RobotContext: any = createContext(null); @@ -16,6 +14,7 @@ export default ({ children }: any) => { getOrganization, getRoboticsCloud, getInstance, + getPhysicalInstance, getFleet, getNamespace, getRobot, @@ -30,6 +29,8 @@ export default ({ children }: any) => { const [activeTab, setActiveTab] = useState("Overview"); + const [responsePhysicalInstance, setResponsePhysicalInstance] = + useState(undefined); const [responseRobot, setResponseRobot] = useState(undefined); const [responseBuildManager, setResponseBuildManager] = useState(undefined); @@ -98,6 +99,8 @@ export default ({ children }: any) => { !envApplication && handleGetBuildManager(); } else if (!responseLaunchManagers) { !envApplication && handleGetLaunchManagers(); + } else if (responseRobot?.physicalInstance && !responsePhysicalInstance) { + handleGetPhysicalInstance(); } const timerResponseRobot = setInterval(() => { @@ -286,7 +289,7 @@ export default ({ children }: any) => { } // ROS Topic Setter - // VDI Test Connection + // VDI - vIDE Test Connection useEffect(() => { const vdiClient: WebSocket | null = isSettedCookie && connectionsReducer?.vdi === null @@ -294,17 +297,21 @@ export default ({ children }: any) => { : null; vdiClient?.addEventListener("open", () => { - dispatcher({ - type: "vdi", - payload: true, - }); + ["vdi", "virtualIDE"].map((connection) => + dispatcher({ + type: connection, + payload: true, + }), + ); }); vdiClient?.addEventListener("error", () => { - dispatcher({ - type: "vdi", - payload: false, - }); + ["vdi", "virtualIDE"].map((connection) => + dispatcher({ + type: connection, + payload: false, + }), + ); }); connectionsReducer?.vdi !== null && vdiClient && vdiClient.close(); @@ -314,37 +321,30 @@ export default ({ children }: any) => { }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [isSettedCookie, connectionsReducer?.vdi]); - // VDI Test Connection + // VDI - vIDE Test Connection - // V-IDE Test Connection + // Physical IDE Test Connection useEffect(() => { - try { - if (isSettedCookie && isProduction) { - axiosInterceptorOpenApi - .get(responseRobot?.ideIngressEndpoint + "healthz") - .then((response: AxiosResponse) => { - console.log(response.data); - dispatcher({ - type: "virtualIDE", - payload: true, - }); - }); + if (isSettedCookie && typeof connectionsReducer?.vdi === "boolean") { + if ( + connectionsReducer?.vdi && + responsePhysicalInstance?.federationPhase === "Connected" && + responsePhysicalInstance?.multicastPhase === "Connected" && + responsePhysicalInstance?.phase === "Connected" + ) { + dispatcher({ + type: "physicalIDE", + payload: true, + }); } else { dispatcher({ - type: "virtualIDE", + type: "physicalIDE", payload: false, }); } - } catch (error) { - dispatcher({ - type: "virtualIDE", - payload: false, - }); } - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isSettedCookie]); - // V-IDE Test Connection + }, [responsePhysicalInstance, isSettedCookie, connectionsReducer?.vdi]); + // Physical IDE Test Connection function handleGetOrganization() { getOrganization( @@ -390,6 +390,22 @@ export default ({ children }: any) => { ); } + function handleGetPhysicalInstance() { + getPhysicalInstance( + { + organizationId: pagesState?.organization?.organizationId!, + roboticsCloudName: pagesState?.roboticsCloud?.name!, + instanceId: pagesState?.instance?.instanceId!, + physicalInstanceName: responseRobot?.physicalInstance, + region: pagesState?.roboticsCloud?.region!, + }, + { + ifErrorNavigateTo404: false, + setResponse: setResponsePhysicalInstance, + }, + ); + } + function handleGetFleet() { getFleet( { @@ -519,6 +535,7 @@ export default ({ children }: any) => { value={{ activeTab, setActiveTab, + responsePhysicalInstance, responseRobot, responseBuildManager, responseLaunchManagers, diff --git a/src/hooks/useRobot.tsx b/src/hooks/useRobot.tsx index 2695de1b..97d3aeac 100644 --- a/src/hooks/useRobot.tsx +++ b/src/hooks/useRobot.tsx @@ -4,6 +4,7 @@ import { useContext } from "react"; interface IuseRobot { activeTab: string; setActiveTab: any; + responsePhysicalInstance: any; responseRobot: any; responseBuildManager: any; responseLaunchManagers: any; diff --git a/src/interfaces/useFunctionsInterfaces.ts b/src/interfaces/useFunctionsInterfaces.ts index b897ff50..500170a5 100644 --- a/src/interfaces/useFunctionsInterfaces.ts +++ b/src/interfaces/useFunctionsInterfaces.ts @@ -43,6 +43,14 @@ export interface IgetPhysicalInstances { region: string; } +export interface IgetPhysicalInstance { + organizationId: string; + roboticsCloudName: string; + instanceId: string; + physicalInstanceName: string; + region: string; +} + export interface IgetInstance { organizationId: string; roboticsCloudName: string; @@ -171,6 +179,10 @@ export interface IuseFunctions { values: IgetPhysicalInstances, parameters?: ImultipleGetParameters, ) => void; + getPhysicalInstance: ( + values: IgetPhysicalInstance, + parameters?: IsingleGetParameters, + ) => void; getInstance: ( values: IgetInstance, parameters?: IsingleGetParameters,