-
Notifications
You must be signed in to change notification settings - Fork 3.8k
refactor(ui): use native terminal row buttons #8263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
67dea87
Use native buttons for terminal log rows
0b51931
test(terminal): verify complete native row markup
e1ceb58
fix(terminal): expose selected row state and use absolute imports
3732bad
fix(terminal): identify current output without toggle semantics
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
...kspaceId]/w/[workflowId]/components/terminal/components/status-display/status-display.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
.../[workspaceId]/w/[workflowId]/components/terminal/components/terminal-row-button.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import { act } from 'react' | ||
| import { BlockTileView } from '@sim/workflow-renderer' | ||
| import { createRoot, type Root } from 'react-dom/client' | ||
| import { renderToStaticMarkup } from 'react-dom/server' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { | ||
| StatusDisplay, | ||
| TerminalRowButton, | ||
| } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/components' | ||
| import { ROW_STYLES } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/types' | ||
|
|
||
| let root: Root | ||
| let host: HTMLDivElement | ||
|
|
||
| beforeEach(() => { | ||
| ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true | ||
| host = document.createElement('div') | ||
| document.body.appendChild(host) | ||
| root = createRoot(host) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| act(() => root.unmount()) | ||
| host.remove() | ||
| }) | ||
|
|
||
| describe('TerminalRowButton', () => { | ||
| it('renders selected disclosure semantics and handles one native click locally', () => { | ||
| const onClick = vi.fn() | ||
| const onParentClick = vi.fn() | ||
|
|
||
| act(() => { | ||
| root.render( | ||
| <div onClick={onParentClick}> | ||
| <TerminalRowButton selected aria-expanded data-entry-id='entry-1' onClick={onClick}> | ||
| <span>Workflow result</span> | ||
| </TerminalRowButton> | ||
| </div> | ||
| ) | ||
| }) | ||
|
|
||
| const button = host.querySelector('button')! | ||
| expect(button.type).toBe('button') | ||
| expect(button.getAttribute('aria-expanded')).toBe('true') | ||
| expect(button.getAttribute('aria-current')).toBe('true') | ||
| expect(button.getAttribute('data-entry-id')).toBe('entry-1') | ||
| expect(button.className).toBe(ROW_STYLES.rowSelected) | ||
| act(() => button.focus()) | ||
| expect(document.activeElement).toBe(button) | ||
| act(() => button.click()) | ||
| expect(onClick).toHaveBeenCalledTimes(1) | ||
| expect(onParentClick).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('keeps the base chip row when selection and expansion are absent', () => { | ||
| act(() => { | ||
| root.render(<TerminalRowButton>Block output</TerminalRowButton>) | ||
| }) | ||
| const button = host.querySelector('button')! | ||
| expect(button.className).toBe(ROW_STYLES.row) | ||
| expect(button.hasAttribute('aria-expanded')).toBe(false) | ||
| expect(button.hasAttribute('aria-current')).toBe(false) | ||
| expect(button.textContent).toBe('Block output') | ||
| }) | ||
|
|
||
| it('does not mark an unselected output row as current', () => { | ||
| act(() => { | ||
| root.render(<TerminalRowButton selected={false}>Other output</TerminalRowButton>) | ||
| }) | ||
| expect(host.querySelector('button')?.hasAttribute('aria-current')).toBe(false) | ||
| }) | ||
|
|
||
| it('keeps the running status inline inside a native button', () => { | ||
| const html = renderToStaticMarkup( | ||
| <TerminalRowButton> | ||
| <StatusDisplay isRunning isCanceled={false} formattedDuration='-' /> | ||
| </TerminalRowButton> | ||
| ) | ||
| expect(html).toMatch(/^<button\b/) | ||
| expect(html).toContain('>Running</span>') | ||
| expect(html).not.toContain('<div') | ||
| }) | ||
|
|
||
| it('keeps the complete tile, label, chevron, and status as valid button contents', () => { | ||
| const Icon = ({ className }: { className?: string }) => <svg className={className} /> | ||
| const html = renderToStaticMarkup( | ||
| <TerminalRowButton aria-expanded={false}> | ||
| <span className={ROW_STYLES.content}> | ||
| <BlockTileView as='span' blockType='agent' icon={Icon} bgColor='#33C482' useAccent /> | ||
| <span className={ROW_STYLES.label}>Agent</span> | ||
| <svg aria-hidden='true' /> | ||
| </span> | ||
| <span className={ROW_STYLES.status}> | ||
| <StatusDisplay isRunning isCanceled={false} formattedDuration='-' /> | ||
| </span> | ||
| </TerminalRowButton> | ||
| ) | ||
| const document = new DOMParser().parseFromString(html, 'text/html') | ||
| const button = document.querySelector('button') | ||
| expect(button?.getAttribute('aria-expanded')).toBe('false') | ||
| expect(button?.textContent).toContain('Agent') | ||
| expect(button?.textContent).toContain('Running') | ||
| expect(button?.querySelector('[data-workflow-type-icon="agent"]')).not.toBeNull() | ||
| expect(button?.querySelectorAll('button, a, div')).toHaveLength(0) | ||
| expect(document.body.children).toHaveLength(1) | ||
| }) | ||
| }) |
31 changes: 31 additions & 0 deletions
31
...space/[workspaceId]/w/[workflowId]/components/terminal/components/terminal-row-button.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import type { ButtonHTMLAttributes } from 'react' | ||
| import { cn } from '@sim/emcn' | ||
| import { ROW_STYLES } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/types' | ||
|
|
||
| export interface TerminalRowButtonProps | ||
| extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'aria-current'> { | ||
| /** Use the selected chip surface for the active output row. */ | ||
| selected?: boolean | ||
| } | ||
|
|
||
| /** Native terminal row action with the established EMCN chip surface. */ | ||
| export function TerminalRowButton({ | ||
| selected, | ||
| className, | ||
| onClick, | ||
| type, | ||
| ...props | ||
| }: TerminalRowButtonProps) { | ||
| return ( | ||
| <button | ||
| type={type ?? 'button'} | ||
| className={cn(selected ? ROW_STYLES.rowSelected : ROW_STYLES.row, className)} | ||
| aria-current={selected ? 'true' : undefined} | ||
| onClick={(event) => { | ||
| event.stopPropagation() | ||
| onClick?.(event) | ||
| }} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.