import { Fragment, useState } from "react"; import { observer } from "mobx-react-lite"; // hooks import { usePopper } from "react-popper"; import useEstimateOption from "hooks/use-estimate-option"; // ui import { Check, ChevronDown, Search, Triangle } from "lucide-react"; import { Combobox } from "@headlessui/react"; import { Tooltip } from "@plane/ui"; // types import { Placement } from "@popperjs/core"; export interface IIssuePropertyEstimates { view?: "profile" | "workspace" | "project"; projectId: string | null; value: number | null; onChange: (value: number | null) => void; disabled?: boolean; hideDropdownArrow?: boolean; className?: string; buttonClassName?: string; optionsClassName?: string; placement?: Placement; } export const IssuePropertyEstimates: React.FC = observer((props) => { const { view, projectId, value, onChange, disabled, hideDropdownArrow = false, className = "", buttonClassName = "", optionsClassName = "", placement, } = props; const [query, setQuery] = useState(""); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { isEstimateActive, estimatePoints } = useEstimateOption(); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const options: { value: number | null; query: string; content: any }[] | undefined = (estimatePoints ?? []).map( (estimate) => ({ value: estimate.key, query: estimate.value, content: (
{estimate.value}
), }) ); options?.unshift({ value: null, query: "none", content: (
None
), }); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const selectedEstimate = estimatePoints?.find((e) => e.key === value); const label = (
{selectedEstimate?.value ?? "None"}
); return ( onChange(val as number | null)} disabled={disabled} >
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `flex items-center justify-between gap-2 cursor-pointer select-none truncate rounded px-1 py-1.5 ${ active ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); });