import { Settings2 } from 'lucide-react' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { LabelBadge } from './LabelBadge' import { useAuth } from '@/lib/auth' import { useValidLabelsQuery, useBugChangeLabelsMutation, BugDetailDocument, } from '@/__generated__/graphql' interface LabelEditorProps { bugPrefix: string currentLabels: Array<{ name: string; color: { R: number; G: number; B: number } }> /** Current repo slug, passed as `ref` in refetch query variables. */ ref_?: string | null } // Gear-icon popover in the BugDetailPage sidebar for adding/removing labels. // Loads all valid labels from the repo and toggles them via bugChangeLabels. // Hidden in read-only mode. export function LabelEditor({ bugPrefix, currentLabels, ref_ }: LabelEditorProps) { const { user } = useAuth() const { data } = useValidLabelsQuery({ skip: !user, variables: { ref: ref_ } }) const [changeLabels] = useBugChangeLabelsMutation({ refetchQueries: [{ query: BugDetailDocument, variables: { ref: ref_, prefix: bugPrefix } }], }) const validLabels = data?.repository?.validLabels.nodes ?? [] const currentNames = new Set(currentLabels.map((l) => l.name)) async function toggleLabel(name: string) { const isSet = currentNames.has(name) await changeLabels({ variables: { input: { prefix: bugPrefix, added: isSet ? [] : [name], Removed: isSet ? [name] : [], }, }, }) } return (

Labels

{user && validLabels.length > 0 && (

Apply labels

{validLabels.map((label) => { const active = currentNames.has(label.name) return ( ) })}
)}
{currentLabels.length === 0 ? (

None yet

) : (
{currentLabels.map((label) => ( ))}
)}
) }