Files
supabase/apps/studio/components/interfaces/Explorer/MoveCellDropdownContent.tsx
Joshen Lim 93d9d80535 joshen/fe 4149 explorer support adding removing cells in notebook (#49037)
## Context

Related to Explorer/Notebooks - this PR adds the functionality to add /
remove cells

Separately - am thinking we can shift a lot of the "cell update" logic
into notebook-state, mainly so that each UI component doesn't need to be
aware of the notebook's `cells` but just its own cell.

I'll do it separately though to prevent bloating this PR, already left
comments where i think can be refactored

<img width="250" alt="image"
src="https://github.com/user-attachments/assets/91aae5f9-07b9-4327-8e21-8e9d71098aa6"
/>
<img width="250" alt="image"
src="https://github.com/user-attachments/assets/677de208-5c52-4155-90c6-bc0879070693"
/>
<img width="250" alt="image"
src="https://github.com/user-attachments/assets/17c3dae7-87bc-40bb-bfa0-15df101006ce"
/>
<img width="1091" height="262" alt="image"
src="https://github.com/user-attachments/assets/a09c3d23-696a-4b55-a1f8-4602e56a60dc"
/>



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## New Features
- Add query and Markdown cells directly within notebooks.
- Move, remove, and reorder cells using drag-and-drop or cell controls.
- Add cells from empty states and notebook toolbar actions.
- Edit Markdown cells, mark edits as complete, and see placeholders for
empty content.

## Improvements
- Cell controls and hover interactions are more consistent and
responsive.
- Moving cells is disabled at the top or bottom of a notebook.
- Sample cells now use standardized content and formatting.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-14 00:17:29 +07:00

58 lines
1.8 KiB
TypeScript

import { ArrowDown, ArrowUp, Trash } from 'lucide-react'
import { DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator } from 'ui'
import { useCurrentNotebook, useNotebooksStateSnapshot } from '@/state/notebooks/notebooks-state'
interface MoveCellDropdownContentProps {
cellId: string
}
export const MoveCellDropdownContent = ({ cellId }: MoveCellDropdownContentProps) => {
const snap = useNotebooksStateSnapshot()
const currentNotebook = useCurrentNotebook()
const cells = currentNotebook?.notebook.content?.cells ?? []
const currentIndex = cells.findIndex((c) => c.id === cellId)
const isFirstCell = currentIndex <= 0
const isLastCell = currentIndex === -1 || currentIndex === cells.length - 1
const onSelectMoveCell = (direction: 'up' | 'down') => {
const notebookId = currentNotebook?.notebook.id
if (!notebookId) return
snap.moveCell({ id: notebookId, cellId, direction })
}
const onSelectRemoveCell = () => {
const notebookId = currentNotebook?.notebook.id
if (!notebookId) return
snap.removeCell({ id: notebookId, cellId })
}
return (
<DropdownMenuContent align="start" className="w-40">
<DropdownMenuItem
className="gap-x-2"
disabled={isFirstCell}
onClick={() => onSelectMoveCell('up')}
>
<ArrowUp size={14} />
<p>Move up</p>
</DropdownMenuItem>
<DropdownMenuItem
className="gap-x-2"
disabled={isLastCell}
onClick={() => onSelectMoveCell('down')}
>
<ArrowDown size={14} />
<p>Move down</p>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem className="gap-x-2" onClick={() => onSelectRemoveCell()}>
<Trash size={14} />
<p>Remove cell</p>
</DropdownMenuItem>
</DropdownMenuContent>
)
}