Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-ui): keep guardrail tabs and markdown headers in sync

M9400012bae61
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index 20844f82c..bc127afb8 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -13105,7 +13105,7 @@ button.cu-gfs-tree__button:focus-visible,
.cu-gfs-markdown-preview__content .gfs-markdown-table-scroll th {
background: rgba(var(--cu-edge-rgb), 0.14);
color: var(--cu-text);
- font-size: inherit;
+ font-size: var(--cu-font-size-md);
font-weight: 600;
letter-spacing: normal;
position: static;
diff --git a/control-ui/app/guardrails/[name]/__tests__/page.test.tsx b/control-ui/app/guardrails/[name]/__tests__/page.test.tsx
index e9ababe15..2d01cc5f3 100644
--- a/control-ui/app/guardrails/[name]/__tests__/page.test.tsx
+++ b/control-ui/app/guardrails/[name]/__tests__/page.test.tsx
@@ -7,6 +7,7 @@ import GuardrailDetailPage from '../page'
const navigation = vi.hoisted(() => ({
params: { name: 'sample-hook', tab: 'details' as string | undefined },
push: vi.fn(),
+ replace: vi.fn(),
notFound: vi.fn(() => {
throw new Error('NOT_FOUND')
}),
@@ -18,7 +19,7 @@ const api = vi.hoisted(() => ({
vi.mock('next/navigation', () => ({
useParams: () => navigation.params,
- useRouter: () => ({ push: navigation.push }),
+ useRouter: () => ({ push: navigation.push, replace: navigation.replace }),
notFound: navigation.notFound,
}))
vi.mock('@lib/api', () => ({
@@ -31,31 +32,8 @@ vi.mock('@components/ConfirmDialog', () => ({
useConfirmDialog: () => ({ confirm: vi.fn(), confirmDialog: null }),
}))
vi.mock('@components/Toast', () => ({ useToast: () => ({ showToast: vi.fn() }) }))
-vi.mock('@components/DetailPageShell', () => ({
- DetailPageShell: ({
- activeTab,
- children,
- tabs,
- }: {
- activeTab: string
- children: ReactNode
- tabs: Array<{ href: string; label: string; value: string }>
- }) => (
- <main>
- <nav aria-label="Guardrail detail sections">
- {tabs.map(tab => (
- <a
- key={tab.value}
- aria-current={tab.value === activeTab ? 'page' : undefined}
- href={tab.href}
- >
- {tab.label}
- </a>
- ))}
- </nav>
- {children}
- </main>
- ),
+vi.mock('@components/DashboardLayout', () => ({
+ DashboardLayout: ({ children }: { children: ReactNode }) => <main>{children}</main>,
}))
beforeEach(() => {
@@ -89,12 +67,25 @@ describe('guardrail detail routes', () => {
)
).toBeInTheDocument()
expect(
- screen.getByRole('link', { name: tab === 'details' ? 'Details' : 'Agents with access' })
- ).toHaveAttribute('aria-current', 'page')
- expect(screen.getByRole('link', { name: 'Agents with access' })).toHaveAttribute(
- 'href',
- '/guardrails/sample-hook/agents'
+ screen.getByRole('tab', { name: tab === 'details' ? 'Details' : 'Agents with access' })
+ ).toHaveAttribute('aria-selected', 'true')
+ })
+
+ it('switches sections and replaces the route when a tab is clicked in the real shell', async () => {
+ render(<GuardrailDetailPage />)
+ expect(
+ await screen.findByText('Runtime configuration reported by the installed hook.')
+ ).toBeInTheDocument()
+
+ fireEvent.click(screen.getByRole('tab', { name: 'Agents with access' }))
+
+ expect(screen.getByText('sample-agent')).toBeInTheDocument()
+ expect(screen.queryByText('Runtime configuration reported by the installed hook.')).toBeNull()
+ expect(screen.getByRole('tab', { name: 'Agents with access' })).toHaveAttribute(
+ 'aria-selected',
+ 'true'
)
+ expect(navigation.replace).toHaveBeenCalledWith('/guardrails/sample-hook/agents')
})
it('rejects unknown tab routes', async () => {
diff --git a/control-ui/app/guardrails/[name]/page.tsx b/control-ui/app/guardrails/[name]/page.tsx
index f6c0d2c3a..6575eecf0 100644
--- a/control-ui/app/guardrails/[name]/page.tsx
+++ b/control-ui/app/guardrails/[name]/page.tsx
@@ -159,10 +159,9 @@ export default function GuardrailDetailPage() {
return CONTROL_ROUTES.guardrails.tab(name, tab)
}
- // Tab navigation goes through the Link rendered by TabBar (see the href on
- // each tab option); DetailPageShell requires a handler to render tabs.
function selectTab(tab: GuardrailTab) {
- void tab
+ setActiveTab(tab)
+ router.replace(guardrailTabHref(tab))
}
async function handleUninstall() {
@@ -202,7 +201,6 @@ export default function GuardrailDetailPage() {
tabs={GUARDRAIL_DETAIL_TABS.map(tab => ({
value: tab,
label: GUARDRAIL_TAB_LABELS[tab],
- href: guardrailTabHref(tab),
}))}
title={name || 'Guardrail'}
titleActions={
diff --git a/control-ui/components/GfsMarkdownPreview/index.tsx b/control-ui/components/GfsMarkdownPreview/index.tsx
index 96b6e8b12..21f93335b 100644
--- a/control-ui/components/GfsMarkdownPreview/index.tsx
+++ b/control-ui/components/GfsMarkdownPreview/index.tsx
@@ -61,7 +61,7 @@ const GFS_MARKDOWN_COMPONENTS: Components = {
role="region"
tabIndex={0}
>
- <DataTable {...props} className="cu-table gfs-markdown-table" variant="embedded">
+ <DataTable {...props} className="gfs-markdown-table" variant="embedded">
{children}
</DataTable>
</TableViewport>
diff --git a/control-ui/components/__tests__/GfsMarkdownPreview.test.tsx b/control-ui/components/__tests__/GfsMarkdownPreview.test.tsx
index a1cbac668..5e999fa8e 100644
--- a/control-ui/components/__tests__/GfsMarkdownPreview.test.tsx
+++ b/control-ui/components/__tests__/GfsMarkdownPreview.test.tsx
@@ -1,5 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, render, screen, within } from '@testing-library/react'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
import { GfsMarkdownPreview } from '../GfsMarkdownPreview'
import { ToastProvider } from '../Toast'
@@ -59,10 +61,17 @@ describe('GfsMarkdownPreview', () => {
name: 'Markdown preview of inventory.md',
})
const table = within(article).getByRole('table')
+ expect(table).not.toHaveClass('cu-table')
expect(within(table).getByRole('columnheader', { name: 'Item' })).toHaveAttribute(
'scope',
'col'
)
+ const css = readFileSync(resolve(__dirname, '../../app/globals.css'), 'utf8')
+ const headerRule = css.match(
+ /\.cu-gfs-markdown-preview__content \.gfs-markdown-table-scroll th \{([^}]*)\}/
+ )?.[1]
+ expect(headerRule).toMatch(/font-size:\s*var\(--cu-font-size-md\)/)
+ expect(headerRule).toMatch(/text-transform:\s*none/)
expect(within(table).getByRole('cell', { name: 'GFS files' })).toBeInTheDocument()
expect(screen.getByRole('region', { name: 'Scrollable Markdown table' })).toHaveAttribute(
'tabindex',
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 064217612..c98bef98b 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.657",
+ "version": "0.1.658",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.657",
+ "version": "0.1.658",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index 9b3807f93..3f9e6c074 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.657",
+ "version": "0.1.658",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",