import { Fragment, useState } from "react"; import { usePopper } from "react-popper"; import { observer } from "mobx-react-lite"; import { Combobox } from "@headlessui/react"; import { Check, ChevronDown, Search, Triangle } from "lucide-react"; // ui import { Tooltip } from "@plane/ui"; // types import { Placement } from "@popperjs/core"; import { useMobxStore } from "lib/mobx/store-provider"; 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 { 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 { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const { project: { project_details }, projectEstimates: { projectEstimates }, } = useMobxStore(); const projectDetails = projectId ? project_details[projectId] : null; const isEstimateEnabled = projectDetails?.estimate !== null; const estimates = projectEstimates; const estimatePoints = projectDetails && isEstimateEnabled ? estimates?.find((e) => e.id === projectDetails.estimate)?.points : null; 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"}
); if (!isEstimateEnabled) return null; 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 cursor-pointer select-none items-center justify-between gap-2 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...

)}
); });