forked from forthfate/openorbit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-shell.tsx
More file actions
211 lines (209 loc) · 5.93 KB
/
Copy pathapp-shell.tsx
File metadata and controls
211 lines (209 loc) · 5.93 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
import {
Activity,
BarChart3,
BookOpen,
Boxes,
Braces,
FileCode2,
PanelLeftClose,
Play,
Settings,
Sparkles,
} from "lucide-react";
import { SiGithub } from "react-icons/si";
import { useEffect, useState, type ReactNode } from "react";
import type { Page } from "../domain/models";
import type { Locale } from "../locales";
import { localeMessages, locales } from "../locales";
import { ChatAssistant } from "../components/chat-assistant";
const sidebarStorageKey = "orbit.sidebar.collapsed";
export function AppShell({
page,
setPage,
locale,
theme,
headerAction,
activeRunCount = 0,
children,
}: {
page: Page;
setPage: (page: Page) => void;
locale: Locale;
theme: string;
headerAction?: ReactNode;
activeRunCount?: number;
children: ReactNode;
}) {
const t = locales[locale];
const [collapsed, setCollapsed] = useState(
() => localStorage.getItem(sidebarStorageKey) === "true",
);
const pageDescriptions = localeMessages<Record<Page, string>>(
locale,
"shell",
);
const appMeta = localeMessages<{ title: string; titleSeparator: string }>(
locale,
"appMeta",
);
const dashboardLinks = localeMessages<{
repository: string;
releases: string;
openApi: string;
sdkDocs: string;
}>(locale, "dashboardLinks");
const navigation: [Page, ReactNode, string][] = [
["dashboard", <Activity size={17} />, t.dashboard],
["assets", <Boxes size={17} />, t.assets],
["builds", <FileCode2 size={17} />, t.builds],
["runs", <Play size={17} />, t.runs],
["improvements", <BarChart3 size={17} />, t.improvements],
["settings", <Settings size={17} />, t.settings],
];
const dashboardRepositoryLinks = page === "dashboard" && (
<>
<a
className="dashboard-repository-link"
href="https://github.com/forthfate/openorbit"
target="_blank"
rel="noreferrer"
>
<SiGithub size={16} />
{dashboardLinks.repository}
</a>
<a
className="dashboard-repository-link"
href="https://github.com/forthfate/openorbit/releases"
target="_blank"
rel="noreferrer"
>
<BookOpen size={16} />
{dashboardLinks.releases}
</a>
<a
className="dashboard-repository-link"
href="/api/docs"
target="_blank"
rel="noreferrer"
>
<Braces size={16} />
{dashboardLinks.openApi}
</a>
<a
className="dashboard-repository-link"
href="/sdk-docs/sdk/"
target="_blank"
rel="noreferrer"
>
<BookOpen size={16} />
{dashboardLinks.sdkDocs}
</a>
</>
);
const activeRunLabel = activeRunCount > 99 ? "99+" : String(activeRunCount);
useEffect(
() => localStorage.setItem(sidebarStorageKey, String(collapsed)),
[collapsed],
);
useEffect(() => {
document.title = `${appMeta.title}${appMeta.titleSeparator}${pageDescriptions[page]}`;
document.documentElement.lang = locale;
}, [appMeta, locale, page, pageDescriptions]);
const navigationLabels = localeMessages<{
expandNavigation: string;
collapseNavigation: string;
activeRuns: string;
githubLabel: string;
githubTitle: string;
}>(locale, "navigationAccessibility");
const sidebarLabel = collapsed
? navigationLabels.expandNavigation
: navigationLabels.collapseNavigation;
return (
<main
className={collapsed ? "sidebar-collapsed" : undefined}
data-theme={theme === "midnight" ? "midnight" : undefined}
>
<aside>
<button
className="sidebar-toggle"
type="button"
aria-label={sidebarLabel}
aria-expanded={!collapsed}
title={sidebarLabel}
onClick={() => setCollapsed((value) => !value)}
>
<PanelLeftClose size={18} />
</button>
{collapsed ? (
<button
className="brand brand--expand"
type="button"
aria-label={navigationLabels.expandNavigation}
title={navigationLabels.expandNavigation}
onClick={() => setCollapsed(false)}
>
<Sparkles size={20} />
</button>
) : (
<div className="brand">
<Sparkles size={20} />
<div>
<span>{appMeta.title}</span>
<small>{__OPENORBIT_VERSION__}</small>
</div>
</div>
)}
<nav>
{navigation.map(([id, icon, label]) => (
<button
className={page === id ? "active" : ""}
onClick={() => setPage(id)}
key={id}
aria-label={label}
title={collapsed ? label : undefined}
>
{icon}
<span className="nav-label">{label}</span>
{id === "runs" && activeRunCount > 0 && (
<span
className="nav-run-count"
aria-label={navigationLabels.activeRuns.replace("{count}", String(activeRunCount))}
>
{activeRunLabel}
</span>
)}
</button>
))}
</nav>
</aside>
<section className="content">
<header>
<div className="page-header-copy">
<h1>{t[page]}</h1>
<p className="sub">{pageDescriptions[page]}</p>
</div>
<div className="page-header-actions">
{dashboardRepositoryLinks}
{headerAction}
</div>
</header>
{children}
<footer>
<span>© insighta cloud Inc.</span>
<a
className="github-link"
href="https://github.com/forthfate/openorbit"
target="_blank"
rel="noreferrer"
aria-label={navigationLabels.githubLabel}
title={navigationLabels.githubTitle}
>
<SiGithub size={18} />
</a>
</footer>
</section>
<ChatAssistant />
</main>
);
}