Repository navigation
feat(web): replace code snippet generation with CLI setup instructions (#78) #230
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,207 @@ | ||
| import { Dialog } from "@headlessui/react"; | ||
| import { cn } from "lib/utils"; | ||
| import { useProjectId } from "lib/hooks/useProjectId"; | ||
| import { useTracking } from "lib/tracking"; | ||
| import { Code, Copy } from "lucide-react"; | ||
| import { useRouter } from "next/router"; | ||
| import { Check, Copy, ExternalLink, Terminal } from "lucide-react"; | ||
| import { useState } from "react"; | ||
| import { toast } from "react-hot-toast"; | ||
| import { BsCodeSlash } from "react-icons/bs"; | ||
| import { CodeSnippet } from "./CodeSnippet"; | ||
| import { | ||
| DropdownMenu, | ||
| DropdownMenuContent, | ||
| DropdownMenuItem, | ||
| DropdownMenuTrigger, | ||
| } from "./DropdownMenu"; | ||
| import { Button } from "./ui/button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "./ui/dialog"; | ||
|
|
||
| function CodeSnippetModal({ | ||
| function CliInstructionsModal({ | ||
| isOpen, | ||
| onClose, | ||
| }: { | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| }) { | ||
| const projectId = useRouter().query.projectId as string; | ||
| const [copiedIndex, setCopiedIndex] = useState<number | null>(null); | ||
| const [packageManager, setPackageManager] = useState<"npm" | "pnpm" | "yarn">( | ||
| "npm" | ||
| ); | ||
|
|
||
| const copyToClipboard = (text: string, index: number) => { | ||
| navigator.clipboard.writeText(text); | ||
| setCopiedIndex(index); | ||
| toast.success("Copied to clipboard!"); | ||
| setTimeout(() => setCopiedIndex(null), 2000); | ||
| }; | ||
|
|
||
| const installCommands = { | ||
| npm: "npm i -g @tryabby/cli", | ||
| pnpm: "pnpm i -g @tryabby/cli", | ||
| yarn: "yarn add -g @tryabby/cli", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Yarn's global installation command. When users select yarn, both the displayed command and the copied command use
|
||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open={isOpen} onClose={onClose} className="relative z-50"> | ||
| {/* The backdrop, rendered as a fixed sibling to the panel container */} | ||
| <div className="fixed inset-0 bg-black/70" aria-hidden="true" /> | ||
| <Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}> | ||
| <DialogContent className="max-w-xl border-zinc-800 bg-zinc-950 p-6 text-zinc-100 sm:rounded-xl"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Limit the dialog height and enable vertical scrolling. On a short viewport, such as 640×360, the four-step dialog extends above and below the screen. The shared
|
||
| <DialogHeader> | ||
| <div className="flex items-center space-x-2"> | ||
| <Terminal className="h-5 w-5 text-pink-500" /> | ||
| <DialogTitle className="text-xl font-bold text-white"> | ||
| Abby CLI Instructions | ||
| </DialogTitle> | ||
| </div> | ||
| <DialogDescription className="text-zinc-400"> | ||
| Configure feature flags, remote configs, and A/B tests directly from | ||
| your terminal. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <div className="mt-4 space-y-3"> | ||
| {/* Step 1: Install */} | ||
| <div className="rounded-lg border border-zinc-800 bg-zinc-900/60 p-3.5"> | ||
| <div className="mb-2 flex items-center justify-between"> | ||
| <span className="text-sm font-semibold text-zinc-200"> | ||
| 1. Install the CLI | ||
| </span> | ||
| <div className="flex space-x-1 rounded-md bg-zinc-800 p-0.5"> | ||
| {(["npm", "pnpm", "yarn"] as const).map((pm) => ( | ||
| <button | ||
| key={pm} | ||
| type="button" | ||
| onClick={() => setPackageManager(pm)} | ||
| className={cn( | ||
| "rounded px-2 py-0.5 text-xs font-medium transition-colors", | ||
| packageManager === pm | ||
| ? "bg-zinc-700 text-white" | ||
| : "text-zinc-400 hover:text-zinc-200" | ||
| )} | ||
| > | ||
| {pm} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| <div className="flex items-center justify-between rounded bg-zinc-950 px-3 py-2 font-mono text-sm text-zinc-300"> | ||
| <code>{installCommands[packageManager]}</code> | ||
| <button | ||
| type="button" | ||
| onClick={() => | ||
| copyToClipboard(installCommands[packageManager], 1) | ||
| } | ||
| className="ml-2 text-zinc-400 transition-colors hover:text-white" | ||
| title="Copy command" | ||
| > | ||
| {copiedIndex === 1 ? ( | ||
| <Check className="h-4 w-4 text-green-400" /> | ||
| ) : ( | ||
| <Copy className="h-4 w-4" /> | ||
| )} | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Step 2: Login */} | ||
| <div className="rounded-lg border border-zinc-800 bg-zinc-900/60 p-3.5"> | ||
| <div className="mb-2 flex items-center justify-between"> | ||
| <span className="text-sm font-semibold text-zinc-200"> | ||
| 2. Authenticate | ||
| </span> | ||
| <span className="text-xs text-zinc-500"> | ||
| Requires API key from profile | ||
| </span> | ||
| </div> | ||
| <div className="flex items-center justify-between rounded bg-zinc-950 px-3 py-2 font-mono text-sm text-zinc-300"> | ||
| <code>abby login</code> | ||
| <button | ||
| type="button" | ||
| onClick={() => copyToClipboard("abby login", 2)} | ||
| className="ml-2 text-zinc-400 transition-colors hover:text-white" | ||
| title="Copy command" | ||
| > | ||
| {copiedIndex === 2 ? ( | ||
| <Check className="h-4 w-4 text-green-400" /> | ||
| ) : ( | ||
| <Copy className="h-4 w-4" /> | ||
| )} | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Step 3: Initialize */} | ||
| <div className="rounded-lg border border-zinc-800 bg-zinc-900/60 p-3.5"> | ||
| <div className="mb-2 flex items-center justify-between"> | ||
| <span className="text-sm font-semibold text-zinc-200"> | ||
| 3. Initialize configuration | ||
| </span> | ||
| <span className="text-xs text-zinc-500"> | ||
| Creates abby.config.ts | ||
| </span> | ||
| </div> | ||
| <div className="flex items-center justify-between rounded bg-zinc-950 px-3 py-2 font-mono text-sm text-zinc-300"> | ||
| <code>abby init</code> | ||
| <button | ||
| type="button" | ||
| onClick={() => copyToClipboard("abby init", 3)} | ||
| className="ml-2 text-zinc-400 transition-colors hover:text-white" | ||
| title="Copy command" | ||
| > | ||
| {copiedIndex === 3 ? ( | ||
| <Check className="h-4 w-4 text-green-400" /> | ||
| ) : ( | ||
| <Copy className="h-4 w-4" /> | ||
| )} | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Step 4: Push */} | ||
| <div className="rounded-lg border border-zinc-800 bg-zinc-900/60 p-3.5"> | ||
| <div className="mb-2 flex items-center justify-between"> | ||
| <span className="text-sm font-semibold text-zinc-200"> | ||
| 4. Synchronize changes | ||
| </span> | ||
| <span className="text-xs text-zinc-500"> | ||
| Pushes flags & tests to Abby | ||
| </span> | ||
| </div> | ||
| <div className="flex items-center justify-between rounded bg-zinc-950 px-3 py-2 font-mono text-sm text-zinc-300"> | ||
| <code>abby push</code> | ||
| <button | ||
| type="button" | ||
| onClick={() => copyToClipboard("abby push", 4)} | ||
| className="ml-2 text-zinc-400 transition-colors hover:text-white" | ||
| title="Copy command" | ||
| > | ||
| {copiedIndex === 4 ? ( | ||
| <Check className="h-4 w-4 text-green-400" /> | ||
| ) : ( | ||
| <Copy className="h-4 w-4" /> | ||
| )} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Full-screen container to center the panel */} | ||
| <div className="fixed inset-0 flex items-center justify-center p-4"> | ||
| {/* The actual dialog panel */} | ||
| <Dialog.Panel className="mx-auto w-full max-w-4xl"> | ||
| <CodeSnippet projectId={projectId} /> | ||
| </Dialog.Panel> | ||
| </div> | ||
| <div className="mt-4 flex items-center justify-between border-t border-zinc-800 pt-4 text-sm text-zinc-400"> | ||
| <a | ||
| href="https://docs.tryabby.com/reference/cli" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="flex items-center text-pink-400 transition-colors hover:text-pink-300" | ||
| > | ||
| Read CLI Documentation | ||
| <ExternalLink className="ml-1.5 h-3.5 w-3.5" /> | ||
| </a> | ||
| <Button variant="secondary" size="sm" onClick={onClose}> | ||
| Close | ||
| </Button> | ||
| </div> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
|
|
@@ -57,12 +223,11 @@ export function CodeSnippetModalButton() { | |
| <DropdownMenu> | ||
| <DropdownMenuTrigger | ||
| asChild | ||
| // all other events are prevented by radix :( | ||
| onPointerDown={() => { | ||
| trackEvent("Dashboard Code Clicked"); | ||
| }} | ||
| > | ||
| <Button size="icon" variant="secondary" title=""> | ||
| <Button size="icon" variant="secondary" title="CLI & Project Details"> | ||
| <BsCodeSlash size={20} /> | ||
| </Button> | ||
| </DropdownMenuTrigger> | ||
|
|
@@ -72,11 +237,14 @@ export function CodeSnippetModalButton() { | |
| Copy Project ID | ||
| </DropdownMenuItem> | ||
| <DropdownMenuItem onClick={() => setIsOpen(true)}> | ||
| <Code className="mr-2 h-4 w-4" /> | ||
| Generate Code Snippet | ||
| <Terminal className="mr-2 h-4 w-4" /> | ||
| CLI Instructions | ||
| </DropdownMenuItem> | ||
| </DropdownMenuContent> | ||
| <CodeSnippetModal isOpen={isOpen} onClose={() => setIsOpen(false)} /> | ||
| <CliInstructionsModal | ||
| isOpen={isOpen} | ||
| onClose={() => setIsOpen(false)} | ||
| /> | ||
|
Comment on lines
+244
to
+247
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restore focus to the dashboard control when the CLI Instructions dialog closes.
Record the focused element in the dialog's
|
||
| </DropdownMenu> | ||
| ); | ||
| } | ||
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.
Show copy success only after the clipboard write succeeds.
If clipboard permission is denied,
writeTextrejects its promise. This helper still shows a checkmark and a success toast, although the clipboard retains its previous contents. Await the write and show error feedback on rejection, or use the existingtoast.promisepattern. (w3c.github.io)Based on learnings, preserve observable failures from asynchronous clipboard helpers.
Source: Learnings