Skip to content

Commit 6068ba7

Browse files
grejgreg
andauthored
Add cell toolbar multi-actions with clear outputs and delete cell (#208)
* fixed issue 126. must be paired with update to runt * format clean up for failed test --------- Co-authored-by: greg <greg@gregs-MacBook-Pro.local>
1 parent 7bbb5ff commit 6068ba7

4 files changed

Lines changed: 76 additions & 9 deletions

File tree

src/components/notebook/AiCell.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ export const AiCell: React.FC<AiCellProps> = ({
6464
mobileStyle: "chat-bubble",
6565
});
6666

67+
const clearCellOutputs = useCallback(async () => {
68+
if (hasOutputs) {
69+
store.commit(
70+
events.cellOutputsCleared({
71+
cellId: cell.id,
72+
wait: false,
73+
clearedBy: "current-user",
74+
})
75+
);
76+
}
77+
}, [cell.id, store, hasOutputs]);
78+
6779
const executeAiPrompt = useCallback(async () => {
6880
// Use localSource instead of cell.source to get the current typed content
6981
const sourceToExecute = localSource || cell.source;
@@ -244,6 +256,8 @@ export const AiCell: React.FC<AiCellProps> = ({
244256
onMoveUp={onMoveUp}
245257
onMoveDown={onMoveDown}
246258
onDeleteCell={onDeleteCell}
259+
onClearOutputs={clearCellOutputs}
260+
hasOutputs={hasOutputs}
247261
toggleSourceVisibility={toggleSourceVisibility}
248262
toggleAiContextVisibility={toggleAiContextVisibility}
249263
playButton={

src/components/notebook/Cell.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ export const Cell: React.FC<CellProps> = ({
106106
);
107107
}, [cell.id, cell.aiContextVisible, store]);
108108

109+
const clearCellOutputs = useCallback(async () => {
110+
if (hasOutputs) {
111+
store.commit(
112+
events.cellOutputsCleared({
113+
cellId: cell.id,
114+
wait: false,
115+
clearedBy: "current-user",
116+
})
117+
);
118+
}
119+
}, [cell.id, store, hasOutputs]);
120+
109121
const executeCell = useCallback(async () => {
110122
// Use localSource instead of cell.source to get the current typed content
111123
const sourceToExecute = localSource || cell.source;
@@ -321,6 +333,8 @@ export const Cell: React.FC<CellProps> = ({
321333
onMoveUp={onMoveUp}
322334
onMoveDown={onMoveDown}
323335
onDeleteCell={onDeleteCell}
336+
onClearOutputs={clearCellOutputs}
337+
hasOutputs={hasOutputs}
324338
toggleSourceVisibility={toggleSourceVisibility}
325339
toggleAiContextVisibility={toggleAiContextVisibility}
326340
playButton={

src/components/notebook/SqlCell.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ export const SqlCell: React.FC<SqlCellProps> = ({
8080
);
8181
}, [localQuery, cell.id, cell.executionCount, store]);
8282

83+
const clearCellOutputs = useCallback(async () => {
84+
if (hasOutputs) {
85+
store.commit(
86+
events.cellOutputsCleared({
87+
cellId: cell.id,
88+
wait: false,
89+
clearedBy: "current-user",
90+
})
91+
);
92+
}
93+
}, [cell.id, store, hasOutputs]);
94+
8395
const interruptQuery = useCallback(() => {
8496
// Find the current execution in the queue for this cell
8597
const executionQueue = store.query(
@@ -198,6 +210,8 @@ export const SqlCell: React.FC<SqlCellProps> = ({
198210
onMoveUp={onMoveUp}
199211
onMoveDown={onMoveDown}
200212
onDeleteCell={onDeleteCell}
213+
onClearOutputs={clearCellOutputs}
214+
hasOutputs={hasOutputs}
201215
toggleSourceVisibility={toggleSourceVisibility}
202216
toggleAiContextVisibility={toggleAiContextVisibility}
203217
playButton={

src/components/notebook/shared/CellControls.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import React from "react";
22
import { Button } from "@/components/ui/button";
3+
import {
4+
DropdownMenu,
5+
DropdownMenuContent,
6+
DropdownMenuItem,
7+
DropdownMenuTrigger,
8+
} from "@/components/ui/dropdown-menu";
39
import {
410
Plus,
511
ChevronUp,
@@ -9,6 +15,8 @@ import {
915
ArrowUp,
1016
ArrowDown,
1117
X,
18+
MoreVertical,
19+
Eraser,
1220
} from "lucide-react";
1321
import { tables } from "@runt/schema";
1422

@@ -19,6 +27,8 @@ interface CellControlsProps {
1927
onMoveUp: () => void;
2028
onMoveDown: () => void;
2129
onDeleteCell: () => void;
30+
onClearOutputs: () => void;
31+
hasOutputs: boolean;
2232
toggleSourceVisibility: () => void;
2333
toggleAiContextVisibility?: () => void;
2434
playButton?: React.ReactNode;
@@ -31,6 +41,8 @@ export const CellControls: React.FC<CellControlsProps> = ({
3141
onMoveUp,
3242
onMoveDown,
3343
onDeleteCell,
44+
onClearOutputs,
45+
hasOutputs,
3446
toggleSourceVisibility,
3547
toggleAiContextVisibility,
3648
playButton,
@@ -113,15 +125,28 @@ export const CellControls: React.FC<CellControlsProps> = ({
113125
>
114126
<ArrowDown className="h-3 w-3" />
115127
</Button>
116-
<Button
117-
variant="ghost"
118-
size="sm"
119-
onClick={onDeleteCell}
120-
className="hover:bg-muted/80 h-7 w-7 p-0 text-red-500 hover:text-red-600"
121-
title="Delete cell"
122-
>
123-
<X className="h-3 w-3" />
124-
</Button>
128+
<DropdownMenu>
129+
<DropdownMenuTrigger asChild>
130+
<Button
131+
variant="ghost"
132+
size="sm"
133+
className="hover:bg-muted/80 h-7 w-7 p-0"
134+
title="More options"
135+
>
136+
<MoreVertical className="h-3 w-3" />
137+
</Button>
138+
</DropdownMenuTrigger>
139+
<DropdownMenuContent align="end">
140+
<DropdownMenuItem onClick={onClearOutputs} disabled={!hasOutputs}>
141+
<Eraser className="mr-2 h-4 w-4" />
142+
<span>Clear outputs</span>
143+
</DropdownMenuItem>
144+
<DropdownMenuItem onClick={onDeleteCell} variant="destructive">
145+
<X className="mr-2 h-4 w-4" />
146+
<span>Delete cell</span>
147+
</DropdownMenuItem>
148+
</DropdownMenuContent>
149+
</DropdownMenu>
125150
</div>
126151
</div>
127152
);

0 commit comments

Comments
 (0)