Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

add send button, and clean styles of AI buttons (#7445)

Shahmir Varqha60449ab0a679
diff --git a/frontend/src/components/editor/ai/add-cell-with-ai.tsx b/frontend/src/components/editor/ai/add-cell-with-ai.tsx
index e8c1c9df8a..ac9ed0c2c3 100644
--- a/frontend/src/components/editor/ai/add-cell-with-ai.tsx
+++ b/frontend/src/components/editor/ai/add-cell-with-ai.tsx
@@ -56,10 +56,7 @@ import { prettyError } from "@/utils/errors";
import { jotaiJsonStorage } from "@/utils/storage/jotai";
import { ZodLocalStorage } from "@/utils/storage/typed";
import { PythonIcon } from "../cell/code/icons";
-import {
- CompletionActions,
- createAiCompletionOnKeydown,
-} from "./completion-handlers";
+import { createAiCompletionOnKeydown } from "./completion-handlers";
import { CONTEXT_TRIGGER, mentionsCompletionSource } from "./completion-utils";
import { StreamingChunkTransport } from "./transport/chat-transport";
@@ -151,7 +148,6 @@ export const AddCellWithAI: React.FC<{
const isLoading = status === "streaming" || status === "submitted";
const hasCompletion = stagedAICells.size > 0;
- const multipleCompletions = stagedAICells.size > 1;
const submit = () => {
if (!isLoading) {
@@ -256,29 +252,20 @@ export const AddCellWithAI: React.FC<{
);
return (
- <div className={cn("flex flex-col w-full gap-2 py-2")}>
+ <div className={cn("flex flex-col w-full py-2")}>
{inputComponent}
<div className="flex flex-row justify-between -mt-1 ml-1 mr-3">
{!hasCompletion && (
- <span className="text-xs text-muted-foreground px-3 flex flex-col gap-1">
+ <span className="text-xs text-muted-foreground px-3 flex flex-col gap-1 mt-2">
<span>
You can mention{" "}
<span className="text-(--cyan-11)">@dataframe</span> or{" "}
<span className="text-(--cyan-11)">@sql_table</span> to pull
- additional context such as column names.
+ additional context such as column names. Code from other cells is
+ automatically included.
</span>
- <span>Code from other cells is automatically included.</span>
</span>
)}
- {hasCompletion && (
- <CompletionActions
- isLoading={isLoading}
- onAccept={handleAcceptCompletion}
- onDecline={handleDeclineCompletion}
- size="sm"
- multipleCompletions={multipleCompletions}
- />
- )}
<div className="ml-auto flex items-center gap-1">
{languageDropdown}
<AIModelDropdown
diff --git a/frontend/src/components/editor/ai/ai-completion-editor.tsx b/frontend/src/components/editor/ai/ai-completion-editor.tsx
index 7fa8318aa2..ec3fddf180 100644
--- a/frontend/src/components/editor/ai/ai-completion-editor.tsx
+++ b/frontend/src/components/editor/ai/ai-completion-editor.tsx
@@ -6,6 +6,7 @@ import {
AtSignIcon,
CircleCheckIcon,
Loader2Icon,
+ SendIcon,
SparklesIcon,
XIcon,
} from "lucide-react";
@@ -38,7 +39,6 @@ import { retryWithTimeout } from "@/utils/timeout";
import { PromptInput } from "./add-cell-with-ai";
import {
AcceptCompletionButton,
- CompletionActions,
createAiCompletionOnKeydown,
RejectCompletionButton,
} from "./completion-handlers";
@@ -253,6 +253,60 @@ export const AiCompletionEditor: React.FC<Props> = ({
}
};
+ const loadingStopButton = (
+ <Button
+ data-testid="stop-completion-button"
+ variant="text"
+ size="xs"
+ className="mb-0"
+ onClick={stop}
+ >
+ <Loader2Icon className="animate-spin mr-1" size={14} />
+ Stop
+ </Button>
+ );
+
+ const submitButton = (
+ <Tooltip content="Submit">
+ <Button variant="text" size="icon" onClick={handleSubmit}>
+ <SendIcon className="h-3 w-3" />
+ </Button>
+ </Tooltip>
+ );
+
+ const contextButton = (
+ <Tooltip content="Add context">
+ <Button
+ variant="text"
+ size="icon"
+ onClick={() => addContextCompletion(inputRef)}
+ >
+ <AtSignIcon className="h-3 w-3" />
+ </Button>
+ </Tooltip>
+ );
+
+ const completionButtons = (
+ <>
+ <AcceptCompletionButton
+ isLoading={isLoading}
+ onAccept={handleAcceptCompletion}
+ size="xs"
+ multipleCompletions={false}
+ acceptShortcut="Mod-↵"
+ runCell={runCell}
+ borderless={true}
+ />
+ <RejectCompletionButton
+ onDecline={handleDeclineCompletion}
+ size="xs"
+ multipleCompletions={false}
+ declineShortcut="Shift-Mod-Delete"
+ borderless={true}
+ />
+ </>
+ );
+
return (
<div
data-ai-input-open={showInput}
@@ -295,43 +349,22 @@ export const AiCompletionEditor: React.FC<Props> = ({
hasCompletion: completion.trim().length > 0,
})}
/>
- {isLoading && (
- <Button
- data-testid="stop-completion-button"
- variant="text"
- size="xs"
- className="mb-0"
- onClick={stop}
- >
- <Loader2Icon className="animate-spin mr-1" size={14} />
- Stop
- </Button>
- )}
+
<div className="-mr-1.5 py-1.5">
<div className="flex flex-row items-center justify-end gap-0.5">
- <Tooltip content="Add context">
- <Button
- variant="text"
- size="icon"
- onClick={() => addContextCompletion(inputRef)}
- >
- <AtSignIcon className="h-3 w-3" />
- </Button>
- </Tooltip>
+ {isLoading && loadingStopButton}
+ {submitButton}
+ {contextButton}
<AIModelDropdown
- triggerClassName="h-7 text-xs w-24"
+ triggerClassName="h-7 text-xs"
iconSize="small"
forRole="edit"
+ displayIconOnly={true}
/>
</div>
{completion && (
- <div className="-mb-1.5">
- <CompletionActions
- isLoading={isLoading}
- onAccept={handleAcceptCompletion}
- onDecline={handleDeclineCompletion}
- size="xs"
- />
+ <div className="mt-1 flex items-center gap-1">
+ {completionButtons}
</div>
)}
</div>
@@ -351,7 +384,7 @@ export const AiCompletionEditor: React.FC<Props> = ({
htmlFor={includeOtherCellsCheckboxId}
className="text-muted-foreground text-xs whitespace-nowrap ellipsis"
>
- Include all code
+ All code
</Label>
</div>
</Tooltip>
@@ -450,15 +483,14 @@ const CompletionBanner: React.FC<CompletionBannerProps> = ({
isLoading={isLoading}
onAccept={onAccept}
size="xs"
- buttonStyles="border-none rounded-md rounded-r-none"
- playButtonStyles="border-0 border-l-1 rounded-md rounded-l-none"
+ borderless={true}
runCell={runCell}
// acceptShortcut="Mod-↵"
/>
<RejectCompletionButton
onDecline={onReject}
size="xs"
- className="border-none rounded-md"
+ borderless={true}
// declineShortcut="Shift-Mod-Delete"
/>
</div>
diff --git a/frontend/src/components/editor/ai/completion-handlers.tsx b/frontend/src/components/editor/ai/completion-handlers.tsx
index eeadb28174..3d469733f4 100644
--- a/frontend/src/components/editor/ai/completion-handlers.tsx
+++ b/frontend/src/components/editor/ai/completion-handlers.tsx
@@ -41,57 +41,6 @@ export const createAiCompletionOnKeydown = (opts: {
};
};
-/**
- * Common completion action buttons with keyboard shortcuts
- */
-export const CompletionActions: React.FC<{
- isLoading: boolean;
- onAccept: () => void;
- onDecline: () => void;
- size?: "xs" | "sm";
- acceptShortcut?: string;
- declineShortcut?: string;
- multipleCompletions?: boolean;
-}> = ({
- isLoading,
- onAccept,
- onDecline,
- size = "sm",
- acceptShortcut = "Mod-↵",
- declineShortcut = "Shift-Mod-Delete",
- multipleCompletions = false,
-}) => {
- return (
- <>
- <Button
- data-testid="accept-completion-button"
- variant="text"
- size={size}
- className="mb-0"
- disabled={isLoading}
- onClick={onAccept}
- >
- <span className="text-(--grass-11) opacity-100">
- Accept{multipleCompletions && " all"}{" "}
- <MinimalHotkeys className="ml-1 inline" shortcut={acceptShortcut} />
- </span>
- </Button>
- <Button
- data-testid="decline-completion-button"
- variant="text"
- size={size}
- className="mb-0 pl-1 pr-0"
- onClick={onDecline}
- >
- <span className="text-(--red-10)">
- Reject{multipleCompletions && " all"}{" "}
- <MinimalHotkeys className="ml-1 inline" shortcut={declineShortcut} />
- </span>
- </Button>
- </>
- );
-};
-
export const CompletionActionsCellFooter: React.FC<{
isLoading: boolean;
onAccept: () => void;
@@ -120,6 +69,7 @@ export const AcceptCompletionButton: React.FC<{
size?: "xs" | "sm";
buttonStyles?: string;
playButtonStyles?: string;
+ borderless?: boolean;
acceptShortcut?: string;
runCell?: () => void;
}> = ({
@@ -131,6 +81,7 @@ export const AcceptCompletionButton: React.FC<{
acceptShortcut,
runCell,
playButtonStyles,
+ borderless = false,
}) => {
const handleAcceptAndRun = () => {
onAccept();
@@ -154,7 +105,7 @@ export const AcceptCompletionButton: React.FC<{
size={size}
disabled={isLoading}
onClick={onAccept}
- className={`${baseClasses} rounded-r-none ${buttonStyles}`}
+ className={`${baseClasses} rounded-r-none ${borderless && "border-none rounded-md rounded-r-none"} ${buttonStyles}`}
>
{text}
{acceptShortcut && (
@@ -173,7 +124,7 @@ export const AcceptCompletionButton: React.FC<{
size={size}
disabled={isLoading}
onClick={handleAcceptAndRun}
- className={`${baseClasses} rounded-l-none px-1.5 ${playButtonStyles}`}
+ className={`${baseClasses} rounded-l-none px-1.5 ${borderless && "border-0 border-l-1"} ${playButtonStyles}`}
>
<PlayIcon className="h-2.5 w-2.5" />
</Button>
@@ -203,6 +154,7 @@ export const RejectCompletionButton: React.FC<{
multipleCompletions?: boolean;
size?: "xs" | "sm";
className?: string;
+ borderless?: boolean;
declineShortcut?: string;
}> = ({
onDecline,
@@ -210,6 +162,7 @@ export const RejectCompletionButton: React.FC<{
size = "sm",
className,
declineShortcut,
+ borderless = false,
}) => {
return (
<Button
@@ -219,7 +172,7 @@ export const RejectCompletionButton: React.FC<{
className={`h-6 text-(--red-10) bg-(--red-3)/60 hover:bg-(--red-3)
dark:bg-(--red-4)/80 dark:hover:bg-(--red-3) rounded px-3 font-semibold
active:bg-(--red-5) dark:active:bg-(--red-4)
- border-(--red-6) border hover:shadow-xs ${className}`}
+ border-(--red-6) border hover:shadow-xs ${borderless && "border-none rounded-md"} ${className}`}
>
Reject{multipleCompletions && " all"}
{declineShortcut && (