-
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
+4,515
−191
Open
Changes from all commits
Commits
Show all changes
13 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 80afd8d
fix(tables): stabilize reference preview scrolling
j15z 81b8847
fix(tables): preserve reference preview scrolling and clipping
j15z cb225b6
fix(tables): route reference preview wheel scrolling
j15z fabb273
improvement(tables): move preview navigation into header
j15z b734463
improvement(tables): polish reference row previews
j15z 884d43f
fix(tables): preserve foreign key integrity
j15z 5bb480f
docs(tables): add a gentle table tour
j15z 32536a5
Merge feat/table-fks into feat/reference-row-preview
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
70 changes: 70 additions & 0 deletions
70
...orkspace/[workspaceId]/tables/[tableId]/components/table-grid/cells/cell-content.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,70 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import { act } from 'react' | ||
| import { createTableColumn } from '@sim/testing' | ||
| 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( | ||
| '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/cells/cell-render', | ||
| () => ({ | ||
| resolveCellRender: () => ({ kind: 'empty' }), | ||
| CellRender: () => null, | ||
| }) | ||
| ) | ||
|
|
||
| vi.mock( | ||
| '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/cells/inline-editors', | ||
| () => ({ InlineEditor: () => <input data-testid='inline-editor' /> }) | ||
| ) | ||
|
|
||
| import { CellContent } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/cells/cell-content' | ||
|
|
||
| const COLUMN: DisplayColumn = { | ||
| ...createTableColumn({ id: 'col-name', name: 'Name', type: 'string' }), | ||
| key: 'col-name', | ||
| groupSize: 1, | ||
| groupStartColIndex: 0, | ||
| headerLabel: 'Name', | ||
| 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('CellContent', () => { | ||
| it('keeps the inline editor below the sticky table header', () => { | ||
| act(() => { | ||
| root.render( | ||
| <CellContent | ||
| value='Acme' | ||
| column={COLUMN} | ||
| workspaceId='workspace-1' | ||
| isEditing | ||
| onSave={vi.fn()} | ||
| onCancel={vi.fn()} | ||
| /> | ||
| ) | ||
| }) | ||
|
|
||
| const editorLayer = container.querySelector('[data-testid="inline-editor"]')?.parentElement | ||
| expect(editorLayer?.className).toContain('z-[9]') | ||
| expect(editorLayer?.className).not.toContain('z-10') | ||
| }) | ||
| }) |
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
184 changes: 184 additions & 0 deletions
184
...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,184 @@ | ||
| /** | ||
| * @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>, | ||
| Button: ({ | ||
| children, | ||
| size, | ||
| variant, | ||
| ...props | ||
| }: React.ButtonHTMLAttributes<HTMLButtonElement> & { | ||
| size?: string | ||
| variant?: string | ||
| }) => ( | ||
| <button data-size={size} data-variant={variant} {...props}> | ||
| {children} | ||
| </button> | ||
| ), | ||
| Checkbox: () => null, | ||
| ChipTag: ({ | ||
| children, | ||
| variant, | ||
| ...props | ||
| }: React.HTMLAttributes<HTMLSpanElement> & { variant?: string }) => ( | ||
| <span data-chip-tag-variant={variant} {...props}> | ||
| {children} | ||
| </span> | ||
| ), | ||
| 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', | ||
| referenceTableName: '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 referenced table name', () => { | ||
| expect( | ||
| resolveCellRender({ | ||
| value: 'row-account-1', | ||
| exec: undefined, | ||
| column: REFERENCE_COLUMN, | ||
| waitingOnLabels: undefined, | ||
| }) | ||
| ).toEqual({ kind: 'column-chip', label: 'Accounts' }) | ||
| }) | ||
|
|
||
| it('keeps an empty reference cell empty', () => { | ||
| expect( | ||
| resolveCellRender({ | ||
| value: '', | ||
| exec: undefined, | ||
| column: REFERENCE_COLUMN, | ||
| waitingOnLabels: undefined, | ||
| }) | ||
| ).toEqual({ kind: 'empty' }) | ||
| }) | ||
|
|
||
| it('uses a neutral label while the referenced table name is unavailable', () => { | ||
| expect( | ||
| resolveCellRender({ | ||
| value: 'row-account-1', | ||
| exec: undefined, | ||
| column: { ...REFERENCE_COLUMN, referenceTableName: undefined }, | ||
| waitingOnLabels: undefined, | ||
| }) | ||
| ).toEqual({ kind: 'column-chip', label: 'Referenced table' }) | ||
| }) | ||
|
|
||
| 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('Accounts') | ||
| expect(chip?.dataset.variant).toBe('ghost') | ||
| expect(chip?.dataset.size).toBe('sm') | ||
| expect(chip?.className).toContain('max-w-full') | ||
| expect(chip?.className).toContain('p-0') | ||
| expect(chip?.querySelector('svg')).toBeNull() | ||
| const tag = chip?.querySelector('[data-chip-tag-variant="field"]') | ||
| expect(tag?.textContent).toBe('Accounts') | ||
| expect(tag?.className).toContain('min-w-0') | ||
| expect(tag?.className).toContain('max-w-full') | ||
|
|
||
| act(() => chip?.click()) | ||
|
|
||
| expect(onReferenceClick).toHaveBeenCalledOnce() | ||
| expect(container.textContent).not.toContain('row-account-1') | ||
| }) | ||
|
|
||
| it('keeps a chip double-click from reaching the reference cell', () => { | ||
| const onCellDoubleClick = vi.fn() | ||
|
|
||
| act(() => { | ||
| root.render( | ||
| <div onDoubleClick={onCellDoubleClick}> | ||
| <CellRender | ||
| kind={{ kind: 'column-chip', label: 'Accounts' }} | ||
| isEditing={false} | ||
| referenceAction={{ expanded: false, onClick: vi.fn() }} | ||
| /> | ||
| </div> | ||
| ) | ||
| }) | ||
|
|
||
| act(() => { | ||
| container | ||
| .querySelector('button') | ||
| ?.dispatchEvent(new MouseEvent('dblclick', { bubbles: true })) | ||
| }) | ||
|
|
||
| expect(onCellDoubleClick).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
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.