Skip to content

Commit 0086614

Browse files
committed
Add status bar components
1 parent 02bc8ae commit 0086614

File tree

5 files changed

+135
-4
lines changed

5 files changed

+135
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jderobot-ide-interface",
3-
"version": "0.1.36",
3+
"version": "0.1.37",
44
"main": "dist/main.js",
55
"typings": "dist/index.d.ts",
66
"files": [

src/components/StatusBar/StatusBar.tsx

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ const StatusBar = ({
9494
<label>{state}</label>
9595
</StyledStatusBarEntry>
9696
{extraComponents.universeSelector ? (
97-
<>{extraComponents.universeSelector}</>
97+
<StatusBarCustomUniverseSelector
98+
project={project}
99+
commsManager={commsManager}
100+
api={api}
101+
components={extraComponents}
102+
/>
98103
) : (
99104
<DefaultUniverseSelector
100105
project={project}
@@ -235,3 +240,128 @@ const DefaultUniverseSelector = ({
235240
</DropdownStatusBar>
236241
);
237242
};
243+
244+
export const StatusBarCustomUniverseSelector = ({
245+
project,
246+
commsManager,
247+
api,
248+
components,
249+
}: {
250+
project: string;
251+
commsManager: CommsManager | null;
252+
api: ExtraApi;
253+
components: any;
254+
}) => {
255+
const theme = useTheme();
256+
const [open, setOpen] = useState<boolean>(false);
257+
const { warning, error } = useError();
258+
const [universe, setUniverse] = useState<string | undefined>(
259+
commsManager?.getUniverse(),
260+
);
261+
262+
useEffect(() => {
263+
if (commsManager) {
264+
console.log("Change Universe", commsManager.getUniverse());
265+
setUniverse(commsManager.getUniverse());
266+
}
267+
}, [commsManager?.getUniverse()]);
268+
269+
const terminateUniverse = async () => {
270+
if (!commsManager) {
271+
warning(
272+
"Failed to connect with the Robotics Backend docker. Please make sure it is connected.",
273+
);
274+
return;
275+
}
276+
// Down the RB ladder
277+
await commsManager.terminateApplication();
278+
await commsManager.terminateTools();
279+
await commsManager.terminateUniverse();
280+
};
281+
282+
const launchUniverse = async (universe: string) => {
283+
if (!commsManager) {
284+
warning(
285+
"Failed to connect with the Robotics Backend docker. Please make sure it is connected.",
286+
);
287+
return;
288+
}
289+
290+
if (project === "") {
291+
error("Failed to find the current project name.");
292+
return;
293+
}
294+
295+
try {
296+
const universeConfig = await api.universes.get_config(project, universe);
297+
298+
var tools = universeConfig.tools;
299+
300+
if (!tools.includes("state_monitor")) {
301+
tools.push("state_monitor");
302+
}
303+
304+
const world_config = universeConfig.world;
305+
306+
const robot_config = universeConfig.robot;
307+
308+
const universe_config = {
309+
name: universe,
310+
world: world_config,
311+
robot: robot_config,
312+
};
313+
314+
await commsManager.launchWorld(universe_config);
315+
console.log("RB universe launched!");
316+
// TODO: update to tools
317+
await commsManager.prepareTools(tools, universeConfig.tools_config);
318+
console.log("Viz ready!");
319+
} catch (e: unknown) {
320+
throw e; // rethrow
321+
}
322+
};
323+
324+
const selectUniverse = async (universeName: string) => {
325+
console.log(universeName);
326+
327+
if (!universeName) return;
328+
329+
try {
330+
// Launch if new universe selected
331+
if (universeName !== universe) {
332+
if (universe) await api.universes.list(project);
333+
if (universe) await terminateUniverse();
334+
await launchUniverse(universeName);
335+
console.log("Launch universe successful");
336+
}
337+
} catch (e: unknown) {
338+
if (e instanceof Error) {
339+
console.error("Unable to retrieve universe config: " + e.message);
340+
error("Unable to retrieve universe config: " + e.message);
341+
}
342+
}
343+
};
344+
345+
return (
346+
<div>
347+
<StyledStatusBarEntry
348+
id="universe-selector"
349+
title="Universe selector"
350+
onClick={() => setOpen(true)}
351+
text={theme.palette.text}
352+
>
353+
<label>
354+
{universe ? `Universe: ${universe}` : "Click to select universe"}
355+
</label>
356+
</StyledStatusBarEntry>
357+
{open && (
358+
<components.universeSelector
359+
isOpen={open}
360+
onSelect={selectUniverse}
361+
onClose={() => setOpen(false)}
362+
project={project}
363+
/>
364+
)}
365+
</div>
366+
);
367+
};

src/components/StatusBar/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default as StatusBar } from "./StatusBar";
1+
export { default as StatusBar, StatusBarCustomUniverseSelector } from "./StatusBar";

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IdeInterface } from "./components";
22
export default IdeInterface;
33

44
export { VncViewer } from "./components";
5+
export { StatusBarCustomUniverseSelector } from "./components";
56
export { ProgressBar } from "./components";
67
export {
78
Button,

src/types/fileTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ export interface EditorsEntry {
7878
export type Layout = "only-editor" | "only-viewers" | "both";
7979

8080
export interface StatusBarComponents {
81-
universeSelector?: JSX.Element;
81+
universeSelector?: string;
8282
extras: JSX.Element[];
8383
}

0 commit comments

Comments
 (0)