import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { usePopper } from "react-popper"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // ui import { Combobox } from "@headlessui/react"; // icons import { ContrastIcon } from "@plane/ui"; // icons import { Check, Search } from "lucide-react"; export interface IssueCycleSelectProps { workspaceSlug: string; projectId: string; value: string | null; onChange: (value: string) => void; } export const IssueCycleSelect: React.FC = observer((props) => { const { workspaceSlug, projectId, value, onChange } = props; const [query, setQuery] = useState(""); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "bottom-start", }); const { cycle: cycleStore } = useMobxStore(); const fetchCycles = () => { if (workspaceSlug && projectId) cycleStore.fetchCycles(workspaceSlug, projectId, "all"); }; const cycles = cycleStore.cycles?.[projectId]?.["all"] ?? []; const selectedCycle = cycles ? cycles?.find((i) => i.id === value) : undefined; const options = cycles?.map((cycle) => ({ value: cycle.id, query: cycle.name, content: (
{cycle.name}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const label = selectedCycle ? (
{selectedCycle.name}
) : (
Cycle
); return ( onChange(val)} disabled={false} >
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( <> {filteredOptions.map((option) => ( `flex cursor-pointer select-none items-center justify-between gap-2 truncate rounded px-1 py-1.5 ${ active && !selected ? "bg-custom-background-80" : "" } w-full truncate ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} ))} `flex items-center justify-between gap-2 ${ active ? "bg-custom-background-80" : "" } w-full cursor-pointer select-none truncate rounded px-1 py-1.5 text-custom-text-100` } >
None
) : (

No matching results

) ) : (

Loading...

)}
); });