import { Fragment, useState } from "react"; import { observer } from "mobx-react"; import { usePopper } from "react-popper"; import { Check, Search, Tag } from "lucide-react"; import { Combobox } from "@headlessui/react"; // hooks import { useLabel } from "@/hooks/store"; // components export interface IIssueLabelSelect { workspaceSlug: string; projectId: string; issueId: string; values: string[]; onSelect: (_labelIds: string[]) => void; } export const IssueLabelSelect: React.FC = observer((props) => { const { workspaceSlug, projectId, issueId, values, onSelect } = props; // store hooks const { fetchProjectLabels, getProjectLabels } = useLabel(); // states const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const [isLoading, setIsLoading] = useState(false); const [query, setQuery] = useState(""); const projectLabels = getProjectLabels(projectId); const fetchLabels = () => { setIsLoading(true); if (!projectLabels && workspaceSlug && projectId) fetchProjectLabels(workspaceSlug, projectId).then(() => setIsLoading(false)); }; const options = (projectLabels ?? []).map((label) => ({ value: label.id, query: label.name, content: (
{label.name}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "bottom-end", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const issueLabels = values ?? []; const label = (
Select Label
); const searchInputKeyDown = (e: React.KeyboardEvent) => { if (query !== "" && e.key === "Escape") { e.stopPropagation(); setQuery(""); } }; if (!issueId || !values) return <>; return ( <> onSelect(value)} multiple >
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} onKeyDown={searchInputKeyDown} />
{isLoading ? (

Loading...

) : filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `flex cursor-pointer select-none items-center justify-between gap-2 truncate rounded px-1 py-1.5 hover:bg-custom-background-80 ${ selected ? "text-custom-text-100" : "text-custom-text-200" }` } > {({ selected }) => ( <> {option.content} {selected && (
)} )}
)) ) : (

No matching results

)}
); });