-
Notifications
You must be signed in to change notification settings - Fork 162
feat: add feature flag folders for organization #330
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
Closed
+520
−44
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
742e199
feat: add feature flag folders for organization (#271)
maoshuorz a2bbfe3
fix: resolve lint issues in flag folders feature
maoshuorz a81f4e4
fix: address review feedback on folder validation and UX
maoshuorz 8e56612
fix: align API folder filter with client-side hierarchical matching
maoshuorz 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
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
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
148 changes: 148 additions & 0 deletions
148
apps/dashboard/app/(main)/websites/[id]/flags/_components/folder-selector.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,148 @@ | ||
| "use client"; | ||
|
|
||
| import { FolderIcon, PlusIcon } from "@phosphor-icons/react"; | ||
| import { useMemo, useState } from "react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { | ||
| Popover, | ||
| PopoverContent, | ||
| PopoverTrigger, | ||
| } from "@/components/ui/popover"; | ||
| import { cn } from "@/lib/utils"; | ||
| import type { Flag } from "./types"; | ||
|
|
||
| const FOLDER_PATH_REGEX = /^[a-zA-Z0-9_\-/]*$/; | ||
|
|
||
| interface FolderSelectorProps { | ||
| value: string | null | undefined; | ||
| onChange: (folder: string | null) => void; | ||
| existingFlags: Flag[]; | ||
| } | ||
|
|
||
| export function FolderSelector({ | ||
| value, | ||
| onChange, | ||
| existingFlags, | ||
| }: FolderSelectorProps) { | ||
| const [open, setOpen] = useState(false); | ||
| const [newFolderInput, setNewFolderInput] = useState(""); | ||
|
|
||
| const existingFolders = useMemo(() => { | ||
| const folders = new Set<string>(); | ||
| for (const flag of existingFlags) { | ||
| if (flag.folder) { | ||
| folders.add(flag.folder); | ||
| // Also add parent folders | ||
| const parts = flag.folder.split("/"); | ||
| for (let i = 1; i < parts.length; i++) { | ||
| folders.add(parts.slice(0, i).join("/")); | ||
| } | ||
| } | ||
| } | ||
| return Array.from(folders).sort(); | ||
| }, [existingFlags]); | ||
|
|
||
| const handleSelect = (folder: string | null) => { | ||
| onChange(folder); | ||
| setOpen(false); | ||
| }; | ||
|
|
||
| const handleCreateFolder = () => { | ||
| const trimmed = newFolderInput.trim().replace(/^\/+|\/+$/g, ""); | ||
| if (trimmed && FOLDER_PATH_REGEX.test(trimmed)) { | ||
| onChange(trimmed); | ||
| setNewFolderInput(""); | ||
| setOpen(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Popover onOpenChange={setOpen} open={open}> | ||
| <PopoverTrigger asChild> | ||
| <Button | ||
| className={cn( | ||
| "w-full justify-start font-normal", | ||
| !value && "text-muted-foreground" | ||
| )} | ||
| type="button" | ||
| variant="outline" | ||
| > | ||
| <FolderIcon className="mr-2 size-4" weight="duotone" /> | ||
| {value || "No folder"} | ||
| </Button> | ||
| </PopoverTrigger> | ||
| <PopoverContent align="start" className="w-64 p-2"> | ||
| <div className="space-y-1"> | ||
| {/* No folder option */} | ||
| <button | ||
| className={cn( | ||
| "flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm transition-colors hover:bg-accent", | ||
| !value && "bg-accent" | ||
| )} | ||
| onClick={() => handleSelect(null)} | ||
| type="button" | ||
| > | ||
| <span className="text-muted-foreground">No folder</span> | ||
| </button> | ||
|
|
||
| {/* Existing folders */} | ||
| {existingFolders.map((folder) => ( | ||
| <button | ||
| className={cn( | ||
| "flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm transition-colors hover:bg-accent", | ||
| value === folder && "bg-accent" | ||
| )} | ||
| key={folder} | ||
| onClick={() => handleSelect(folder)} | ||
| type="button" | ||
| > | ||
| <FolderIcon | ||
| className="size-4 shrink-0 text-muted-foreground" | ||
| weight="duotone" | ||
| /> | ||
| <span className="truncate">{folder}</span> | ||
| </button> | ||
| ))} | ||
|
|
||
| {/* Divider */} | ||
| {existingFolders.length > 0 && ( | ||
| <div className="my-1 h-px bg-border" /> | ||
| )} | ||
|
|
||
| {/* New folder input */} | ||
| <div className="flex items-center gap-1"> | ||
| <Input | ||
| className="h-8 text-sm" | ||
| onChange={(e) => setNewFolderInput(e.target.value)} | ||
| onKeyDown={(e) => { | ||
| if (e.key === "Enter") { | ||
| e.preventDefault(); | ||
| handleCreateFolder(); | ||
| } | ||
| }} | ||
| placeholder="New folder path..." | ||
| value={newFolderInput} | ||
| /> | ||
| <Button | ||
| className="size-8 shrink-0" | ||
| disabled={(() => { | ||
| const trimmed = newFolderInput.trim().replace(/^\/+|\/+$/g, ""); | ||
| return !trimmed || !FOLDER_PATH_REGEX.test(trimmed); | ||
| })()} | ||
| onClick={handleCreateFolder} | ||
| size="icon" | ||
| type="button" | ||
| variant="ghost" | ||
| > | ||
| <PlusIcon className="size-4" /> | ||
| </Button> | ||
| </div> | ||
| <p className="px-1 text-muted-foreground text-xs"> | ||
| Use / for nested folders (e.g. billing/plans) | ||
| </p> | ||
| </div> | ||
| </PopoverContent> | ||
| </Popover> | ||
| ); | ||
| } | ||
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.
"New folder" button enabled for slash-only input
The button's
disabledcheck evaluatesnewFolderInput.trim()as the truthy guard, buthandleCreateFolderstrips leading/trailing slashes before the emptiness check. This means a user can type/(or///), see the + button become enabled, click it, and nothing happens silently — becausetrimmedbecomes""after thereplace.Aligning the disabled logic with the same strip-then-check: