import React from "react"; // headless ui import { Combobox } from "@headlessui/react"; // lucide icons import { ChevronDown, Search, X, Check } from "lucide-react"; // mobx import { observer } from "mobx-react-lite"; // components import { Tooltip } from "@plane/ui"; // hooks import useDynamicDropdownPosition from "hooks/use-dynamic-dropdown"; // mobx import { useMobxStore } from "lib/mobx/store-provider"; import { RootStore } from "store/root"; interface IFiltersOption { id: string; title: string; color: string | null; } export interface IIssuePropertyLabels { value?: any; onChange?: (id: any, data: any) => void; disabled?: boolean; className?: string; buttonClassName?: string; optionsClassName?: string; dropdownArrow?: boolean; } export const IssuePropertyLabels: React.FC = observer( ({ value, onChange, disabled, className, buttonClassName, optionsClassName, dropdownArrow = true, }) => { const { project: projectStore }: RootStore = useMobxStore(); const dropdownBtn = React.useRef(null); const dropdownOptions = React.useRef(null); const [isOpen, setIsOpen] = React.useState(false); const [search, setSearch] = React.useState(""); const options: IFiltersOption[] | [] = (projectStore?.projectLabels && projectStore?.projectLabels?.length > 0 && projectStore?.projectLabels.map((_label: any) => ({ id: _label?.id, title: _label?.name, color: _label?.color || null, }))) || []; useDynamicDropdownPosition(isOpen, () => setIsOpen(false), dropdownBtn, dropdownOptions); const selectedOption: IFiltersOption[] = (value && value?.length > 0 && options.filter((_label: IFiltersOption) => value.includes(_label.id))) || []; const filteredOptions: IFiltersOption[] = search === "" ? options && options.length > 0 ? options : [] : options && options.length > 0 ? options.filter((_label: IFiltersOption) => _label.title.toLowerCase().replace(/\s+/g, "").includes(search.toLowerCase().replace(/\s+/g, "")) ) : []; return ( _label.id) as string[]} onChange={(data: string[]) => { if (onChange && selectedOption) onChange(data, selectedOption); }} disabled={disabled} > {({ open }: { open: boolean }) => { if (open) { if (!isOpen) setIsOpen(true); } else if (isOpen) setIsOpen(false); return ( <> {selectedOption && selectedOption?.length > 0 ? ( <> {selectedOption?.length === 1 ? ( _label.title) || []).join(", ")} >
{selectedOption[0]?.title}
) : ( _label.title) || []).join(", ")} >
{selectedOption?.length} Labels
)} ) : (
Select option
)} {dropdownArrow && !disabled && (
)}
{options && options.length > 0 ? ( <>
setSearch(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{search && search.length > 0 && (
setSearch("")} className="flex-shrink-0 flex justify-center items-center w-[16px] h-[16px] rounded-sm cursor-pointer hover:bg-custom-background-80" >
)}
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `cursor-pointer select-none truncate rounded px-1 py-1.5 ${ active || (value && value.length > 0 && value.includes(option?.id)) ? "bg-custom-background-80" : "" } ${ value && value.length > 0 && value.includes(option?.id) ? "text-custom-text-100" : "text-custom-text-200" }` } >
{option.title}
{value && value.length > 0 && value.includes(option?.id) && (
)}
)) ) : (

No matching results

) ) : (

Loading...

)}
) : (

No options available.

)}
); }} ); } );