Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): r3-l1 preserve component-only titles
Josuéd39b0b7fadd6
diff --git a/control-ui/components/TablePanelHeader/contentSemantics.ts b/control-ui/components/TablePanelHeader/contentSemantics.tsnew file mode 100644index 000000000..0f72cfcf3--- /dev/null+++ b/control-ui/components/TablePanelHeader/contentSemantics.ts@@ -0,0 +1,36 @@+import { Children, Fragment, isValidElement } from 'react'+import type { ReactNode } from 'react'++function flattenTitleNodes(title: ReactNode): ReactNode[] {+ return Children.toArray(title).flatMap(node =>+ isValidElement<{ children?: ReactNode }>(node) && node.type === Fragment+ ? flattenTitleNodes(node.props.children)+ : node+ )+}++export function splitTitleContent(title: ReactNode): {+ icon: ReactNode | null+ text: ReactNode[]+} {+ const nodes = flattenTitleNodes(title)+ const [first, ...remaining] = nodes+ const icon =+ remaining.length > 0 && isValidElement(first) && typeof first.type !== 'string' ? first : null++ return {+ icon,+ text: icon ? remaining : nodes,+ }+}++export function hasInteractiveDescendant(node: ReactNode): boolean {+ if (!isValidElement<{ children?: ReactNode }>(node)) return false+ if (+ typeof node.type === 'string' &&+ ['a', 'button', 'input', 'select', 'textarea'].includes(node.type)+ ) {+ return true+ }+ return Children.toArray(node.props.children).some(hasInteractiveDescendant)+}diff --git a/control-ui/components/TablePanelHeader/index.tsx b/control-ui/components/TablePanelHeader/index.tsxindex d21c8c72d..b019fcfe9 100644--- a/control-ui/components/TablePanelHeader/index.tsx+++ b/control-ui/components/TablePanelHeader/index.tsx@@ -1,31 +1,11 @@'use client'-import { Children, Fragment, isValidElement } from 'react'-import type { ReactNode } from 'react'import { DataViewHeader } from '@clerum/frontend-components'import { cn } from '@lib/cn'import { ClampedDescription } from './ClampedDescription'+import { hasInteractiveDescendant, splitTitleContent } from './contentSemantics'import type { TablePanelHeaderProps } from './types'-function flattenTitleNodes(title: ReactNode): ReactNode[] {- return Children.toArray(title).flatMap(node =>- isValidElement<{ children?: ReactNode }>(node) && node.type === Fragment- ? flattenTitleNodes(node.props.children)- : node- )-}--function hasInteractiveDescendant(node: ReactNode): boolean {- if (!isValidElement<{ children?: ReactNode }>(node)) return false- if (- typeof node.type === 'string' &&- ['a', 'button', 'input', 'select', 'textarea'].includes(node.type)- ) {- return true- }- return Children.toArray(node.props.children).some(hasInteractiveDescendant)-}-/** Control UI compatibility adapter for the shared list header. */export function TablePanelHeader({actionsClassName,@@ -37,13 +17,7 @@ export function TablePanelHeader({title,titleActions,}: TablePanelHeaderProps) {- const titleNodes = flattenTitleNodes(title)- const [firstTitleNode, ...remainingTitleNodes] = titleNodes- const titleIcon =- isValidElement(firstTitleNode) && typeof firstTitleNode.type !== 'string'- ? firstTitleNode- : undefined- const titleText = titleIcon ? remainingTitleNodes : titleNodes+ const { icon: titleIcon, text: titleText } = splitTitleContent(title)return (<DataViewHeaderdiff --git a/control-ui/components/__tests__/TablePanelHeaderTitleSemantics.test.tsx b/control-ui/components/__tests__/TablePanelHeaderTitleSemantics.test.tsxnew file mode 100644index 000000000..32a9a1a86--- /dev/null+++ b/control-ui/components/__tests__/TablePanelHeaderTitleSemantics.test.tsx@@ -0,0 +1,39 @@+import { describe, expect, it } from 'vitest'+import { render, screen } from '@testing-library/react'+import { TablePanelHeader } from '../TablePanelHeader'++function ComponentTitle() {+ return <span>Component-only title</span>+}++function AgentsIcon() {+ return <svg aria-label="Agents icon" />+}++describe('TablePanelHeader title semantics', () => {+ it('keeps a single component title in the visible title text', () => {+ render(<TablePanelHeader title={<ComponentTitle />} />)++ const title = screen.getByText('Component-only title')+ expect(title.closest('.cu-table-panel__title-text')).not.toBeNull()+ expect(document.querySelector('.cu-table-panel__title-icon')).toBeNull()+ })++ it('still separates an icon from the remaining title text', () => {+ render(+ <TablePanelHeader+ title={+ <>+ <AgentsIcon />+ Agents+ </>+ }+ />+ )++ expect(+ screen.getByLabelText('Agents icon').closest('.cu-table-panel__title-icon')+ ).not.toBeNull()+ expect(screen.getByText('Agents').closest('.cu-table-panel__title-text')).not.toBeNull()+ })+})diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 9ab51c9f9..5484f9994 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.600",+ "version": "0.1.601","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.600",+ "version": "0.1.601","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.jsonindex 50e4b134b..b6d3b6d2c 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.600",+ "version": "0.1.601","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",