EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
TabTerminal_NEW.jsx
Go to the documentation of this file.
1import React from 'react';
2import MeshCentralEmbed, { VIEWMODE } from '../../components/MeshCentralEmbed';
3import { apiFetch } from '../../lib/api';
4
5export default function TabTerminal({ agentId, agentUuid }) {
6 const [nodeId, setNodeId] = React.useState(null);
7 const [loading, setLoading] = React.useState(true);
8 const [error, setError] = React.useState(null);
9
10 React.useEffect(() => {
11 async function loadNodeId() {
12 setLoading(true);
13 setError(null);
14
15 try {
16 const response = await apiFetch(`/agent/${agentUuid || agentId}/meshcentral-url`);
17
18 if (!response.ok) {
19 const errorData = await response.json();
20 throw new Error(errorData.error || 'Failed to get MeshCentral connection');
21 }
22
23 const data = await response.json();
24 setNodeId(data.meshcentralNodeId);
25
26 } catch (err) {
27 console.error('[TabTerminal] Failed to load node ID:', err);
28 setError(err.message);
29 } finally {
30 setLoading(false);
31 }
32 }
33
34 if (agentUuid || agentId) {
35 loadNodeId();
36 }
37 }, [agentUuid, agentId]);
38
39 if (loading) {
40 return (
41 <div className="tab-container">
42 <div style={{ textAlign: 'center', padding: '3rem' }}>
43 <div className="spinner" style={{ margin: '0 auto 1rem' }}></div>
44 <p>Loading terminal...</p>
45 </div>
46 </div>
47 );
48 }
49
50 if (error) {
51 return (
52 <div className="tab-container">
53 <div className="card" style={{ textAlign: 'center', padding: '2rem' }}>
54 <div style={{ fontSize: '3rem', marginBottom: '1rem' }}>⚠️</div>
55 <h3>Connection Error</h3>
56 <p style={{ color: '#d32f2f' }}>{error}</p>
57 </div>
58 </div>
59 );
60 }
61
62 return (
63 <div className="tab-container" style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
64 <MeshCentralEmbed
65 nodeId={nodeId}
66 viewMode={VIEWMODE.TERMINAL}
67 title="Terminal"
68 />
69 </div>
70 );
71}