import { FC, useCallback, useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; // icons import { ListFilter, Search, X } from "lucide-react"; // types import type { TModuleFilters } from "@plane/types"; // components import { ArchiveTabsList } from "@/components/archives"; import { FiltersDropdown } from "@/components/issues"; import { ModuleFiltersSelection, ModuleOrderByDropdown } from "@/components/modules"; // helpers import { cn } from "@/helpers/common.helper"; // hooks import { useMember, useModuleFilter } from "@/hooks/store"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; export const ArchivedModulesHeader: FC = observer(() => { // router const router = useRouter(); const { projectId } = router.query; // refs const inputRef = useRef(null); // hooks const { currentProjectArchivedFilters, currentProjectDisplayFilters, archivedModulesSearchQuery, updateFilters, updateDisplayFilters, updateArchivedModulesSearchQuery, } = useModuleFilter(); const { workspace: { workspaceMemberIds }, } = useMember(); // states const [isSearchOpen, setIsSearchOpen] = useState(archivedModulesSearchQuery !== "" ? true : false); // outside click detector hook useOutsideClickDetector(inputRef, () => { if (isSearchOpen && archivedModulesSearchQuery.trim() === "") setIsSearchOpen(false); }); const handleFilters = useCallback( (key: keyof TModuleFilters, value: string | string[]) => { if (!projectId) return; const newValues = currentProjectArchivedFilters?.[key] ?? []; if (Array.isArray(value)) value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); }); else { if (currentProjectArchivedFilters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); else newValues.push(value); } updateFilters(projectId.toString(), { [key]: newValues }, "archived"); }, [currentProjectArchivedFilters, projectId, updateFilters] ); const handleInputKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Escape") { if (archivedModulesSearchQuery && archivedModulesSearchQuery.trim() !== "") updateArchivedModulesSearchQuery(""); else { setIsSearchOpen(false); inputRef.current?.blur(); } } }; return (
{/* filter options */}
{!isSearchOpen && ( )}
updateArchivedModulesSearchQuery(e.target.value)} onKeyDown={handleInputKeyDown} /> {isSearchOpen && ( )}
{ if (!projectId || val === currentProjectDisplayFilters?.order_by) return; updateDisplayFilters(projectId.toString(), { order_by: val, }); }} /> } title="Filters" placement="bottom-end"> { if (!projectId) return; updateDisplayFilters(projectId.toString(), val); }} handleFiltersUpdate={handleFilters} memberIds={workspaceMemberIds ?? undefined} isArchived />
); });