Skip to content

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

TypeScript

fix(control-ui): let a form section's owner hold its open state

Andy Pavia8f9fb5cdb373
diff --git a/control-ui/components/HookInstallForm/index.tsx b/control-ui/components/HookInstallForm/index.tsx
index 10b5b995e..c91bf78af 100644
--- a/control-ui/components/HookInstallForm/index.tsx
+++ b/control-ui/components/HookInstallForm/index.tsx
@@ -76,6 +76,10 @@ export function HookInstallForm({ entry, onCancel, onInstalled }: HookInstallFor
const [capabilities, setCapabilities] = useState<Set<HookCapability>>(new Set())
const [order, setOrder] = useState(String(DEFAULT_HOOK_ORDER))
const [failMode, setFailMode] = useState<'open' | 'closed'>('open')
+ // Owned here rather than inside FormSection: step 0's subtree unmounts on
+ // Continue, so a disclosure holding its own state would forget it and come
+ // back closed on Back, hiding the capabilities the operator just reviewed.
+ const [advancedOpen, setAdvancedOpen] = useState(false)
const [loading, setLoading] = useState(true)
const [installing, setInstalling] = useState(false)
const [error, setError] = useState('')
@@ -118,6 +122,7 @@ export function HookInstallForm({ entry, onCancel, onInstalled }: HookInstallFor
setStep(0)
setError('')
setCredValues({})
+ setAdvancedOpen(false)
// Seed from the author's declaration so the default install is the working
// one. The ceiling effect below narrows this once an agent is selected, and
// the operator can still untick anything.
@@ -385,7 +390,12 @@ export function HookInstallForm({ entry, onCancel, onInstalled }: HookInstallFor
{/* Everything an install can leave at its default lives behind one
disclosure: the entry's own facts, which are applied as-is, the
granted capabilities, and the ordering/fail-mode knobs. */}
- <FormSection title="Advanced details" collapsible>
+ <FormSection
+ title="Advanced details"
+ collapsible
+ open={advancedOpen}
+ onOpenChange={setAdvancedOpen}
+ >
<div className="cu-summary-list cu-summary-list--flush">
{targetImage ? (
<div className="cu-summary-list__row">
diff --git a/control-ui/components/__tests__/FormSection.test.tsx b/control-ui/components/__tests__/FormSection.test.tsx
index 93362a59c..9ff10553d 100644
--- a/control-ui/components/__tests__/FormSection.test.tsx
+++ b/control-ui/components/__tests__/FormSection.test.tsx
@@ -1,4 +1,4 @@
-import { afterEach, describe, expect, it } from 'vitest'
+import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { FormSection } from '../ui'
@@ -40,9 +40,9 @@ describe('FormSection', () => {
expect(screen.queryByText('order field')).toBeNull()
})
- it('starts open when defaultOpen is set, and points the toggle at its content', () => {
+ it('follows the owner when open is controlled, and points the toggle at its content', () => {
render(
- <FormSection title="Advanced details" collapsible defaultOpen>
+ <FormSection title="Advanced details" collapsible open onOpenChange={() => undefined}>
<p>order field</p>
</FormSection>
)
@@ -54,4 +54,18 @@ describe('FormSection', () => {
expect(controlled).not.toBeNull()
expect(controlled).toHaveTextContent('order field')
})
+
+ it('reports a toggle to its owner rather than acting on it when controlled', () => {
+ // The owner holds the state so it survives the section being unmounted; the
+ // section must not open itself behind the owner's back.
+ const onOpenChange = vi.fn()
+ render(
+ <FormSection title="Advanced details" collapsible open={false} onOpenChange={onOpenChange}>
+ <p>order field</p>
+ </FormSection>
+ )
+ fireEvent.click(screen.getByRole('button', { name: 'Advanced details' }))
+ expect(onOpenChange).toHaveBeenCalledWith(true)
+ expect(screen.queryByText('order field')).toBeNull()
+ })
})
diff --git a/control-ui/components/__tests__/HookInstallForm.test.tsx b/control-ui/components/__tests__/HookInstallForm.test.tsx
index c43b06563..89325f17e 100644
--- a/control-ui/components/__tests__/HookInstallForm.test.tsx
+++ b/control-ui/components/__tests__/HookInstallForm.test.tsx
@@ -242,6 +242,30 @@ describe('HookInstallForm — declaration never escapes the ceiling', () => {
})
})
+describe('HookInstallForm — step navigation', () => {
+ it('keeps Advanced details open across Continue and Back', async () => {
+ // Step 0's subtree unmounts on Continue. When the disclosure held its own
+ // state, Back rebuilt it closed and the capabilities the operator had just
+ // reviewed — and any warning their edit produced — silently disappeared.
+ render(
+ <HookInstallForm
+ entry={entryWith({ requiredCapabilities: ['may_rewrite'] })}
+ onCancel={noop}
+ onInstalled={noop}
+ />
+ )
+ await openAdvanced()
+
+ fireEvent.click(await screen.findByRole('button', { name: /continue/i }))
+ expect(await screen.findByText(/will be installed on agent/i)).toBeInTheDocument()
+
+ fireEvent.click(screen.getByRole('button', { name: /back/i }))
+ const toggle = await screen.findByRole('button', { name: /advanced details/i })
+ expect(toggle).toHaveAttribute('aria-expanded', 'true')
+ expect(capabilityBox('May rewrite').checked).toBe(true)
+ })
+})
+
describe('HookInstallForm — ungranted-capability warning', () => {
// `enforceCapabilities` neutralizes deny/rewrite/substitute and nothing else,
// so the "actions are discarded" warning must not be shown for a capability
diff --git a/control-ui/components/ui/index.tsx b/control-ui/components/ui/index.tsx
index 1a3737bbb..5df4561cf 100644
--- a/control-ui/components/ui/index.tsx
+++ b/control-ui/components/ui/index.tsx
@@ -59,11 +59,19 @@ export function FormSection({
description,
title,
collapsible = false,
- defaultOpen = false,
+ open: openProp,
+ onOpenChange,
}: FormSectionProps) {
- const [open, setOpen] = React.useState(defaultOpen)
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false)
+ const open = openProp ?? uncontrolledOpen
const contentId = React.useId()
+ function toggle() {
+ const next = !open
+ if (openProp === undefined) setUncontrolledOpen(next)
+ onOpenChange?.(next)
+ }
+
if (!collapsible) {
return (
<section className="cu-form-section">
@@ -86,7 +94,7 @@ export function FormSection({
className="cu-form-section__toggle"
aria-expanded={open}
aria-controls={contentId}
- onClick={() => setOpen(value => !value)}
+ onClick={toggle}
>
<IconChevronRight className={open ? 'is-expanded' : undefined} width={18} height={18} />
{title}
diff --git a/control-ui/components/ui/types.ts b/control-ui/components/ui/types.ts
index 7a444421e..195a8fa0a 100644
--- a/control-ui/components/ui/types.ts
+++ b/control-ui/components/ui/types.ts
@@ -32,7 +32,12 @@ export type FormSectionProps = {
// installs leave alone. Collapsed shows the title only, so the section costs
// one line until someone opens it.
collapsible?: boolean
- defaultOpen?: boolean
+ // Optional controlled state. Left out, the section owns its own and starts
+ // closed. Passed, the owner holds it — which is what a section needs when it
+ // lives inside a subtree that unmounts (a wizard step), or when what should
+ // be open depends on data that has not arrived at first render.
+ open?: boolean
+ onOpenChange?: (open: boolean) => void
}
export type TextInputProps = InputHTMLAttributes<HTMLInputElement> & {
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 2ec4fe8e5..fe4130736 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.454",
+ "version": "0.1.455",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.454",
+ "version": "0.1.455",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 1d989a4b6..f717e25df 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.454",
+ "version": "0.1.455",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",