-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(tables): preview referenced rows inline #7106
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
Open
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e2040a
feat(tables): preview referenced rows inline
j15z 43c84a3
fix(tables): extend reference preview dividers
j15z 9b1191e
revert(tables): keep preview dividers within grid
j15z a9482da
fix(tables): contain reference preview within table
j15z e4d355c
improvement(tables): finish reference preview layout
j15z 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
120 changes: 120 additions & 0 deletions
120
...workspace/[workspaceId]/tables/[tableId]/components/table-grid/cells/cell-render.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,120 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import { act } from 'react' | ||
| import { createRoot, type Root } from 'react-dom/client' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import type { DisplayColumn } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/types' | ||
|
|
||
| vi.mock('@sim/emcn', () => ({ | ||
| Badge: ({ children }: { children: React.ReactNode }) => <span>{children}</span>, | ||
| Checkbox: () => null, | ||
| Chip: ({ children, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement>) => ( | ||
| <button {...props}>{children}</button> | ||
| ), | ||
| cn: (...values: Array<string | false | null | undefined>) => values.filter(Boolean).join(' '), | ||
| Tooltip: { | ||
| Root: ({ children }: { children: React.ReactNode }) => children, | ||
| Trigger: ({ children }: { children: React.ReactNode }) => children, | ||
| Content: ({ children }: { children: React.ReactNode }) => children, | ||
| }, | ||
| })) | ||
|
|
||
| vi.mock('@/app/workspace/[workspaceId]/logs/utils', () => ({ | ||
| StatusBadge: () => null, | ||
| })) | ||
|
|
||
| vi.mock( | ||
| '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/cells/sim-resource-cell', | ||
| () => ({ SimResourceCell: () => null }) | ||
| ) | ||
|
|
||
| vi.mock('@/app/workspace/[workspaceId]/tables/[tableId]/components/select-field', () => ({ | ||
| resolveSelectOptions: () => [], | ||
| SelectPill: () => null, | ||
| })) | ||
|
|
||
| import { | ||
| CellRender, | ||
| resolveCellRender, | ||
| } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/cells/cell-render' | ||
|
|
||
| const REFERENCE_COLUMN: DisplayColumn = { | ||
| id: 'col-account', | ||
| key: 'col-account', | ||
| name: 'Account', | ||
| type: 'reference', | ||
| referenceTableId: 'table-accounts', | ||
| groupSize: 1, | ||
| groupStartColIndex: 0, | ||
| headerLabel: 'Account', | ||
| isGroupStart: true, | ||
| } | ||
|
|
||
| let container: HTMLDivElement | ||
| let root: Root | ||
|
|
||
| beforeEach(() => { | ||
| globalThis.IS_REACT_ACT_ENVIRONMENT = true | ||
| container = document.createElement('div') | ||
| document.body.appendChild(container) | ||
| act(() => { | ||
| root = createRoot(container) | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| act(() => root.unmount()) | ||
| container.remove() | ||
| }) | ||
|
|
||
| describe('reference cell rendering', () => { | ||
| it('resolves a stored row ID to a chip labeled with the reference column name', () => { | ||
| expect( | ||
| resolveCellRender({ | ||
| value: 'row-account-1', | ||
| exec: undefined, | ||
| column: REFERENCE_COLUMN, | ||
| waitingOnLabels: undefined, | ||
| }) | ||
| ).toMatchObject({ kind: 'column-chip', label: 'Account' }) | ||
| }) | ||
|
|
||
| it('keeps an empty reference cell empty', () => { | ||
| expect( | ||
| resolveCellRender({ | ||
| value: '', | ||
| exec: undefined, | ||
| column: REFERENCE_COLUMN, | ||
| waitingOnLabels: undefined, | ||
| }) | ||
| ).toEqual({ kind: 'empty' }) | ||
| }) | ||
|
|
||
| it('opens the referenced row from the chip without exposing its stored row ID', () => { | ||
| const onReferenceClick = vi.fn() | ||
|
|
||
| act(() => { | ||
| root.render( | ||
| <CellRender | ||
| kind={resolveCellRender({ | ||
| value: 'row-account-1', | ||
| exec: undefined, | ||
| column: REFERENCE_COLUMN, | ||
| waitingOnLabels: undefined, | ||
| })} | ||
| isEditing={false} | ||
| referenceAction={{ expanded: false, onClick: onReferenceClick }} | ||
| /> | ||
| ) | ||
| }) | ||
|
|
||
| const chip = container.querySelector('button') | ||
| expect(chip?.textContent).toBe('Account') | ||
|
|
||
| act(() => chip?.click()) | ||
|
|
||
| expect(onReferenceClick).toHaveBeenCalledOnce() | ||
| expect(container.textContent).not.toContain('row-account-1') | ||
| }) | ||
| }) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Double-clicking a reference chip still bubbles
dblclickto the cell, so opening the preview can also enter inline edit mode. Stop double-click propagation on the chip, matching the URL cell behavior.Prompt for AI agents