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 { DiceIcon } from "@plane/ui"; // icons import { Check, Search } from "lucide-react"; export interface IssueModuleSelectProps { workspaceSlug: string; projectId: string; value: string | null; onChange: (value: string) => void; } export const IssueModuleSelect: 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 { module: moduleStore } = useMobxStore(); const fetchModules = () => { if (workspaceSlug && projectId) moduleStore.fetchModules(workspaceSlug, projectId); }; const modules = projectId ? moduleStore.modules[projectId] : undefined; const selectedModule = modules ? modules?.find((i) => i.id === value) : undefined; const options = modules?.map((module) => ({ value: module.id, query: module.name, content: (
{module.name}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const label = selectedModule ? (
{selectedModule.name}
) : (
Module
); return ( onChange(val)}>
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...

)}
); });