Skip to content

Commit

Permalink
feat(version): release 0.25.2 version
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhangunduz committed Dec 21, 2023
1 parent e0f3c43 commit 19cea0b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ui",
"version": "0.25.1",
"version": "0.25.2",
"private": true,
"scripts": {
"dev": "react-scripts start",
Expand Down
21 changes: 12 additions & 9 deletions src/components/Connections/Connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ import StateCell from "../TableInformationCells/StateCell";
import { envApplication } from "../../helpers/envProvider";
import { useKeycloak } from "@react-keycloak/web";
import useRobot from "../../hooks/useRobot";
import { ReactElement } from "react";
import { ReactElement, useEffect } from "react";

export default function Connections(): ReactElement {
const { responseRobot, isSettedCookie, isRosConnected, isVDIConnected } =
useRobot();
const { responseRobot, isSettedCookie, connectionsReducer } = useRobot();
const { keycloak } = useKeycloak();

useEffect(() => {
console.log("connectionsReducer", connectionsReducer);
}, [connectionsReducer]);

return (
<div className="flex gap-4">
{!envApplication && (
<div className="flex gap-1" id="ros">
<ConnectionLabel label="ROS" />
<StateCell
state={
isRosConnected === null
connectionsReducer?.ros === null
? "Waiting"
: isRosConnected === true
: connectionsReducer?.ros === true
? "Connected"
: "Warning"
}
Expand All @@ -35,9 +38,9 @@ export default function Connections(): ReactElement {
/>
<StateCell
state={
isVDIConnected === null
connectionsReducer?.vdi === null
? "Waiting"
: isVDIConnected
: connectionsReducer?.vdi
? "Connected"
: "Warning"
}
Expand Down Expand Up @@ -72,9 +75,9 @@ export default function Connections(): ReactElement {
/>
<StateCell
state={
isVDIConnected === null
connectionsReducer?.vdi === null
? "Waiting"
: isVDIConnected
: connectionsReducer?.vdi
? "Connected"
: "Warning"
}
Expand Down
81 changes: 56 additions & 25 deletions src/contexts/RobotContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, createContext, useState } from "react";
import { useEffect, createContext, useState, useReducer } from "react";
import { IrobotTab } from "../interfaces/robotInterfaces";
import { envApplication } from "../helpers/envProvider";
import useFunctions from "../hooks/useFunctions";
Expand Down Expand Up @@ -42,9 +42,40 @@ export default ({ children }: any) => {

const [ros, setRos] = useState<ROSLIB.Ros | null>(null);
const [topicList, setTopicList] = useState<any>([]);
const [isRosConnected, setIsRosConnected] = useState<boolean | null>(null);

const [isVDIConnected, setIsVDIConnected] = useState<boolean | null>(null);
const [connectionsReducer, dispatcher] = useReducer(handleReducer, {
ros: null,
virtualIDE: null,
physicalIDE: null,
vdi: null,
});

function handleReducer(state: any, action: any) {
switch (action.type) {
case "ros":
return {
...state,
ros: action.payload,
};
case "virtualIDE":
return {
...state,
virtualIDE: action.payload,
};
case "physicalIDE":
return {
...state,
physicalIDE: action.payload,
};
case "vdi":
return {
...state,
vdi: action.payload,
};
default:
return state;
}
}

// Main Functions
useEffect(() => {
Expand Down Expand Up @@ -192,13 +223,16 @@ export default ({ children }: any) => {
setRos(ros);

rosClient?.on("connection", function () {
isRosConnected === null && setIsRosConnected(true);
connectionsReducer?.ros === null &&
dispatcher({ type: "ros", payload: true });
});
rosClient?.on("error", function (error) {
isRosConnected === null && setIsRosConnected(false);
connectionsReducer?.ros === null &&
dispatcher({ type: "ros", payload: false });
});
rosClient?.on("close", function () {
isRosConnected === null && setIsRosConnected(false);
connectionsReducer?.ros === null &&
dispatcher({ type: "ros", payload: false });
});

return () => {
Expand Down Expand Up @@ -252,37 +286,37 @@ export default ({ children }: any) => {

// VDI Test Connection
useEffect(() => {
const vdiClient =
isSettedCookie && isVDIConnected === null
const vdiClient: WebSocket | null =
isSettedCookie && connectionsReducer?.vdi === null
? new WebSocket(responseRobot?.vdiIngressEndpoint + "ws?password=admin")
: null;

vdiClient?.addEventListener("open", () => {
if (isVDIConnected === null) {
setIsVDIConnected(true);
vdiClient?.close();
}
dispatcher({
type: "vdi",
payload: true,
});
});

vdiClient?.addEventListener("error", () => {
if (isVDIConnected === null) {
setIsVDIConnected(false);
vdiClient?.close();
}
dispatcher({
type: "vdi",
payload: false,
});
});

vdiClient?.addEventListener("close", () => {
if (isVDIConnected === null) {
setIsVDIConnected(false);
vdiClient?.close();
}
dispatcher({
type: "vdi",
payload: false,
});
});

return () => {
vdiClient?.close();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSettedCookie, isVDIConnected]);
}, [isSettedCookie, connectionsReducer?.vdi]);
// VDI Test Connection

function handleGetOrganization() {
Expand Down Expand Up @@ -468,10 +502,7 @@ export default ({ children }: any) => {
topicList,
isSettedCookie,
setIsSettedCookie,
isRosConnected,
setIsRosConnected,
isVDIConnected,
setIsVDIConnected,
connectionsReducer,
setTopicList,
handleForceUpdate,
handleResetRobot,
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/useRobot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ interface IuseRobot {
setTopicList: any;
isSettedCookie: boolean | null;
setIsSettedCookie: any;
isRosConnected: boolean | null;
setIsRosConnected: any;
isVDIConnected: boolean | null;
setIsVDIConnected: any;
connectionsReducer: any;
handleForceUpdate: any;
handleResetRobot: () => void;
}
Expand Down

0 comments on commit 19cea0b

Please sign in to comment.