-
Notifications
You must be signed in to change notification settings - Fork 11
feat(code): use Quill Chip for mention chips + PromptInput story #1756
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
Merged
+389
−33
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b894174
chore: prompt inputs are now quill chips, went for bare DOM instead o…
adamleithp 6900f42
update prompt input chips to use quill, rebuilt prompt input storyboo…
adamleithp 13e417a
fix: revert pastedText interface change, keep visual-only in story
adamleithp 585664e
fix: prevent duplicate chip insertion on story re-render
adamleithp 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
283 changes: 283 additions & 0 deletions
283
apps/code/src/renderer/features/message-editor/components/PromptInput.stories.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,283 @@ | ||
| import type { SessionConfigOption } from "@agentclientprotocol/sdk"; | ||
| import { Providers } from "@components/Providers"; | ||
| import { ReasoningLevelSelector } from "@features/sessions/components/ReasoningLevelSelector"; | ||
| import { UnifiedModelSelector } from "@features/sessions/components/UnifiedModelSelector"; | ||
| import type { AgentAdapter } from "@features/settings/stores/settingsStore"; | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import type { EditorHandle } from "../types"; | ||
| import type { MentionChip } from "../utils/content"; | ||
| import { PromptInput } from "./PromptInput"; | ||
|
|
||
| // --- Mock data matching SessionConfigOption shape --- | ||
|
|
||
| const mockModelOption = { | ||
| id: "model", | ||
| name: "Model", | ||
| type: "select" as const, | ||
| currentValue: "gpt-5.4", | ||
| options: [ | ||
| { | ||
| group: "recommended", | ||
| name: "Recommended", | ||
| options: [ | ||
| { value: "gpt-5.4", name: "GPT 5.4" }, | ||
| { value: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" }, | ||
| ], | ||
| }, | ||
| { | ||
| group: "other", | ||
| name: "Other", | ||
| options: [ | ||
| { value: "claude-opus-4-6", name: "Claude Opus 4.6" }, | ||
| { value: "o3-pro", name: "o3-pro" }, | ||
| { value: "claude-haiku-4-5", name: "Claude Haiku 4.5" }, | ||
| ], | ||
| }, | ||
| ], | ||
| } satisfies SessionConfigOption; | ||
|
|
||
| const mockReasoningOption = { | ||
| id: "thought", | ||
| name: "Reasoning", | ||
| type: "select" as const, | ||
| currentValue: "high", | ||
| options: [ | ||
| { value: "off", name: "Off" }, | ||
| { value: "low", name: "Low" }, | ||
| { value: "medium", name: "Medium" }, | ||
| { value: "high", name: "High" }, | ||
| ], | ||
| } satisfies SessionConfigOption; | ||
|
|
||
| // --- Wrapper to inject chips after mount --- | ||
|
|
||
| function PromptInputWithChips({ | ||
| chips, | ||
| ...props | ||
| }: React.ComponentProps<typeof PromptInput> & { chips?: MentionChip[] }) { | ||
| const ref = useRef<EditorHandle>(null); | ||
| const insertedRef = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| if (!chips?.length || insertedRef.current) return; | ||
| insertedRef.current = true; | ||
| const timer = setTimeout(() => { | ||
| for (const chip of chips) { | ||
| ref.current?.insertChip(chip); | ||
| } | ||
| }, 200); | ||
| return () => clearTimeout(timer); | ||
| }, [chips]); | ||
|
|
||
| return <PromptInput ref={ref} {...props} />; | ||
| } | ||
|
|
||
| // --- Wrapper with stateful selectors --- | ||
|
|
||
| function PromptInputWithSelectors({ | ||
| chips, | ||
| showSelectors = true, | ||
| ...props | ||
| }: React.ComponentProps<typeof PromptInput> & { | ||
| chips?: MentionChip[]; | ||
| showSelectors?: boolean; | ||
| }) { | ||
| const [adapter, setAdapter] = useState<AgentAdapter>("claude"); | ||
| const [modelOption, setModelOption] = | ||
| useState<SessionConfigOption>(mockModelOption); | ||
| const [reasoningOption, setReasoningOption] = | ||
| useState<SessionConfigOption>(mockReasoningOption); | ||
|
|
||
| const handleModelChange = (value: string) => { | ||
| setModelOption({ ...mockModelOption, currentValue: value }); | ||
| }; | ||
|
|
||
| const handleReasoningChange = (value: string) => { | ||
| setReasoningOption({ ...mockReasoningOption, currentValue: value }); | ||
| }; | ||
|
|
||
| return ( | ||
| <PromptInputWithChips | ||
| chips={chips} | ||
| modelSelector={ | ||
| showSelectors ? ( | ||
| <UnifiedModelSelector | ||
| modelOption={modelOption} | ||
| adapter={adapter} | ||
| onAdapterChange={setAdapter} | ||
| onModelChange={handleModelChange} | ||
| /> | ||
| ) : ( | ||
| false | ||
| ) | ||
| } | ||
| reasoningSelector={ | ||
| showSelectors ? ( | ||
| <ReasoningLevelSelector | ||
| thoughtOption={reasoningOption} | ||
| adapter={adapter} | ||
| onChange={handleReasoningChange} | ||
| /> | ||
| ) : ( | ||
| false | ||
| ) | ||
| } | ||
| {...props} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| const meta: Meta<typeof PromptInputWithSelectors> = { | ||
| title: "Features/MessageEditor/PromptInput", | ||
| component: PromptInputWithSelectors, | ||
| parameters: { | ||
| layout: "padded", | ||
| }, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <Providers> | ||
| <div className="max-w-[800px]"> | ||
| <Story /> | ||
| </div> | ||
| </Providers> | ||
| ), | ||
| ], | ||
| args: { | ||
| sessionId: "storybook-session", | ||
| placeholder: "Type a message...", | ||
| disabled: false, | ||
| isLoading: false, | ||
| autoFocus: true, | ||
| isActiveSession: true, | ||
| enableBashMode: true, | ||
| enableCommands: true, | ||
| showSelectors: true, | ||
| onSubmit: () => {}, | ||
| onCancel: () => {}, | ||
| }, | ||
| argTypes: { | ||
| disabled: { control: "boolean" }, | ||
| isLoading: { control: "boolean" }, | ||
| enableBashMode: { control: "boolean" }, | ||
| enableCommands: { control: "boolean" }, | ||
| showSelectors: { control: "boolean" }, | ||
| placeholder: { control: "text" }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof PromptInputWithSelectors>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| export const WithFileChip: Story = { | ||
| name: "With File Chip", | ||
| args: { | ||
| chips: [ | ||
| { | ||
| type: "file", | ||
| id: "/src/settings.json", | ||
| label: ".claude/settings.json", | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| export const WithCommandChip: Story = { | ||
| name: "With Command Chip", | ||
| args: { | ||
| chips: [{ type: "command", id: "good", label: "good" }], | ||
| }, | ||
| }; | ||
|
|
||
| export const WithMultipleChips: Story = { | ||
| name: "With Multiple Chips", | ||
| args: { | ||
| chips: [ | ||
| { | ||
| type: "file", | ||
| id: "/src/settings.json", | ||
| label: ".claude/settings.json", | ||
| }, | ||
| { type: "command", id: "good", label: "good" }, | ||
| { | ||
| type: "file", | ||
| id: "/workflows/release.yml", | ||
| label: "workflows/agent-release.yml", | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| export const AllChipTypes: Story = { | ||
| name: "All Chip Types", | ||
| args: { | ||
| chips: [ | ||
| { type: "file", id: "/src/index.ts", label: "src/index.ts" }, | ||
| { type: "command", id: "review", label: "review" }, | ||
| { | ||
| type: "github_issue", | ||
| id: "https://github.com/org/repo/issues/123", | ||
| label: "#123 Fix the bug", | ||
| }, | ||
| { type: "error", id: "error-1", label: "TypeError: undefined" }, | ||
| { type: "experiment", id: "exp-1", label: "new-checkout-flow" }, | ||
| { type: "insight", id: "insight-1", label: "Weekly active users" }, | ||
| { type: "feature_flag", id: "flag-1", label: "enable-dark-mode" }, | ||
| { | ||
| type: "file", | ||
| id: "/tmp/pasted-content.txt", | ||
| label: "pasted-content.txt", | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| export const BashMode: Story = { | ||
| name: "Bash Mode (type ! to activate)", | ||
| args: { | ||
| enableBashMode: true, | ||
| placeholder: "Type ! to enter bash mode...", | ||
| }, | ||
| }; | ||
|
|
||
| export const Loading: Story = { | ||
| name: "Loading (With Cancel)", | ||
| args: { | ||
| isLoading: true, | ||
| }, | ||
| }; | ||
|
|
||
| export const Disabled: Story = { | ||
| args: { | ||
| disabled: true, | ||
| }, | ||
| }; | ||
|
|
||
| export const LongChipLabels: Story = { | ||
| name: "Long Chip Labels", | ||
| args: { | ||
| chips: [ | ||
| { | ||
| type: "file", | ||
| id: "/apps/code/src/renderer/features/message-editor/tiptap/MentionChipView.tsx", | ||
| label: | ||
| "apps/code/src/renderer/features/message-editor/tiptap/MentionChipView.tsx", | ||
| }, | ||
| { | ||
| type: "file", | ||
| id: "/packages/agent/src/adapters/claude/permissions/permission-options.ts", | ||
| label: | ||
| "packages/agent/src/adapters/claude/permissions/permission-options.ts", | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| export const NoToolbar: Story = { | ||
| name: "No Toolbar (Minimal)", | ||
| args: { | ||
| showSelectors: false, | ||
| }, | ||
| }; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useEffectruns wheneverchipsreference changes. In Storybook, switching between stories or toggling any control causes a full re-render with a newchipsarray reference, soinsertChipfires again for each chip already in the editor, producing duplicates. A stable reference (e.g.useRefguard or deep-equal comparison) would prevent this.Prompt To Fix With AI