Skip to content

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

TypeScript

feat: standardize bounded Control edit dialogs

Josuéa11d279d9da5
diff --git a/control-ui/components/ControlSettingsPanel/index.tsx b/control-ui/components/ControlSettingsPanel/index.tsx
index e5c8c95f9..7f7f9f308 100644
--- a/control-ui/components/ControlSettingsPanel/index.tsx
+++ b/control-ui/components/ControlSettingsPanel/index.tsx
@@ -1,8 +1,8 @@
'use client'
-import { type FormEvent, useEffect, useMemo, useState } from 'react'
+import { useEffect, useMemo, useState } from 'react'
import { useSearchParams } from 'next/navigation'
-import { SingleValueEditDialog } from '@clerum/frontend-components'
+import { SimpleEditDialog, SingleValueEditDialog } from '@clerum/frontend-components'
import {
hasControlAdminBridgeAlertOverrides,
resetControlAdminBridgeAlerts,
@@ -192,8 +192,7 @@ export function ControlSettingsPanel({ emailConfirmationStatus }: ControlSetting
showToast('Alerts reset.', { tone: 'success' })
}
- async function handleSavePassword(event: FormEvent<HTMLFormElement>) {
- event.preventDefault()
+ async function handleSavePassword() {
if (!canSavePassword) return
setPasswordError('')
if (newPassword !== confirmPassword) {
@@ -455,78 +454,51 @@ export function ControlSettingsPanel({ emailConfirmationStatus }: ControlSetting
)}
/>
- {showPasswordModal ? (
- <div
- className="cu-modal-backdrop"
- role="presentation"
- onMouseDown={event => {
- if (event.target === event.currentTarget) closePasswordModal()
- }}
- >
- <form
- className="cu-modal-panel cu-modal-panel--narrow"
- role="dialog"
- aria-modal="true"
- aria-labelledby="settings-password-title"
- onSubmit={event => void handleSavePassword(event)}
- >
- <div className="cu-modal-panel__head">
- <h3 id="settings-password-title" className="cu-modal-panel__title">
- Change password
- </h3>
- </div>
- <div className="cu-modal-panel__body">
- <Field label="Current password" htmlFor="settings-current-password" required>
- <TextInput
- id="settings-current-password"
- type="password"
- value={currentPassword}
- onChange={event => setCurrentPassword(event.target.value)}
- disabled={savingPassword}
- autoComplete="current-password"
- />
- </Field>
- <Field label="New password" htmlFor="settings-new-password" required>
- <TextInput
- id="settings-new-password"
- type="password"
- value={newPassword}
- onChange={event => setNewPassword(event.target.value)}
- disabled={savingPassword}
- autoComplete="new-password"
- />
- </Field>
- <Field label="Confirm new password" htmlFor="settings-confirm-password" required>
- <TextInput
- id="settings-confirm-password"
- type="password"
- value={confirmPassword}
- onChange={event => setConfirmPassword(event.target.value)}
- disabled={savingPassword}
- autoComplete="new-password"
- />
- </Field>
- {passwordError ? (
- <div className="cu-banner cu-banner--error">{passwordError}</div>
- ) : null}
- </div>
- <div className="cu-modal-panel__foot">
- <Button
- type="button"
- variant="ghost"
- size="sm"
- onClick={closePasswordModal}
- disabled={savingPassword}
- >
- Cancel
- </Button>
- <Button type="submit" variant="primary" size="sm" disabled={!canSavePassword}>
- {savingPassword ? 'Saving...' : 'Save password'}
- </Button>
- </div>
- </form>
+ <SimpleEditDialog
+ open={showPasswordModal}
+ title="Change password"
+ description="Confirm your current password, then choose a new password."
+ pending={savingPassword}
+ error={passwordError}
+ isDirty={currentPassword.length > 0 || newPassword.length > 0 || confirmPassword.length > 0}
+ isValid={canSavePassword}
+ saveLabel="Save password"
+ onCancel={closePasswordModal}
+ onSave={() => void handleSavePassword()}
+ >
+ <div className="cu-modal-panel__body">
+ <Field label="Current password" htmlFor="settings-current-password" required>
+ <TextInput
+ id="settings-current-password"
+ type="password"
+ value={currentPassword}
+ onChange={event => setCurrentPassword(event.target.value)}
+ disabled={savingPassword}
+ autoComplete="current-password"
+ />
+ </Field>
+ <Field label="New password" htmlFor="settings-new-password" required>
+ <TextInput
+ id="settings-new-password"
+ type="password"
+ value={newPassword}
+ onChange={event => setNewPassword(event.target.value)}
+ disabled={savingPassword}
+ autoComplete="new-password"
+ />
+ </Field>
+ <Field label="Confirm new password" htmlFor="settings-confirm-password" required>
+ <TextInput
+ id="settings-confirm-password"
+ type="password"
+ value={confirmPassword}
+ onChange={event => setConfirmPassword(event.target.value)}
+ disabled={savingPassword}
+ autoComplete="new-password"
+ />
+ </Field>
</div>
- ) : null}
+ </SimpleEditDialog>
{confirmDialog}
</div>
)
diff --git a/control-ui/components/HostEnvTable.tsx b/control-ui/components/HostEnvTable.tsx
index 6f6d0e1d7..0431b331a 100644
--- a/control-ui/components/HostEnvTable.tsx
+++ b/control-ui/components/HostEnvTable.tsx
@@ -2,7 +2,7 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import type { ReactNode } from 'react'
-import { DataTable } from '@clerum/frontend-components'
+import { DataTable, SimpleEditDialog } from '@clerum/frontend-components'
import {
HostEnvEntry,
HostEnvWriteResult,
@@ -13,7 +13,7 @@ import {
import { useConfirmDialog } from './ConfirmDialog'
import { RowActionsMenu } from './RowActionsMenu'
import { useToast } from './Toast'
-import { IconRefresh, IconX } from './icons'
+import { IconRefresh } from './icons'
import { Button, CheckboxField, Field, TextInput } from './ui'
const RESERVED_PROVIDER_KEYS = new Set([
@@ -333,29 +333,22 @@ export function HostEnvTable({
</tbody>
</DataTable>
- {open ? (
- <section className="cu-host-env-form" data-testid="host-env-form">
- <div className="cu-host-env-form__head">
- <div>
- <h3 className="cu-host-env-form__title">
- {editingKey ? `Edit ${editingKey}` : 'Add variable'}
- </h3>
- <p className="cu-host-env-form__description">
- {editingKey
- ? 'Update the value applied to this agent.'
- : 'Create an operator-managed variable for this agent.'}
- </p>
- </div>
- <button
- type="button"
- className="cu-btn cu-btn--icon cu-btn--toolbar"
- onClick={closeForm}
- aria-label="Close variable form"
- >
- <IconX width={16} height={16} />
- </button>
- </div>
-
+ <SimpleEditDialog
+ open={open}
+ title={editingKey ? `Edit ${editingKey}` : 'Add variable'}
+ description={
+ editingKey
+ ? 'Update the value applied to this agent.'
+ : 'Create an operator-managed variable for this agent.'
+ }
+ pending={saving}
+ error={error}
+ isDirty={keyDraft.length > 0 || valueDraft.length > 0 || secretDraft}
+ isValid={!keyDraftError && Boolean((editingKey ?? keyDraft).trim()) && Boolean(valueDraft)}
+ onCancel={closeForm}
+ onSave={() => void save()}
+ >
+ <div data-testid="host-env-form">
<div className="cu-host-env-form__grid">
<Field
error={keyDraftError}
@@ -395,17 +388,8 @@ export function HostEnvTable({
description="Stored in a Kubernetes Secret and never returned by GET."
/>
</div>
-
- <div className="cu-host-env-form__actions">
- <Button type="button" variant="ghost" onClick={closeForm}>
- Cancel
- </Button>
- <Button type="button" variant="primary" onClick={save} disabled={saving}>
- {saving ? 'Saving…' : 'Save'}
- </Button>
- </div>
- </section>
- ) : null}
+ </div>
+ </SimpleEditDialog>
{confirmDialog}
</section>
diff --git a/control-ui/components/__tests__/ControlSettingsPanel.test.tsx b/control-ui/components/__tests__/ControlSettingsPanel.test.tsx
index 93c28b5ee..aaf28f936 100644
--- a/control-ui/components/__tests__/ControlSettingsPanel.test.tsx
+++ b/control-ui/components/__tests__/ControlSettingsPanel.test.tsx
@@ -3,11 +3,13 @@ import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-li
import {
getControlUISettingsMe,
requestControlUISettingsEmailChange,
+ updateControlUISettingsPassword,
updateControlUISettingsUsername,
} from '@lib/api'
import { ControlSettingsPanel } from '../ControlSettingsPanel'
const checkAuth = vi.fn()
+const logout = vi.fn()
const showToast = vi.fn()
vi.mock('next/navigation', () => ({
@@ -15,7 +17,7 @@ vi.mock('next/navigation', () => ({
}))
vi.mock('../AuthContext', () => ({
- useAuth: () => ({ checkAuth, logout: vi.fn() }),
+ useAuth: () => ({ checkAuth, logout }),
}))
vi.mock('../AdminBridgeAlerts', () => ({
@@ -45,6 +47,7 @@ vi.mock('@lib/api', () => ({
const mockGetSettings = vi.mocked(getControlUISettingsMe)
const mockRequestEmailChange = vi.mocked(requestControlUISettingsEmailChange)
const mockUpdateUsername = vi.mocked(updateControlUISettingsUsername)
+const mockUpdatePassword = vi.mocked(updateControlUISettingsPassword)
function accountRow(label: string): HTMLElement {
const row = screen.getByText(label).closest('.cu-settings-row')
@@ -136,4 +139,31 @@ describe('ControlSettingsPanel scalar dialogs', () => {
expect(screen.getByText('Confirmation pending for [email protected].')).toBeInTheDocument()
expect(showToast).toHaveBeenCalledWith('Confirmation email sent.', { tone: 'success' })
})
+
+ it('uses the shared simple dialog and preserves password reauthentication', async () => {
+ mockUpdatePassword.mockResolvedValue(undefined)
+ render(<ControlSettingsPanel />)
+
+ await screen.findByText('admin')
+ fireEvent.click(screen.getByRole('button', { name: 'Change password' }))
+ const dialog = screen.getByRole('dialog', { name: 'Change password' })
+ fireEvent.change(within(dialog).getByLabelText(/^Current password/), {
+ target: { value: 'current-password' },
+ })
+ fireEvent.change(within(dialog).getByLabelText(/^New password/), {
+ target: { value: 'next-password' },
+ })
+ fireEvent.change(within(dialog).getByLabelText(/^Confirm new password/), {
+ target: { value: 'next-password' },
+ })
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Save password' }))
+
+ await waitFor(() =>
+ expect(mockUpdatePassword).toHaveBeenCalledWith({
+ currentPassword: 'current-password',
+ newPassword: 'next-password',
+ })
+ )
+ expect(logout).toHaveBeenCalledTimes(1)
+ })
})
diff --git a/control-ui/components/__tests__/HostEnvTable.test.tsx b/control-ui/components/__tests__/HostEnvTable.test.tsx
new file mode 100644
index 000000000..b33dcb463
--- /dev/null
+++ b/control-ui/components/__tests__/HostEnvTable.test.tsx
@@ -0,0 +1,40 @@
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import { listHostEnv, putHostEnv } from '@lib/api'
+import { HostEnvTable } from '../HostEnvTable'
+
+vi.mock('@lib/api', () => ({
+ deleteHostEnvKey: vi.fn(),
+ listHostEnv: vi.fn(),
+ putHostEnv: vi.fn(),
+}))
+
+vi.mock('../ConfirmDialog', () => ({
+ useConfirmDialog: () => ({ confirm: vi.fn(), confirmDialog: null }),
+}))
+
+vi.mock('../Toast', () => ({ useToast: () => ({ showToast: vi.fn() }) }))
+
+describe('HostEnvTable simple edit dialog', () => {
+ afterEach(cleanup)
+
+ it('stages a new variable and saves through the existing host env mutation', async () => {
+ vi.mocked(listHostEnv).mockResolvedValue({ items: [] })
+ vi.mocked(putHostEnv).mockResolvedValue({ keys: [] })
+ render(<HostEnvTable hostRef="agent-a" />)
+
+ await screen.findByText('No env vars set for this Host yet.')
+ fireEvent.click(screen.getByRole('button', { name: 'Add variable' }))
+ const dialog = screen.getByRole('dialog', { name: 'Add variable' })
+ fireEvent.change(within(dialog).getByLabelText(/^Name/), { target: { value: 'API_TOKEN' } })
+ fireEvent.change(within(dialog).getByLabelText(/^Value/), { target: { value: 'secret' } })
+ fireEvent.click(within(dialog).getByRole('checkbox', { name: /^Secret/ }))
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+
+ await waitFor(() =>
+ expect(putHostEnv).toHaveBeenCalledWith('agent-a', [
+ { key: 'API_TOKEN', value: 'secret', secret: true },
+ ])
+ )
+ })
+})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 3e36f6fe6..d6f52cf37 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.611",
+ "version": "0.1.612",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.611",
+ "version": "0.1.612",
"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 10127ee47..554a7f1c1 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.611",
+ "version": "0.1.612",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",