import { Fragment, useState } from "react"; import { observer } from "mobx-react-lite"; import { usePopper } from "react-popper"; import { Check, Search, Tag } from "lucide-react"; // hooks import { useIssueDetail, useLabel } from "hooks/store"; // components import { Combobox } from "@headlessui/react"; export interface IIssueLabelSelect { workspaceSlug: string; projectId: string; issueId: string; onSelect: (_labelIds: string[]) => void; } export const IssueLabelSelect: React.FC = observer((props) => { const { workspaceSlug, projectId, issueId, onSelect } = props; // store hooks const { issue: { getIssueById }, } = useIssueDetail(); 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 issue = getIssueById(issueId); 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-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const issueLabels = issue?.label_ids ?? []; const label = (
Select Label
); if (!issue) return <>; return ( <> onSelect(value)} multiple >
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{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

)}
); });