import React, { useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // headless ui import { Combobox, Transition } from "@headlessui/react"; // icons import { CheckIcon, MagnifyingGlassIcon, PlusIcon, RectangleGroupIcon, TagIcon, } from "@heroicons/react/24/outline"; // services import issuesServices from "services/issues.service"; // types import type { IIssueLabels } from "types"; // fetch-keys import { PROJECT_ISSUE_LABELS } from "constants/fetch-keys"; import { IssueLabelsList } from "components/ui"; type Props = { setIsOpen: React.Dispatch>; value: string[]; onChange: (value: string[]) => void; projectId: string; }; export const IssueLabelSelect: React.FC = ({ setIsOpen, value, onChange, projectId }) => { // states const [query, setQuery] = useState(""); const router = useRouter(); const { workspaceSlug } = router.query; const { data: issueLabels } = useSWR( projectId ? PROJECT_ISSUE_LABELS(projectId) : null, workspaceSlug && projectId ? () => issuesServices.getIssueLabels(workspaceSlug as string, projectId) : null ); const filteredOptions = query === "" ? issueLabels : issueLabels?.filter((l) => l.name.toLowerCase().includes(query.toLowerCase())); return ( onChange(val)} className="relative flex-shrink-0" multiple > {({ open }: any) => ( <> `flex cursor-pointer items-center rounded-md border border-brand-base text-xs shadow-sm duration-200 ${ open ? "border-brand-accent bg-brand-accent/5 outline-none ring-1 ring-brand-accent " : "hover:bg-brand-accent/5 " }` } > {value && value.length > 0 ? ( issueLabels?.find((l) => l.id === v)?.color) ?? []} length={3} showLength={true} /> ) : ( Label )}
setQuery(event.target.value)} placeholder="Search for label..." displayValue={(assigned: any) => assigned?.name} />
{issueLabels && filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((label) => { const children = issueLabels?.filter((l) => l.parent === label.id); if (children.length === 0) { if (!label.parent) return ( `${ active ? "bg-brand-surface-2" : "" } group flex min-w-[14rem] cursor-pointer select-none items-center gap-2 truncate rounded px-1 py-1.5 text-gray-600` } value={label.id} > {({ selected }) => (
{label.name}
)}
); } else return (
{label.name}
{children.map((child) => ( `${ active ? "bg-brand-surface-2" : "" } group flex min-w-[14rem] cursor-pointer select-none items-center gap-2 truncate rounded px-1 py-1.5 text-gray-600` } value={child.id} > {({ selected }) => (
{child.name}
)}
))}
); }) ) : (

No labels found

) ) : (

Loading...

)}
)}
); };