-
Notifications
You must be signed in to change notification settings - Fork 3.8k
refactor(ui): share log and enrichment details panels #8026
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
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
60 changes: 60 additions & 0 deletions
60
packages/emcn/src/components/details-panel/details-panel.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,60 @@ | ||
| /** @vitest-environment jsdom */ | ||
| import { act, createRef } from 'react' | ||
| import { DetailsPanel, type DetailsPanelProps } from '@sim/emcn' | ||
| import { createRoot } from 'react-dom/client' | ||
| import { expect, it, vi } from 'vitest' | ||
|
|
||
| it('forwards resize events and retains content and refs while closed', () => { | ||
| ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true | ||
| const container = document.createElement('div') | ||
| document.body.appendChild(container) | ||
| const root = createRoot(container) | ||
| const ref = createRef<HTMLDivElement>() | ||
| const resize = vi.fn() | ||
| const render = (open: boolean, width: DetailsPanelProps['width'] = 520) => ( | ||
| <DetailsPanel | ||
| ref={ref} | ||
| open={open} | ||
| width={width} | ||
| style={{ width: 1, opacity: 0.9 }} | ||
| onResizeStart={resize} | ||
| resizeLabel='Resize details' | ||
| aria-label='Details' | ||
| > | ||
| <input aria-label='Search details' defaultValue='Retained query' /> | ||
| </DetailsPanel> | ||
| ) | ||
|
|
||
| try { | ||
| act(() => root.render(render(true))) | ||
| const panel = ref.current! | ||
| expect(panel.style.getPropertyValue('--details-panel-width')).toBe('520px') | ||
| expect(panel.style.width).toBe('') | ||
| expect(panel.style.opacity).toBe('0.9') | ||
| expect(panel.hasAttribute('inert')).toBe(false) | ||
| const input = panel.querySelector('input')! | ||
| const handle = container.querySelector<HTMLDivElement>('[role="separator"]')! | ||
| expect(handle.style.getPropertyValue('--details-panel-width')).toBe('520px') | ||
| expect(handle.getAttribute('aria-label')).toBe('Resize details') | ||
| expect(panel.contains(handle)).toBe(false) | ||
| act(() => handle.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: 240 }))) | ||
| expect(resize).toHaveBeenCalledTimes(1) | ||
| expect(resize.mock.calls[0][0].clientX).toBe(240) | ||
|
|
||
| act(() => root.render(render(false))) | ||
| expect(panel.hasAttribute('inert')).toBe(true) | ||
| expect(ref.current).toBe(panel) | ||
| expect(panel.querySelector('input')).toBe(input) | ||
| expect(input.value).toBe('Retained query') | ||
| expect(container.querySelector('[role="separator"]')).toBeNull() | ||
| const responsiveWidth = 'clamp(min(320px, 60vw), 520px, 60vw)' | ||
| act(() => root.render(render(true, responsiveWidth))) | ||
| expect(panel.style.getPropertyValue('--details-panel-width')).toBe(responsiveWidth) | ||
| expect(panel.hasAttribute('inert')).toBe(false) | ||
| expect(panel.querySelector('input')).toBe(input) | ||
| expect(container.querySelector('[role="separator"]')).not.toBeNull() | ||
| } finally { | ||
| act(() => root.unmount()) | ||
| container.remove() | ||
| } | ||
| }) |
62 changes: 62 additions & 0 deletions
62
packages/emcn/src/components/details-panel/details-panel.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,62 @@ | ||
| import { type CSSProperties, forwardRef, type HTMLAttributes, type MouseEventHandler } from 'react' | ||
| import { cn } from '../../lib/cn' | ||
|
|
||
| export interface DetailsPanelProps extends HTMLAttributes<HTMLDivElement> { | ||
| /** Slide the panel into view; closed content stays mounted but inert. */ | ||
| open: boolean | ||
| /** Controlled width, including responsive CSS expressions such as clamp(). */ | ||
| width: NonNullable<CSSProperties['width']> | ||
| /** Existing product resize handler; width state stays with the caller. */ | ||
| onResizeStart: MouseEventHandler<HTMLDivElement> | ||
| /** Accessible name for the external resize handle. */ | ||
| resizeLabel: string | ||
| } | ||
|
|
||
| /** | ||
| * Non-modal details sidebar with a right-edge slide and an external resize handle. | ||
| * Its parent supplies the positioned containing block. Content, keyboard commands, | ||
| * and persisted width remain owned by the caller. | ||
| * | ||
| * @example | ||
| * <DetailsPanel open={open} width={width} onResizeStart={handleMouseDown} | ||
| * resizeLabel='Resize log details panel' aria-label='Log details sidebar'> | ||
| * {content} | ||
| * </DetailsPanel> | ||
| */ | ||
| export const DetailsPanel = forwardRef<HTMLDivElement, DetailsPanelProps>( | ||
| ({ open, width, onResizeStart, resizeLabel, className, style, children, ...props }, ref) => { | ||
| const cssWidth = typeof width === 'number' ? `${width}px` : width | ||
| const widthStyle = { '--details-panel-width': cssWidth } as CSSProperties | ||
| const { width: _styleWidth, ...panelStyle } = style ?? {} | ||
|
|
||
| return ( | ||
| <> | ||
| {open && ( | ||
| <div | ||
| className='absolute top-0 right-[calc(var(--details-panel-width)_-_4px)] bottom-0 z-[var(--z-dropdown)] w-[8px] cursor-ew-resize' | ||
| style={widthStyle} | ||
| onMouseDown={onResizeStart} | ||
| role='separator' | ||
| aria-label={resizeLabel} | ||
| aria-orientation='vertical' | ||
| /> | ||
| )} | ||
| <div | ||
| {...props} | ||
| ref={ref} | ||
| inert={!open || props.inert} | ||
| className={cn( | ||
| 'absolute top-0 right-0 bottom-0 z-[var(--z-dropdown)] w-[var(--details-panel-width)] overflow-hidden border-l bg-[var(--bg)] shadow-md transition-transform duration-200 ease-out', | ||
| open ? 'translate-x-0' : 'translate-x-full', | ||
| className | ||
| )} | ||
| style={{ ...panelStyle, ...widthStyle }} | ||
| > | ||
| {children} | ||
| </div> | ||
| </> | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| DetailsPanel.displayName = 'DetailsPanel' | ||
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.
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.