-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(tables): create and open views from chat #6058
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
BillLeoutsakosvl346
wants to merge
6
commits into
staging
Choose a base branch
from
improvement/chat-table-views
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b101abe
chore(test): ignore Playwright artifacts
2703ce9
feat(tables): create views from chat
a7d12e5
fix(tables): address view review feedback
a59c683
fix(tables): honor view feature boundaries
acfef82
fix(tables): handle stale chat views
b3fc19e
fix(tables): clear deleted embedded view state
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
72 changes: 72 additions & 0 deletions
72
...w/components/resource-content/components/embedded-view-table/embedded-view-table.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,72 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
|
|
||
| import { act } from 'react' | ||
| import { createRoot, type Root } from 'react-dom/client' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true | ||
|
|
||
| const { tableMock } = vi.hoisted(() => ({ tableMock: vi.fn() })) | ||
|
|
||
| vi.mock('@/app/workspace/[workspaceId]/tables/[tableId]/table', () => ({ | ||
| Table: (props: Record<string, unknown>) => { | ||
| tableMock(props) | ||
| return <div data-testid='embedded-table' /> | ||
| }, | ||
| })) | ||
|
|
||
| import { EmbeddedViewTable } from './embedded-view-table' | ||
|
|
||
| let container: HTMLDivElement | ||
| let root: Root | ||
|
|
||
| describe('EmbeddedViewTable', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| container = document.createElement('div') | ||
| document.body.appendChild(container) | ||
| root = createRoot(container) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await act(async () => root.unmount()) | ||
| container.remove() | ||
| }) | ||
|
|
||
| it('renders the source Table with the persisted View selected', async () => { | ||
| await act(async () => { | ||
| root.render( | ||
| <EmbeddedViewTable workspaceId='workspace_1' resourceId='tbl_1:view_1' viewsEnabled /> | ||
| ) | ||
| }) | ||
|
|
||
| expect(container.querySelector('[data-testid="embedded-table"]')).not.toBeNull() | ||
| expect(tableMock).toHaveBeenCalledWith({ | ||
| workspaceId: 'workspace_1', | ||
| tableId: 'tbl_1', | ||
| viewId: 'view_1', | ||
| embedded: true, | ||
| viewsEnabled: true, | ||
| }) | ||
| }) | ||
|
|
||
| it('does not render a malformed View resource', async () => { | ||
| await act(async () => { | ||
| root.render(<EmbeddedViewTable workspaceId='workspace_1' resourceId='view_1' />) | ||
| }) | ||
|
|
||
| expect(container.innerHTML).toBe('') | ||
| expect(tableMock).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('does not bypass a disabled Views feature flag', async () => { | ||
| await act(async () => { | ||
| root.render(<EmbeddedViewTable workspaceId='workspace_1' resourceId='tbl_1:view_1' />) | ||
| }) | ||
|
|
||
| expect(container.innerHTML).toBe('') | ||
| expect(tableMock).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
29 changes: 29 additions & 0 deletions
29
...p-view/components/resource-content/components/embedded-view-table/embedded-view-table.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,29 @@ | ||
| 'use client' | ||
|
|
||
| import { parseTableViewResourceId } from '@/lib/copilot/resources/types' | ||
| import { Table } from '@/app/workspace/[workspaceId]/tables/[tableId]/table' | ||
|
|
||
| interface EmbeddedViewTableProps { | ||
| workspaceId: string | ||
| resourceId: string | ||
| viewsEnabled?: boolean | ||
| } | ||
|
|
||
| /** Renders a persisted View resource through its live source Table. */ | ||
| export function EmbeddedViewTable({ | ||
| workspaceId, | ||
| resourceId, | ||
| viewsEnabled = false, | ||
| }: EmbeddedViewTableProps) { | ||
| const parsed = parseTableViewResourceId(resourceId) | ||
| if (!parsed || !viewsEnabled) return null | ||
| return ( | ||
| <Table | ||
| workspaceId={workspaceId} | ||
| tableId={parsed.tableId} | ||
| viewId={parsed.viewId} | ||
| embedded | ||
| viewsEnabled={viewsEnabled} | ||
| /> | ||
| ) | ||
| } | ||
1 change: 1 addition & 0 deletions
1
...nents/mothership-view/components/resource-content/components/embedded-view-table/index.ts
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 @@ | ||
| export { EmbeddedViewTable } from './embedded-view-table' |
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
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
113 changes: 113 additions & 0 deletions
113
...im/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.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,113 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
|
|
||
| import type { ReactNode } from 'react' | ||
| import { act } from 'react' | ||
| import { createRoot, type Root } from 'react-dom/client' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import type { TableViewWire } from '@/lib/api/contracts/tables' | ||
|
|
||
| ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true | ||
|
|
||
| vi.mock('@sim/emcn', () => ({ | ||
| ChipChevronDown: () => null, | ||
| chipContentLabelClass: '', | ||
| chipVariants: () => '', | ||
| cn: (...values: unknown[]) => values.filter(Boolean).join(' '), | ||
| POPOVER_ANIMATION_CLASSES: '', | ||
| Popover: ({ children }: { children: ReactNode }) => <>{children}</>, | ||
| PopoverAnchor: ({ children }: { children: ReactNode }) => <>{children}</>, | ||
| PopoverContent: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| PopoverItem: ({ children, onClick }: { children: ReactNode; onClick?: () => void }) => ( | ||
| <button onClick={onClick}>{children}</button> | ||
| ), | ||
| PopoverSection: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| })) | ||
|
|
||
| import { ViewsMenu } from './views-menu' | ||
|
|
||
| function view(id: string, name: string): TableViewWire { | ||
| return { | ||
| id, | ||
| tableId: 'tbl_1', | ||
| name, | ||
| config: {}, | ||
| isDefault: false, | ||
| createdBy: 'user_1', | ||
| createdAt: new Date('2026-01-01'), | ||
| updatedAt: new Date('2026-01-01'), | ||
| } | ||
| } | ||
|
|
||
| let container: HTMLDivElement | ||
| let root: Root | ||
|
|
||
| describe('ViewsMenu', () => { | ||
| beforeEach(() => { | ||
| container = document.createElement('div') | ||
| document.body.appendChild(container) | ||
| root = createRoot(container) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await act(async () => root.unmount()) | ||
| container.remove() | ||
| }) | ||
|
|
||
| it('renders the implicit Default view first and selects saved Views', async () => { | ||
| const onSelect = vi.fn() | ||
| await act(async () => { | ||
| root.render( | ||
| <ViewsMenu | ||
| views={[view('view_a', 'Alpha'), view('view_z', 'Zulu')]} | ||
| activeViewId={null} | ||
| onSelect={onSelect} | ||
| onRename={vi.fn()} | ||
| onDelete={vi.fn()} | ||
| onNewView={vi.fn()} | ||
| canEdit | ||
| /> | ||
| ) | ||
| }) | ||
|
|
||
| const labels = Array.from(container.querySelectorAll('button')) | ||
| .map((button) => button.textContent?.trim()) | ||
| .filter(Boolean) | ||
| expect(labels.slice(1, 4)).toEqual(['Default view', 'Alpha', 'Zulu']) | ||
|
|
||
| const alpha = Array.from(container.querySelectorAll('button')).find( | ||
| (button) => button.textContent?.trim() === 'Alpha' | ||
| ) | ||
| await act(async () => alpha?.click()) | ||
| expect(onSelect).toHaveBeenCalledWith('view_a') | ||
| }) | ||
|
|
||
| it('exposes rename and delete actions only for saved Views', async () => { | ||
| const onRename = vi.fn() | ||
| const onDelete = vi.fn() | ||
| await act(async () => { | ||
| root.render( | ||
| <ViewsMenu | ||
| views={[view('view_a', 'Alpha')]} | ||
| activeViewId='view_a' | ||
| onSelect={vi.fn()} | ||
| onRename={onRename} | ||
| onDelete={onDelete} | ||
| onNewView={vi.fn()} | ||
| canEdit | ||
| /> | ||
| ) | ||
| }) | ||
|
|
||
| const rename = container.querySelector<HTMLButtonElement>('button[aria-label="Rename"]') | ||
| const remove = container.querySelector<HTMLButtonElement>('button[aria-label="Delete"]') | ||
| expect(rename).not.toBeNull() | ||
| expect(remove).not.toBeNull() | ||
|
|
||
| await act(async () => rename?.click()) | ||
| await act(async () => remove?.click()) | ||
| expect(onRename).toHaveBeenCalledWith('view_a') | ||
| expect(onDelete).toHaveBeenCalledWith('view_a') | ||
| }) | ||
| }) |
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.