forked from Osmantic/ODS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.jsx
More file actions
288 lines (272 loc) · 11.7 KB
/
Copy pathSidebar.jsx
File metadata and controls
288 lines (272 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import { NavLink } from 'react-router-dom'
import { useEffect, useMemo, useState } from 'react'
import {
ChevronLeft,
ChevronRight,
Palette
} from 'lucide-react'
import { getSidebarExternalLinks, getSidebarNavItems } from '../plugins/registry'
import { useTheme } from '../contexts/ThemeContext'
import { fallbackServiceUrl } from '../lib/serviceUrls'
// Derive external service URLs from current host
const getExternalUrl = (port) => fallbackServiceUrl(port)
function OsmanticLogo({ compact = false }) {
return (
<img
className={`osmantic-logo ${compact ? 'osmantic-logo--compact' : ''}`}
src={compact ? '/osmantic-os-icon-192.png' : '/ods-logo.png'}
alt="Osmantic"
draggable="false"
width={compact ? 192 : 760}
height={compact ? 192 : 240}
/>
)
}
export default function Sidebar({ status, collapsed, onToggle }) {
const { theme, cycleTheme, labels } = useTheme() // eslint-disable-line no-unused-vars -- theme switcher temporarily hidden
const [serviceTokens, setServiceTokens] = useState({})
const [apiLinks, setApiLinks] = useState([])
const [showAllQuickLinks, setShowAllQuickLinks] = useState(false)
useEffect(() => {
fetch('/api/service-tokens')
.then(r => r.ok ? r.json() : {})
.then(setServiceTokens)
.catch(() => {})
fetch('/api/external-links')
.then(r => r.ok ? r.json() : [])
.then(setApiLinks)
.catch(() => {})
}, [])
const navItems = useMemo(
() => getSidebarNavItems({ status }),
[status]
)
// Compute external links with auto-auth tokens (e.g. OpenClaw ?token=xxx)
const externalLinks = useMemo(() => {
const links = getSidebarExternalLinks({ status, getExternalUrl, apiLinks })
return links.map(link => {
if (link.key === 'openclaw' && serviceTokens.openclaw) {
return { ...link, url: `${link.url}/?token=${serviceTokens.openclaw}` }
}
return link
})
}, [status, serviceTokens, apiLinks])
const visibleExternalLinks = useMemo(() => {
return showAllQuickLinks
? externalLinks
: externalLinks.filter(link => link.healthy || link.alwaysVisible)
}, [externalLinks, showAllQuickLinks])
// Service counts with degraded nuance
const services = status?.services || []
const deployed = services.filter(s => s.status !== 'not_deployed')
const onlineCount = deployed.filter(s => s.status === 'healthy' || s.status === 'degraded').length
const degradedCount = deployed.filter(s => s.status === 'degraded').length
const totalCount = deployed.length
// Memory bar: use unified (RAM) stats on APUs, VRAM on discrete
const isUnified = status?.gpu?.memoryType === 'unified'
const memPct = isUnified
? (status?.ram?.percent || 0)
: status?.gpu?.vramTotal > 0
? (status.gpu.vramUsed / status.gpu.vramTotal) * 100
: 0
const memUsed = isUnified ? (status?.ram?.used_gb || 0) : (status?.gpu?.vramUsed || 0)
const memTotal = isUnified ? (status?.ram?.total_gb || 0) : (status?.gpu?.vramTotal || 0)
const memLabel = isUnified ? 'Memory' : 'VRAM'
const memFillClass = memPct > 90
? 'liquid-metal-progress-fill liquid-metal-progress-fill--danger'
: memPct > 75
? 'liquid-metal-progress-fill liquid-metal-progress-fill--warn'
: 'liquid-metal-progress-fill'
// Footer status color
const footerColor = degradedCount > 0
? 'text-yellow-500'
: onlineCount === totalCount
? 'text-green-500'
: totalCount > 0
? 'text-yellow-500'
: 'text-theme-text-muted'
return (
<aside
className={`fixed left-0 top-0 flex h-screen flex-col transition-all duration-200 ${collapsed ? 'w-20' : 'w-20 sm:w-64'}`}
style={{
background: `var(--sidebar-bg-glow), var(--sidebar-bg)`,
borderRight: '1px solid var(--sidebar-border)',
boxShadow: 'inset -1px 0 0 rgba(255,255,255,0.04)',
}}
>
{/* Logo */}
<div className="px-4 pt-6 pb-5 border-b overflow-hidden" style={{ borderColor: 'var(--sidebar-border)' }}>
{collapsed ? (
<div className="flex flex-col items-center">
<div className="osmantic-logo-tile">
<OsmanticLogo compact />
</div>
<p className="text-[8px] font-mono mt-2 tracking-[0.18em] uppercase" style={{ color: 'var(--sidebar-text-muted)' }}>
v{status?.version || '...'}
</p>
</div>
) : (
<>
<div className="flex flex-col items-center sm:hidden">
<div className="osmantic-logo-tile">
<OsmanticLogo compact />
</div>
<p className="mt-2 font-mono text-[8px] uppercase tracking-[0.18em]" style={{ color: 'var(--sidebar-text-muted)' }}>
v{status?.version || '...'}
</p>
</div>
<div className="hidden sm:block">
<OsmanticLogo />
<p className="mt-2.5 font-mono text-[8px] uppercase tracking-[0.16em]" style={{ color: 'var(--sidebar-accent-soft)' }}>
OSMANTIC DEPLOYMENT SYSTEM
</p>
<p className="mt-1 text-[10px]" style={{ color: 'var(--sidebar-text-secondary)' }}>
{status?.tier || 'Minimal'} • v{status?.version || '...'}
</p>
</div>
</>
)}
</div>
{/* Navigation */}
<nav className="flex-1 p-4 overflow-y-auto overflow-x-hidden">
<ul className="space-y-1.5">
{navItems.map(({ path, icon: Icon, label }) => (
<li key={path}>
<NavLink
to={path}
end
aria-label={label}
title={label}
className={({ isActive }) =>
`flex items-center ${collapsed ? 'justify-center' : 'justify-center sm:justify-start'} gap-3 px-3 py-2.5 rounded-lg transition-colors ${
isActive
? 'liquid-metal-nav text-white shadow-lg'
: 'text-theme-text-muted hover:text-theme-text'
}`
}
style={({ isActive }) => isActive
? {
border: '1px solid var(--sidebar-active-border)',
boxShadow: 'var(--sidebar-active-shadow)',
}
: {
background: 'transparent',
}
}
>
<Icon size={20} />
{!collapsed && <span className="hidden sm:inline">{label}</span>}
</NavLink>
</li>
))}
</ul>
{/* External Links — hidden when collapsed */}
{!collapsed && (
<div className="mt-4 hidden border-t pt-4 sm:block" style={{ borderColor: 'var(--sidebar-border)' }}>
<div className="mb-2 flex items-center justify-between px-3">
<p className="text-[10px] font-semibold uppercase tracking-[0.24em]" style={{ color: 'var(--sidebar-accent-soft)' }}>
Quick Links
</p>
{externalLinks.length > 0 && (
<button
type="button"
onClick={() => setShowAllQuickLinks(current => !current)}
className="text-[9px] font-mono uppercase tracking-[0.18em] transition-colors hover:text-theme-text"
style={{ color: 'var(--sidebar-accent-soft)' }}
>
{showAllQuickLinks ? 'Show open' : 'View all'}
</button>
)}
</div>
<ul className="space-y-0">
{visibleExternalLinks.map(({ key, url, icon: Icon, label, healthy }) => (
<li key={key}>
<a
href={healthy ? url : undefined}
onClick={(e) => { if (!healthy) e.preventDefault() }}
target={healthy ? '_blank' : undefined}
rel={healthy ? 'noopener noreferrer' : undefined}
className={`flex items-start gap-2.5 px-3 py-1.5 rounded-lg transition-colors ${
healthy
? 'hover:bg-white/[0.03]'
: 'text-theme-text-muted/40 cursor-not-allowed'
}`}
style={healthy ? { color: 'var(--sidebar-text)' } : undefined}
>
<span className="mt-0.5" style={{ color: healthy ? 'var(--sidebar-accent-soft)' : 'var(--sidebar-inactive)' }}>
<Icon size={15} />
</span>
<span className="text-[12px] leading-4">{label}</span>
<span
className="ml-auto text-[9px] font-mono uppercase tracking-[0.18em]"
style={{ color: healthy ? 'var(--sidebar-accent-soft)' : 'var(--sidebar-inactive)' }}
>
{healthy ? 'OPEN' : 'OFFLINE'}
</span>
</a>
</li>
))}
</ul>
</div>
)}
</nav>
{/* Theme + Toggle buttons */}
{/* Theme switcher hidden until Lemonade/Light/Arctic themes are polished for liquid metal design.
To restore: uncomment the Palette button and label below. */}
<div className={`mb-2 flex ${collapsed ? 'mx-2 flex-col items-center gap-2' : 'mx-4 items-center gap-1'}`}>
{/* <button
onClick={cycleTheme}
className="flex items-center justify-center p-2 rounded-lg text-theme-text-muted hover:text-theme-text transition-colors"
title={`Theme: ${labels[theme]} (click to cycle)`}
style={{ background: 'var(--sidebar-hover-bg)' }}
>
<Palette size={18} />
</button>
{!collapsed && (
<span className="text-xs" style={{ color: 'var(--sidebar-label)' }}>{labels[theme]}</span>
)} */}
<button
onClick={onToggle}
className={`${collapsed ? '' : 'ml-auto'} hidden items-center justify-center rounded-lg p-2 text-theme-text-muted transition-colors hover:text-theme-text sm:flex`}
title={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
style={{ background: 'var(--sidebar-hover-bg)' }}
>
{collapsed ? <ChevronRight size={18} /> : <ChevronLeft size={18} />}
</button>
</div>
{/* Status Footer */}
<div className="p-4 border-t" style={{ borderColor: 'var(--sidebar-border)' }}>
{!collapsed && (
<div className="mb-2 hidden items-center justify-between text-sm sm:flex">
<span className="text-theme-text-muted">Services</span>
<span className={footerColor}>
{degradedCount > 0
? `Online: ${onlineCount}/${totalCount} · ${degradedCount} degraded`
: `Online: ${onlineCount}/${totalCount}`
}
</span>
</div>
)}
{(status?.gpu || (isUnified && status?.ram)) && (
<div>
{!collapsed && (
<div className="mb-1 hidden items-center justify-between text-xs text-theme-text-muted sm:flex">
<span>{memLabel}</span>
<span className="font-mono">{memUsed.toFixed ? memUsed.toFixed(1) : memUsed}/{memTotal.toFixed ? memTotal.toFixed(0) : memTotal} GB</span>
</div>
)}
<div
className="liquid-metal-progress-track h-1.5 rounded-full overflow-hidden"
title={collapsed ? `${memLabel}: ${memUsed.toFixed ? memUsed.toFixed(1) : memUsed}/${memTotal.toFixed ? memTotal.toFixed(0) : memTotal} GB` : undefined}
>
<div
className={`h-full rounded-full transition-all ${memFillClass}`}
style={{ width: `${Math.min(memPct, 100)}%` }}
/>
</div>
</div>
)}
</div>
</aside>
)
}