|
|
@@ -1,6 +1,7 @@
|
|
|
-import { useState } from 'react'
|
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
+import { useSearchParams } from 'react-router-dom'
|
|
|
import { api } from '@/api/client'
|
|
|
+import { Badge } from '@/components/form'
|
|
|
import { useAuthStore } from '@/stores/authStore'
|
|
|
import EmbeddingsTab from '@/pages/settings/EmbeddingsTab'
|
|
|
import CacheTab from '@/pages/settings/CacheTab'
|
|
|
@@ -11,58 +12,163 @@ import ProjectFunctionsTab from '@/pages/settings/ProjectFunctionsTab'
|
|
|
import ProjectHostnamesTab from '@/pages/settings/ProjectHostnamesTab'
|
|
|
import ProjectStaticTab from '@/pages/settings/ProjectStaticTab'
|
|
|
|
|
|
-interface TabDef {
|
|
|
+/// The settings page is a TWO-LEVEL layout rather than one horizontal tab
|
|
|
+/// strip, and the reason is the division itself rather than the wrapping.
|
|
|
+///
|
|
|
+/// Eight items in one strip wrapped onto a second line, which is what was
|
|
|
+/// reported - but shrinking the labels would have fixed the symptom and left
|
|
|
+/// the real problem, which is that a global default and a per-project override
|
|
|
+/// looked like siblings. They are not: a global embedding default changes every
|
|
|
+/// tenant in the deployment, a project override changes one. The blast radius
|
|
|
+/// is the thing a user has to be able to read off the screen before they touch
|
|
|
+/// a control, so it decides the layout: a vertical list grouped by SCOPE, with
|
|
|
+/// the scope restated on the panel that is open.
|
|
|
+///
|
|
|
+/// Grouping vertically also removes the wrapping BY CONSTRUCTION - a vertical
|
|
|
+/// list cannot overflow horizontally however many items are added, so the next
|
|
|
+/// settings screen does not reintroduce the defect.
|
|
|
+
|
|
|
+/// `scope` is not decoration: it is what the section header, the nav badge and
|
|
|
+/// the panel's own sentence are all derived from, so the three cannot disagree.
|
|
|
+type Scope = 'global' | 'project'
|
|
|
+
|
|
|
+interface SettingsItem {
|
|
|
id: string
|
|
|
label: string
|
|
|
+ /// One line in the nav, so a user can choose without opening each panel.
|
|
|
+ blurb: string
|
|
|
+ /// Mirrors the route's own gating. Global settings are admin-only; the
|
|
|
+ /// per-project embedding override is requireProjectManage, which is why
|
|
|
+ /// /settings is not admin-gated in App.tsx and must stay reachable.
|
|
|
adminOnly: boolean
|
|
|
render: () => React.ReactNode
|
|
|
}
|
|
|
|
|
|
+interface SettingsSection {
|
|
|
+ id: string
|
|
|
+ scope: Scope
|
|
|
+ title: string
|
|
|
+ caption: string
|
|
|
+ items: SettingsItem[]
|
|
|
+}
|
|
|
+
|
|
|
export default function Settings() {
|
|
|
const admin = useAuthStore((s) => s.admin)
|
|
|
const project = useAuthStore((s) => s.currentProject)
|
|
|
+ const [searchParams, setSearchParams] = useSearchParams()
|
|
|
|
|
|
- // Global settings are admin-only; the project tab is not, so a project
|
|
|
- // manager landing here sees exactly the one tab they may use.
|
|
|
- const tabs: TabDef[] = [
|
|
|
- { id: 'embeddings', label: 'Embeddings', adminOnly: true, render: () => <EmbeddingsTab /> },
|
|
|
- { id: 'cache', label: 'Cache & performance', adminOnly: true, render: () => <CacheTab /> },
|
|
|
- { id: 'access', label: 'Access & security', adminOnly: true, render: () => <AccessTab /> },
|
|
|
- { id: 'webui', label: 'Web UI', adminOnly: true, render: () => <WebuiTab /> },
|
|
|
+ const sections: SettingsSection[] = [
|
|
|
{
|
|
|
- id: 'project',
|
|
|
- label: project ? `Project: ${project}` : 'Project',
|
|
|
- adminOnly: false,
|
|
|
- render: () => <ProjectEmbeddingsTab />,
|
|
|
+ id: 'global',
|
|
|
+ scope: 'global',
|
|
|
+ title: 'Global',
|
|
|
+ caption: 'This deployment, and therefore every project in it.',
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ id: 'embeddings',
|
|
|
+ label: 'Embeddings',
|
|
|
+ blurb: 'Default provider, key and model',
|
|
|
+ adminOnly: true,
|
|
|
+ render: () => <EmbeddingsTab />,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'cache',
|
|
|
+ label: 'Cache & performance',
|
|
|
+ blurb: 'Embedding timeouts and the shared cache',
|
|
|
+ adminOnly: true,
|
|
|
+ render: () => <CacheTab />,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'access',
|
|
|
+ label: 'Access & security',
|
|
|
+ blurb: 'CORS, sessions, captcha, function egress',
|
|
|
+ adminOnly: true,
|
|
|
+ render: () => <AccessTab />,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'webui',
|
|
|
+ label: 'Web UI',
|
|
|
+ blurb: 'This interface and the default project',
|
|
|
+ adminOnly: true,
|
|
|
+ render: () => <WebuiTab />,
|
|
|
+ },
|
|
|
+ ],
|
|
|
},
|
|
|
{
|
|
|
- id: 'functions',
|
|
|
- label: 'Functions',
|
|
|
- // Admin-only, matching the route: these bound what one project may take
|
|
|
- // from a runner every other project shares.
|
|
|
- adminOnly: true,
|
|
|
- render: () => <ProjectFunctionsTab />,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 'hostnames',
|
|
|
- label: 'Hostnames & TLS',
|
|
|
- // Admin-only, matching the route: on the short path form the hostname is
|
|
|
- // the tenancy boundary, so a project must not be able to claim one.
|
|
|
- adminOnly: true,
|
|
|
- render: () => <ProjectHostnamesTab />,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 'static',
|
|
|
- label: 'Static files',
|
|
|
- // Admin-only, matching the route: it decides what this project publishes
|
|
|
- // to the open internet with no credential.
|
|
|
- adminOnly: true,
|
|
|
- render: () => <ProjectStaticTab />,
|
|
|
+ id: 'project',
|
|
|
+ scope: 'project',
|
|
|
+ title: 'Project',
|
|
|
+ caption: 'Only the selected project. Switch projects in the header.',
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ id: 'project-embeddings',
|
|
|
+ label: 'Embeddings override',
|
|
|
+ blurb: 'Point this project at its own provider',
|
|
|
+ // NOT admin-only, matching the route (requireProjectManage). This is
|
|
|
+ // the one item a project manager comes here for.
|
|
|
+ adminOnly: false,
|
|
|
+ render: () => <ProjectEmbeddingsTab />,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'functions',
|
|
|
+ label: 'Functions',
|
|
|
+ blurb: 'Wall-time caps and network egress',
|
|
|
+ // Admin-only, matching the route: these bound what one project may
|
|
|
+ // take from a runner every other project shares.
|
|
|
+ adminOnly: true,
|
|
|
+ render: () => <ProjectFunctionsTab />,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'hostnames',
|
|
|
+ label: 'Hostnames & TLS',
|
|
|
+ blurb: 'The names this project answers on',
|
|
|
+ // Admin-only, matching the route: on the short path form the hostname
|
|
|
+ // is the tenancy boundary, so a project must not be able to claim one.
|
|
|
+ adminOnly: true,
|
|
|
+ render: () => <ProjectHostnamesTab />,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'static',
|
|
|
+ label: 'Static files',
|
|
|
+ blurb: 'Serve stored files publicly',
|
|
|
+ // Admin-only, matching the route: it decides what this project
|
|
|
+ // publishes to the open internet with no credential.
|
|
|
+ adminOnly: true,
|
|
|
+ render: () => <ProjectStaticTab />,
|
|
|
+ },
|
|
|
+ ],
|
|
|
},
|
|
|
- ].filter((t) => admin || !t.adminOnly)
|
|
|
+ ]
|
|
|
|
|
|
- const [active, setActive] = useState(tabs[0]?.id ?? 'project')
|
|
|
- const current = tabs.find((t) => t.id === active) ?? tabs[0]
|
|
|
+ // The page renders only the items this key may use, which is what keeps a
|
|
|
+ // non-admin session on a page with exactly one item rather than on a wall of
|
|
|
+ // controls that all answer 403. A section with nothing left disappears with
|
|
|
+ // its items rather than rendering an empty heading.
|
|
|
+ const visible = sections
|
|
|
+ .map((s) => ({ ...s, items: s.items.filter((i) => admin || !i.adminOnly) }))
|
|
|
+ .filter((s) => s.items.length > 0)
|
|
|
+
|
|
|
+ const flat = visible.flatMap((s) => s.items.map((i) => ({ item: i, section: s })))
|
|
|
+
|
|
|
+ /// The open item lives in the URL so a settings screen can be linked to.
|
|
|
+ /// An unknown or now-forbidden `tab` falls back to the first visible item
|
|
|
+ /// rather than rendering nothing: the id may name an admin-only item this
|
|
|
+ /// session may not have, and a shared link must not produce a blank page.
|
|
|
+ const requested = searchParams.get('tab') ?? ''
|
|
|
+ const currentEntry = flat.find((e) => e.item.id === requested) ?? flat[0]
|
|
|
+
|
|
|
+ function selectItem(id: string) {
|
|
|
+ // `replace` rather than push: clicking through four panels should not make
|
|
|
+ // Back mean "the previous panel" four times before it means "leave".
|
|
|
+ setSearchParams(
|
|
|
+ (prev) => {
|
|
|
+ const next = new URLSearchParams(prev)
|
|
|
+ next.set('tab', id)
|
|
|
+ return next
|
|
|
+ },
|
|
|
+ { replace: true },
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
// Only used to surface a load failure once, at the page level.
|
|
|
const { isError, error } = useQuery({
|
|
|
@@ -71,12 +177,15 @@ export default function Settings() {
|
|
|
enabled: admin,
|
|
|
})
|
|
|
|
|
|
+ const current = currentEntry?.item
|
|
|
+ const currentScope = currentEntry?.section.scope ?? 'global'
|
|
|
+
|
|
|
return (
|
|
|
- <div className="flex flex-col gap-6 max-w-3xl">
|
|
|
+ <div className="flex flex-col gap-6 max-w-5xl">
|
|
|
<div>
|
|
|
<h1 className="text-2xl font-semibold text-slate-100">Settings</h1>
|
|
|
<p className="text-slate-400 text-sm mt-1">
|
|
|
- Changes apply immediately (hot reload). Each tab saves on its own.
|
|
|
+ Changes apply immediately (hot reload). Each panel saves on its own.
|
|
|
</p>
|
|
|
</div>
|
|
|
|
|
|
@@ -88,27 +197,101 @@ export default function Settings() {
|
|
|
</div>
|
|
|
)}
|
|
|
|
|
|
- <div className="flex flex-wrap gap-1 border-b border-slate-700">
|
|
|
- {tabs.map((t) => (
|
|
|
- <button
|
|
|
- key={t.id}
|
|
|
- type="button"
|
|
|
- onClick={() => setActive(t.id)}
|
|
|
- className={[
|
|
|
- 'px-4 py-2 text-sm font-medium border-b-2 -mb-px transition',
|
|
|
- t.id === current?.id
|
|
|
- ? 'border-indigo-500 text-slate-100'
|
|
|
- : 'border-transparent text-slate-400 hover:text-slate-200',
|
|
|
- ].join(' ')}
|
|
|
- >
|
|
|
- {t.label}
|
|
|
- </button>
|
|
|
- ))}
|
|
|
- </div>
|
|
|
+ <div className="flex flex-col gap-6 lg:flex-row lg:items-start">
|
|
|
+ <nav aria-label="Settings sections" className="flex flex-col gap-6 lg:w-64 lg:shrink-0">
|
|
|
+ {visible.map((section) => (
|
|
|
+ <div key={section.id} className="flex flex-col gap-1">
|
|
|
+ <div className="flex items-center gap-2 px-1">
|
|
|
+ <span className="text-[11px] font-semibold uppercase tracking-wider text-slate-500">
|
|
|
+ {section.title}
|
|
|
+ </span>
|
|
|
+ <ScopeBadge scope={section.scope} project={project} />
|
|
|
+ </div>
|
|
|
+ <p className="px-1 text-xs text-slate-500">{section.caption}</p>
|
|
|
|
|
|
- <div className="rounded-xl border border-slate-700 bg-slate-800/30 px-6 py-5">
|
|
|
- {current?.render()}
|
|
|
+ <ul className="mt-1 flex flex-col gap-0.5">
|
|
|
+ {section.items.map((item) => {
|
|
|
+ const active = item.id === current?.id
|
|
|
+ return (
|
|
|
+ <li key={item.id}>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => selectItem(item.id)}
|
|
|
+ aria-current={active ? 'page' : undefined}
|
|
|
+ className={[
|
|
|
+ 'w-full rounded-md border-l-2 px-3 py-2 text-left transition',
|
|
|
+ active
|
|
|
+ ? 'border-indigo-500 bg-slate-800/60 text-slate-100'
|
|
|
+ : 'border-transparent text-slate-400 hover:bg-slate-800/30 hover:text-slate-200',
|
|
|
+ ].join(' ')}
|
|
|
+ >
|
|
|
+ <span className="block text-sm font-medium">{item.label}</span>
|
|
|
+ <span className="block text-xs text-slate-500">{item.blurb}</span>
|
|
|
+ </button>
|
|
|
+ </li>
|
|
|
+ )
|
|
|
+ })}
|
|
|
+ </ul>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+
|
|
|
+ {/* Said here because the project hostnames panel tells the reader to
|
|
|
+ set a deployment hostname "in the global settings", and there is
|
|
|
+ no such control in this UI: it would be a dead end otherwise. */}
|
|
|
+ {admin && (
|
|
|
+ <p className="px-1 text-xs text-slate-500">
|
|
|
+ The deployment's own names (<code>admin_hostname</code>,{' '}
|
|
|
+ <code>global_hostnames</code>) are global settings and are not editable here yet.
|
|
|
+ Set them on <code>PUT /api/v1/settings</code>.
|
|
|
+ </p>
|
|
|
+ )}
|
|
|
+ </nav>
|
|
|
+
|
|
|
+ <section className="min-w-0 flex-1">
|
|
|
+ <div className="rounded-xl border border-slate-700 bg-slate-800/30">
|
|
|
+ <div className="flex flex-col gap-2 border-b border-slate-700 px-6 py-4">
|
|
|
+ <div className="flex flex-wrap items-center gap-2">
|
|
|
+ <h2 className="text-base font-semibold text-slate-100">
|
|
|
+ {current?.label ?? 'Settings'}
|
|
|
+ </h2>
|
|
|
+ <ScopeBadge scope={currentScope} project={project} />
|
|
|
+ </div>
|
|
|
+ {/* The blast radius, restated on the panel that is open. The
|
|
|
+ project selector lives in the page header, far from here, so
|
|
|
+ a per-project panel that did not name its project would be
|
|
|
+ asking the user to remember which tenant they are editing. */}
|
|
|
+ <p className="text-xs text-slate-400">
|
|
|
+ {currentScope === 'project' ? (
|
|
|
+ project ? (
|
|
|
+ <>
|
|
|
+ Applies to <strong className="text-slate-200">{project}</strong> only. No other
|
|
|
+ project is affected.
|
|
|
+ </>
|
|
|
+ ) : (
|
|
|
+ <>No project is selected, so there is nothing for this panel to change yet.</>
|
|
|
+ )
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ Applies to the <strong className="text-slate-200">whole deployment</strong>, so
|
|
|
+ every project is affected.
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="px-6 py-5">{current?.render()}</div>
|
|
|
+ </div>
|
|
|
+ </section>
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
+/// One badge, used in both places the scope is stated, so the nav and the open
|
|
|
+/// panel cannot drift apart. A project badge names the project because the
|
|
|
+/// scope is worthless without it: "project" alone does not say which.
|
|
|
+function ScopeBadge({ scope, project }: { scope: Scope; project: string | null }) {
|
|
|
+ if (scope === 'global') return <Badge>all projects</Badge>
|
|
|
+ if (!project) return <Badge tone="amber">no project selected</Badge>
|
|
|
+ return <Badge tone="indigo">{project}</Badge>
|
|
|
+}
|