Skip to content

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

TypeScript

fix(control-ui): r3-l4 key measurements to description text

Josué3d4c0dd329ba
diff --git a/control-ui/components/TablePanelHeader/ClampedDescription.tsx b/control-ui/components/TablePanelHeader/ClampedDescription.tsx
index 644fcaa92..f5146bb93 100644
--- a/control-ui/components/TablePanelHeader/ClampedDescription.tsx
+++ b/control-ui/components/TablePanelHeader/ClampedDescription.tsx
@@ -31,7 +31,7 @@ export function ClampedDescription({ children }: { children: ReactNode }) {
observer?.disconnect()
window.removeEventListener('resize', measure)
}
- }, [children])
+ }, [tooltipText])
return (
<span
diff --git a/control-ui/components/__tests__/ClampedDescriptionMeasurement.test.tsx b/control-ui/components/__tests__/ClampedDescriptionMeasurement.test.tsx
new file mode 100644
index 000000000..0cd5d9de0
--- /dev/null
+++ b/control-ui/components/__tests__/ClampedDescriptionMeasurement.test.tsx
@@ -0,0 +1,90 @@
+import { describe, expect, it, vi } from 'vitest'
+import { act, render } from '@testing-library/react'
+import { ClampedDescription } from '../TablePanelHeader/ClampedDescription'
+
+type ObserverRecord = {
+ callback: ResizeObserverCallback
+ observe: ReturnType<typeof vi.fn>
+ disconnect: ReturnType<typeof vi.fn>
+}
+
+function createObserverMock(records: ObserverRecord[]) {
+ return class MockResizeObserver {
+ observe = vi.fn()
+ disconnect = vi.fn()
+
+ constructor(private readonly callback: ResizeObserverCallback) {
+ records.push({
+ callback,
+ observe: this.observe,
+ disconnect: this.disconnect,
+ })
+ }
+ }
+}
+
+describe('ClampedDescription measurement lifecycle', () => {
+ it('keeps the resize observer when child identity changes but text does not', () => {
+ const observers: ObserverRecord[] = []
+ vi.stubGlobal('ResizeObserver', createObserverMock(observers))
+ const { rerender, unmount } = render(
+ <ClampedDescription>
+ <span>Stable description</span>
+ </ClampedDescription>
+ )
+
+ try {
+ expect(observers).toHaveLength(1)
+ rerender(
+ <ClampedDescription>
+ <em>Stable description</em>
+ </ClampedDescription>
+ )
+ expect(observers).toHaveLength(1)
+ expect(observers[0].disconnect).not.toHaveBeenCalled()
+ } finally {
+ unmount()
+ vi.unstubAllGlobals()
+ }
+ })
+
+ it('still responds to resize and changed description text', () => {
+ const observers: ObserverRecord[] = []
+ let truncated = false
+ vi.stubGlobal('ResizeObserver', createObserverMock(observers))
+ const scrollHeight = vi
+ .spyOn(HTMLElement.prototype, 'scrollHeight', 'get')
+ .mockImplementation(function () {
+ return this.classList.contains('cu-table-panel__description-value') && truncated ? 48 : 32
+ })
+ const clientHeight = vi
+ .spyOn(HTMLElement.prototype, 'clientHeight', 'get')
+ .mockImplementation(function () {
+ return this.classList.contains('cu-table-panel__description-value') ? 32 : 0
+ })
+ const { rerender, unmount } = render(<ClampedDescription>First description</ClampedDescription>)
+
+ try {
+ const description = document.querySelector('.cu-table-panel__description')
+ expect(description).not.toHaveAttribute('aria-describedby')
+
+ truncated = true
+ act(() => observers[0].callback([], {} as ResizeObserver))
+
+ const descriptionId = description?.getAttribute('aria-describedby')
+ expect(descriptionId).not.toBeNull()
+ expect(document.getElementById(descriptionId || '')).toHaveTextContent('First description')
+
+ rerender(<ClampedDescription>Replacement description</ClampedDescription>)
+ const replacementId = description?.getAttribute('aria-describedby')
+ expect(document.getElementById(replacementId || '')).toHaveTextContent(
+ 'Replacement description'
+ )
+ } finally {
+ scrollHeight.mockRestore()
+ clientHeight.mockRestore()
+ unmount()
+ vi.unstubAllGlobals()
+ }
+ })
+})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 1e35e9ea8..ee88e958a 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.602",
+ "version": "0.1.603",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.602",
+ "version": "0.1.603",
"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 da8067df0..4746cc0f1 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.602",
+ "version": "0.1.603",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",