Repository navigation
feat: Allow to edit a column from the schema visualiser - #43592
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
7 Skipped Deployments
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a ColumnEditionContext (type, provider, hook) and integrates it into the schema graph and table node UI so per-column "Edit" actions call a unified onEditColumn(tableId, columnId) handler. SchemaGraph sets selectedTable and delegates to the table editor snapshot (snap.onEditColumn), and a SidePanelEditor displays the selected table/column for editing. getTables() now returns full PostgresTable[] (including columns). E2E tests expanded/renamed to cover column CRUD flows and column description edits. Sequence DiagramsequenceDiagram
actor User
participant TableNode as SchemaTableNode
participant Context as ColumnEditionContext
participant Graph as SchemaGraph
participant Snap as TableEditorSnapshot
participant SidePanel as SidePanelEditor
participant ColumnEditor as ColumnEditor
participant API as Backend/API
User->>TableNode: Click "Edit" on column
TableNode->>Context: onEditColumn(tableId, columnId)
Context->>Graph: forward onEditColumn
Graph->>Graph: find table & set selectedTable
Graph->>Snap: snap.onEditColumn(tableId, columnId)
Graph->>SidePanel: open with selectedTable
SidePanel->>ColumnEditor: render column details
User->>ColumnEditor: submit edits
ColumnEditor->>API: send update
API->>API: persist & invalidate table list
API-->>ColumnEditor: return success
ColumnEditor->>SidePanel: close/refresh
SidePanel->>Graph: trigger UI update
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🎭 Playwright Test ResultsDetails
Flaky testsFeatures › table-editor.spec.ts › table editor › add enums and show enums on table Skipped testsFeatures › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/studio/components/interfaces/Database/Schemas/ColumnEditionContext.tsx`:
- Around line 1-2: The file imports ReactNode from react-markdown internals;
update the import so ReactNode is imported from 'react' instead (keep
createContext and useContext imports unchanged) — locate the import statement
that references ReactNode (used in this file alongside createContext/useContext)
and change its source to 'react' to match the rest of the codebase.
In `@apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx`:
- Around line 215-227: The new onEditColumn entry in columnEditionContext
bypasses the existing write guards and should be blocked when edits are not
allowed; modify the onEditColumn implementation to check the existing
canUpdateTables and isSchemaLocked flags (computed earlier in the component)
before proceeding: if !canUpdateTables or isSchemaLocked return early; otherwise
locate the table/column as now, call setSelectedTable(table) and
snap.onEditColumn(column). Ensure you reference the same variables
(canUpdateTables, isSchemaLocked, columnEditionContext, onEditColumn,
setSelectedTable, snap.onEditColumn) so the hover action respects schema
write/lock rules.
- Around line 199-213: The effect that loads nodes/edges should re-fit the
viewport when the user changes schemas: update the useEffect watching
isSuccessTables/isSuccessSchemas/tables/resolvedTheme to also include
selectedSchema, and after getGraphDataFromTables resolves and
reactFlowInstance.setNodes/setEdges, call reactFlowInstance.fitView (using the
same setTimeout used for first load) whenever selectedSchema changed (or
whenever not isFirstLoad.current) so the newly loaded graph is centered;
reference isFirstLoad, selectedSchema, getGraphDataFromTables,
reactFlowInstance.setNodes/setEdges, and reactFlowInstance.fitView to locate and
implement the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 0409c930-ef4a-478a-bce2-de2b00978d2c
📒 Files selected for processing (7)
apps/studio/components/interfaces/Database/Schemas/ColumnEditionContext.tsxapps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsxapps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsxapps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsxapps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsxapps/studio/data/tables/tables-query.tse2e/studio/features/database.spec.ts
| const isFirstLoad = useRef(true) | ||
| useEffect(() => { | ||
| if (isSuccessTables && isSuccessSchemas && tables.length > 0) { | ||
| const schema = schemas.find((s) => s.name === selectedSchema) as PostgresSchema | ||
| getGraphDataFromTables(ref as string, schema, tables).then(({ nodes, edges }) => { | ||
| reactFlowInstance.setNodes(nodes) | ||
| reactFlowInstance.setEdges(edges) | ||
| setTimeout(() => reactFlowInstance.fitView({})) // it needs to happen during next event tick | ||
| // Prevent resetting a view after first load to avoid layout changes after editing a column | ||
| if (isFirstLoad.current) { | ||
| isFirstLoad.current = false | ||
| setTimeout(() => reactFlowInstance.fitView({})) // it needs to happen during next event tick | ||
| } | ||
| }) | ||
| } | ||
| }, [isSuccessTables, isSuccessSchemas, tables, resolvedTheme]) |
There was a problem hiding this comment.
Re-fit the viewport when selectedSchema changes.
Once isFirstLoad.current flips to false, every later schema switch reuses the previous viewport. After the first visit, changing schemas can leave the newly loaded graph off-screen until the user manually recenters it.
Possible fix
- const isFirstLoad = useRef(true)
+ const lastFittedSchema = useRef<string | undefined>(undefined)
useEffect(() => {
if (isSuccessTables && isSuccessSchemas && tables.length > 0) {
const schema = schemas.find((s) => s.name === selectedSchema) as PostgresSchema
getGraphDataFromTables(ref as string, schema, tables).then(({ nodes, edges }) => {
reactFlowInstance.setNodes(nodes)
reactFlowInstance.setEdges(edges)
- // Prevent resetting a view after first load to avoid layout changes after editing a column
- if (isFirstLoad.current) {
- isFirstLoad.current = false
+ // Recenter on first load per schema, but not on every table refresh
+ if (lastFittedSchema.current !== selectedSchema) {
+ lastFittedSchema.current = selectedSchema
setTimeout(() => reactFlowInstance.fitView({})) // it needs to happen during next event tick
}
})
}
- }, [isSuccessTables, isSuccessSchemas, tables, resolvedTheme])
+ }, [isSuccessTables, isSuccessSchemas, tables, resolvedTheme, selectedSchema])🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx` around
lines 199 - 213, The effect that loads nodes/edges should re-fit the viewport
when the user changes schemas: update the useEffect watching
isSuccessTables/isSuccessSchemas/tables/resolvedTheme to also include
selectedSchema, and after getGraphDataFromTables resolves and
reactFlowInstance.setNodes/setEdges, call reactFlowInstance.fitView (using the
same setTimeout used for first load) whenever selectedSchema changed (or
whenever not isFirstLoad.current) so the newly loaded graph is centered;
reference isFirstLoad, selectedSchema, getGraphDataFromTables,
reactFlowInstance.setNodes/setEdges, and reactFlowInstance.fitView to locate and
implement the change.
| const columnEditionContext = useMemo<ColumnEditionContextType>( | ||
| () => ({ | ||
| onEditColumn: (tableId, columnId) => { | ||
| const table = tables.find((table) => table.id === tableId) | ||
| if (!table || table.columns == null) return | ||
| const column = table.columns.find((column) => column.id === columnId) | ||
| if (!column) return | ||
| setSelectedTable(table) | ||
| snap.onEditColumn(column) | ||
| }, | ||
| }), | ||
| [tables, snap] | ||
| ) |
There was a problem hiding this comment.
Guard the new edit entry point with the existing write/lock checks.
This handler ignores canUpdateTables and isSchemaLocked, so the new hover action can still open a writable column editor for protected schemas and for users without table write access. The schema visualizer already computes those conditions above; this path needs to enforce them too.
Minimal guard
const columnEditionContext = useMemo<ColumnEditionContextType>(
() => ({
onEditColumn: (tableId, columnId) => {
+ if (!canUpdateTables || isSchemaLocked) return
const table = tables.find((table) => table.id === tableId)
if (!table || table.columns == null) return
const column = table.columns.find((column) => column.id === columnId)
if (!column) return
setSelectedTable(table)
snap.onEditColumn(column)
},
}),
- [tables, snap]
+ [canUpdateTables, isSchemaLocked, tables, snap]
)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const columnEditionContext = useMemo<ColumnEditionContextType>( | |
| () => ({ | |
| onEditColumn: (tableId, columnId) => { | |
| const table = tables.find((table) => table.id === tableId) | |
| if (!table || table.columns == null) return | |
| const column = table.columns.find((column) => column.id === columnId) | |
| if (!column) return | |
| setSelectedTable(table) | |
| snap.onEditColumn(column) | |
| }, | |
| }), | |
| [tables, snap] | |
| ) | |
| const columnEditionContext = useMemo<ColumnEditionContextType>( | |
| () => ({ | |
| onEditColumn: (tableId, columnId) => { | |
| if (!canUpdateTables || isSchemaLocked) return | |
| const table = tables.find((table) => table.id === tableId) | |
| if (!table || table.columns == null) return | |
| const column = table.columns.find((column) => column.id === columnId) | |
| if (!column) return | |
| setSelectedTable(table) | |
| snap.onEditColumn(column) | |
| }, | |
| }), | |
| [canUpdateTables, isSchemaLocked, tables, snap] | |
| ) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx` around
lines 215 - 227, The new onEditColumn entry in columnEditionContext bypasses the
existing write guards and should be blocked when edits are not allowed; modify
the onEditColumn implementation to check the existing canUpdateTables and
isSchemaLocked flags (computed earlier in the component) before proceeding: if
!canUpdateTables or isSchemaLocked return early; otherwise locate the
table/column as now, call setSelectedTable(table) and snap.onEditColumn(column).
Ensure you reference the same variables (canUpdateTables, isSchemaLocked,
columnEditionContext, onEditColumn, setSelectedTable, snap.onEditColumn) so the
hover action respects schema write/lock rules.
| const isFirstLoad = useRef(true) | ||
| useEffect(() => { | ||
| if (isSuccessTables && isSuccessSchemas && tables.length > 0) { | ||
| const schema = schemas.find((s) => s.name === selectedSchema) as PostgresSchema | ||
| getGraphDataFromTables(ref as string, schema, tables).then(({ nodes, edges }) => { | ||
| reactFlowInstance.setNodes(nodes) | ||
| reactFlowInstance.setEdges(edges) | ||
| setTimeout(() => reactFlowInstance.fitView({})) // it needs to happen during next event tick | ||
| // Prevent resetting a view after first load to avoid layout changes after editing a column | ||
| if (isFirstLoad.current) { | ||
| isFirstLoad.current = false | ||
| setTimeout(() => reactFlowInstance.fitView({})) // it needs to happen during next event tick | ||
| } | ||
| }) | ||
| } | ||
| }, [isSuccessTables, isSuccessSchemas, tables, resolvedTheme]) |
| onEditColumn: (tableId, columnId) => { | ||
| const table = tables.find((table) => table.id === tableId) | ||
| if (!table || table.columns == null) return | ||
| const column = table.columns.find((column) => column.id === columnId) |
There was a problem hiding this comment.
nit: spacing here, it cleans it up a bit
| await page.getByRole('button', { name: 'View saml_providers', exact: true }).click() | ||
| }) | ||
|
|
||
| test('columns actions work as expected', async ({ page, ref }) => { |
There was a problem hiding this comment.
♻️ Duplicate comments (1)
apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx (1)
215-229:⚠️ Potential issue | 🟠 MajorGuard
onEditColumnwith permission checks.The
onEditColumnhandler bypasses the existingcanUpdateTablesandisSchemaLockedchecks that protect other edit actions in this component. Users without write permissions or accessing protected schemas can trigger the column editor.Proposed fix
const columnEditionContext = useMemo<ColumnEditionContextType>( () => ({ onEditColumn: (tableId, columnId) => { + if (!canUpdateTables || isSchemaLocked) return const table = tables.find((table) => table.id === tableId) if (!table || table.columns == null) return const column = table.columns.find((column) => column.id === columnId) if (!column) return setSelectedTable(table) snap.onEditColumn(column) }, }), - [tables, snap] + [canUpdateTables, isSchemaLocked, tables, snap] )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx` around lines 215 - 229, The onEditColumn handler inside columnEditionContext must enforce the same permission and lock checks as other edit flows: before finding the table/column, check canUpdateTables() and !isSchemaLocked(), and return early if the user cannot edit; only then call setSelectedTable(table) and snap.onEditColumn(column). Update the columnEditionContext closure (the onEditColumn function) to reference the existing canUpdateTables and isSchemaLocked helpers so unauthorized or locked-schema users cannot open the column editor.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx`:
- Around line 215-229: The onEditColumn handler inside columnEditionContext must
enforce the same permission and lock checks as other edit flows: before finding
the table/column, check canUpdateTables() and !isSchemaLocked(), and return
early if the user cannot edit; only then call setSelectedTable(table) and
snap.onEditColumn(column). Update the columnEditionContext closure (the
onEditColumn function) to reference the existing canUpdateTables and
isSchemaLocked helpers so unauthorized or locked-schema users cannot open the
column editor.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 9816c535-6c6c-4106-bb0d-d63934317b9d
📒 Files selected for processing (3)
apps/studio/components/interfaces/Database/Schemas/ColumnEditionContext.tsxapps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsxapps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx
Braintrust eval report
|
## Problem Editing a column from the schema visualiser requires many clicks ## Solution When hovering over a column in the schema visualiser, an edit button should appear on the right side. Clicking this button should open the column edit pane on the right side of the screen. This would reduce the number of clicks required and allow users to make edits directly from the visualiser instead of using it only as a visual aid.

Problem
Editing a column from the schema visualiser requires many clicks
Solution
When hovering over a column in the schema visualiser, an edit button should appear on the right side. Clicking this button should open the column edit pane on the right side of the screen. This would reduce the number of clicks required and allow users to make edits directly from the visualiser instead of using it only as a visual aid.