Skip to content

Commit

Permalink
refactor(robot-header): 🎉 update robot header with services component
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhangunduz committed Aug 16, 2023
1 parent f1d75f7 commit 5ae2f82
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 53 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.12.5",
"version": "0.12.6",
"private": true,
"dependencies": {
"@emotion/css": "^11.10.6",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface ButtonProps {
type?: "button" | "submit" | "reset";
text: any;
onClick?: () => void;
loading?: boolean;
loading?: boolean | null;
disabled?: boolean;
className?: string;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Cells/StateCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default function StateCell({ state, isRobolaunchState }: IStateCell) {
state === "WaitingForCredentials" ||
state === "ConfiguringEnvironment" ||
state === "CreatingDevelopmentSuite" ||
state === "ConfiguringWorkspaces" ||
state === "BuildingRobot" ? (
<img
className="w-2.5 h-2.5 scale-[3.4]"
Expand Down
34 changes: 2 additions & 32 deletions src/components/RobotHeader/RobotHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { IoLocationOutline } from "react-icons/io5";
import { AiOutlineTeam } from "react-icons/ai";
import CardLayout from "../../layouts/CardLayout";
import ContentLoader from "react-content-loader";
import Button from "../Button/Button";
import RobotResource from "../RobotResource/RobotResource";
import RobotConnectionsViewer from "../RobotConnectionsViewer/RobotConnectionsViewer";
import { envOnPremise } from "../../helpers/envProvider";
import RobotHeaderTabs from "../RobotHeaderTabs/RobotHeaderTabs";
import useRobot from "../../hooks/useRobot";
import RobotServiceButtons from "../RobotServiceButtons/RobotServiceButtons";

interface IRobotHeader {
handleChangeActiveTab: any;
Expand All @@ -29,7 +29,6 @@ export default function RobotHeader({
<div className="h-full flex flex-col justify-around">
<div className="flex gap-2 items-center">
<span className="text-lg font-medium">{url?.robotName}</span>

<div
className={`text-[0.64rem] capitalize font-medium px-3 py-1 rounded-lg w-fit text-layer-primary-500 bg-layer-primary-100`}
>
Expand All @@ -55,43 +54,14 @@ export default function RobotHeader({
{url?.organizationName} Organization
</span>
</span>

<span className="flex gap-2 items-center">
<IoLocationOutline size={16} />
<span className="text-xs font-light">Ankara, Turkiye</span>
</span>
</div>

<div className="hidden md:flex text-xs font-medium text-layer-dark-400 gap-8">
<div className="h-full flex flex-col items-end gap-4">
<div className="flex gap-2">
<div className="flex items-center rounded-lg">
<a
target="_blank"
rel="noreferrer"
href={responseRobot?.ideIngressEndpoint}
>
<Button
text={"Code Editor"}
className="!h-9 text-xs px-4"
/>
</a>
</div>
<div className="flex items-center rounded-lg p-2">
<a
target="_blank"
rel="noreferrer"
href={`https://${
responseRobot?.vdiIngressEndpoint?.split("//")[1]
}`}
>
<Button
text={"Remote Desktop"}
className="!h-9 text-xs px-4"
/>
</a>
</div>
</div>
<RobotServiceButtons />
<RobotConnectionsViewer
ide={isSettedCookie}
vdiURL={responseRobot?.vdiIngressEndpoint}
Expand Down
44 changes: 44 additions & 0 deletions src/components/RobotServiceButtons/RobotServiceButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { ReactElement } from "react";
import useRobot from "../../hooks/useRobot";
import Button from "../Button/Button";

export default function RobotServiceButtons(): ReactElement {
const { responseRobot, isSettedCookie } = useRobot();

return (
<div className="flex gap-2">
<div className="flex items-center rounded-lg">
<a
target="_blank"
rel="noreferrer"
href={responseRobot?.ideIngressEndpoint || "#"}
>
<Button
disabled={!isSettedCookie}
loading={!isSettedCookie}
text={"Code Editor"}
className="!h-9 text-xs px-4"
/>
</a>
</div>
<div className="flex items-center rounded-lg p-2">
<a
target="_blank"
rel="noreferrer"
href={
responseRobot?.vdiIngressEndpoint
? `https://${responseRobot?.vdiIngressEndpoint?.split("//")[1]}`
: "#"
}
>
<Button
disabled={!isSettedCookie}
loading={!isSettedCookie}
text={"Remote Desktop"}
className="!h-9 text-xs px-4"
/>
</a>
</div>
</div>
);
}
25 changes: 13 additions & 12 deletions src/components/VersionViewer/VersionViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import React from "react";
import React, { ReactElement } from "react";
import packageJSON from "../../../package.json";
import { envFrontendUrl, isProduction } from "../../helpers/envProvider";

export default function VersionViewer(): ReactElement {
const developmentURL = `http://localhost:3000${
window.location.href?.split("robolaunch.cloud")[1] || ""
}`;

const productionURL = `${envFrontendUrl}${
window.location.href?.split("3000")[1] || ""
}`;

export default function VersionViewer() {
return (
<div
onClick={() => {
if (process.env.NODE_ENV === "development") {
window.location.href = `${process.env.REACT_APP_FRONTEND_URL}${
window.location.href?.split("3000")[1] || ""
}`;
} else if (process.env.NODE_ENV === "production") {
window.location.href = `http://localhost:3000${
window.location.href?.split("robolaunch.cloud")[1] || ""
}`;
}
window.location.href = isProduction ? developmentURL : productionURL;
}}
className="fixed bottom-0 right-1 z-50 text-[0.64rem] text-layer-light-700 cursor-crosshair"
>
{process.env.NODE_ENV === "production" ? "P" : "D"} {packageJSON?.version}
{isProduction ? "P" : "D"} {packageJSON?.version}
</div>
);
}
5 changes: 5 additions & 0 deletions src/helpers/envProvider.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export const envOnPremise: boolean =
process.env.REACT_APP_ON_PREMISE === "true" ? true : false;

export const envFrontendUrl: string = process.env.REACT_APP_FRONTEND_URL || "";

export const isProduction: boolean =
process.env.NODE_ENV === "production" ? true : false;
20 changes: 20 additions & 0 deletions src/pages/RobotPage/Overview/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,32 @@ export default function Overview({
component={
envOnPremise ? (
<Button
disabled={
responseRobot?.robotClusters?.filter(
(robot: any) => robot?.robotStatus !== "EnvironmentReady"
)?.length
}
loading={
responseRobot?.robotClusters?.filter(
(robot: any) => robot?.robotStatus !== "EnvironmentReady"
)?.length
}
text="Development Suite"
className="!w-44 !h-10 !text-xs"
onClick={informationWidgetAction}
/>
) : (
<Button
disabled={
responseRobot?.robotClusters?.filter(
(robot: any) => robot?.robotStatus !== "EnvironmentReady"
)?.length
}
loading={
responseRobot?.robotClusters?.filter(
(robot: any) => robot?.robotStatus !== "EnvironmentReady"
)?.length
}
text="Teleoperation of Robot"
className="!w-44 !h-10 !text-xs"
onClick={informationWidgetAction}
Expand Down
9 changes: 5 additions & 4 deletions src/pages/RobotPage/RobotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Overview from "./Overview/Overview";
import HiddenFrame from "../../components/HiddenFrame/HiddenFrame";

export default function RobotPage(): ReactElement {
const { activeTab, setActiveTab, responseRobot } = useRobot();
const { activeTab, setActiveTab, responseRobot, isSettedCookie } = useRobot();

const { urls } = useAppSelector((state) => state.robot);

Expand All @@ -38,9 +38,10 @@ export default function RobotPage(): ReactElement {
return (
<Overview
informationWidgetAction={() => {
setActiveTab(
envOnPremise ? "Development Suite" : "Teleoperation"
);
isSettedCookie &&
setActiveTab(
envOnPremise ? "Development Suite" : "Teleoperation"
);
}}
/>
);
Expand Down
7 changes: 4 additions & 3 deletions src/toolkit/RobotSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
IdeleteLaunchManagerRequest,
IdeleteRobotRequest,
} from "../interfaces/robotInterfaces";
import { isProduction } from "../helpers/envProvider";

export const createRobot = createAsyncThunk(
"robot/createFederatedRobot",
Expand Down Expand Up @@ -371,9 +372,9 @@ export const RobotSlice = createSlice({
name: "robot",
initialState: {
urls: {
vdi: process.env.NODE_ENV === "production" ? "" : "",
ide: process.env.NODE_ENV === "production" ? "" : "",
ros: process.env.NODE_ENV === "production" ? "" : "",
vdi: isProduction ? "" : "",
ide: isProduction ? "" : "",
ros: isProduction ? "" : "",
},
},
reducers: {
Expand Down

0 comments on commit 5ae2f82

Please sign in to comment.