import { Fragment, useState } from "react"; import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; import { usePopper } from "react-popper"; import { Combobox } from "@headlessui/react"; import { Check, ChevronDown, Search, User2 } from "lucide-react"; // ui import { Avatar, AvatarGroup, Tooltip } from "@plane/ui"; // types import { Placement } from "@popperjs/core"; export interface IIssuePropertyAssignee { view?: "profile" | "workspace" | "project"; projectId: string | null; value: string[] | string; onChange: (data: string[]) => void; disabled?: boolean; hideDropdownArrow?: boolean; className?: string; buttonClassName?: string; optionsClassName?: string; placement?: Placement; multiple?: true; noLabelBorder?: boolean; } export const IssuePropertyAssignee: React.FC = observer((props) => { const { view, projectId, value, onChange, disabled = false, hideDropdownArrow = false, className, buttonClassName, optionsClassName, placement, multiple = false, noLabelBorder = false, } = props; const { workspace: workspaceStore, project: projectStore } = useMobxStore(); const workspaceSlug = workspaceStore?.workspaceSlug; const [query, setQuery] = useState(""); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const projectMembers = projectId ? projectStore?.members?.[projectId] : undefined; const fetchProjectMembers = () => workspaceSlug && projectId && projectStore.fetchProjectMembers(workspaceSlug, projectId); const options = (projectMembers ?? [])?.map((member) => ({ value: member.member.id, query: member.member.display_name, content: (
{member.member.display_name}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const label = ( 0 ? (projectMembers ? projectMembers : []) ?.filter((m) => value.includes(m.member.display_name)) .map((m) => m.member.display_name) .join(", ") : "No Assignee" } position="top" >
{value && value.length > 0 && Array.isArray(value) ? ( {value.map((assigneeId) => { const member = projectMembers?.find((m) => m.member.id === assigneeId)?.member; if (!member) return null; return ; })} ) : ( )}
); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const comboboxProps: any = { value, onChange, disabled }; if (multiple) comboboxProps.multiple = true; return (
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 && !selected ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); });