import { useCallback } from "react"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { useRouter } from "next/router"; import { Plus } from "lucide-react"; import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TIssueLayouts } from "@plane/types"; // hooks // components // ui import { Breadcrumbs, Button, CustomMenu, PhotoFilterIcon } from "@plane/ui"; import { BreadcrumbLink } from "@/components/common"; import { DisplayFiltersSelection, FiltersDropdown, FilterSelection, LayoutSelection } from "@/components/issues"; // helpers // types // constants import { ProjectLogo } from "@/components/project"; import { EIssuesStoreType, EIssueFilterType, ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "@/constants/issue"; import { EUserProjectRoles } from "@/constants/project"; import { truncateText } from "@/helpers/string.helper"; import { useApplication, useEventTracker, useIssues, useLabel, useMember, useProject, useProjectState, useProjectView, useUser, } from "@/hooks/store"; export const ProjectViewIssuesHeader: React.FC = observer(() => { // router const router = useRouter(); const { workspaceSlug, projectId, viewId } = router.query; // store hooks const { issuesFilter: { issueFilters, updateFilters }, } = useIssues(EIssuesStoreType.PROJECT_VIEW); const { setTrackElement } = useEventTracker(); const { commandPalette: { toggleCreateIssueModal }, } = useApplication(); const { membership: { currentProjectRole }, } = useUser(); const { currentProjectDetails } = useProject(); const { projectViewIds, getViewById } = useProjectView(); const { projectStates } = useProjectState(); const { projectLabels } = useLabel(); const { project: { projectMemberIds }, } = useMember(); const activeLayout = issueFilters?.displayFilters?.layout; const handleLayoutChange = useCallback( (layout: TIssueLayouts) => { if (!workspaceSlug || !projectId || !viewId) return; updateFilters( workspaceSlug.toString(), projectId.toString(), EIssueFilterType.DISPLAY_FILTERS, { layout: layout }, viewId.toString() ); }, [workspaceSlug, projectId, viewId, updateFilters] ); const handleFiltersUpdate = useCallback( (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!workspaceSlug || !projectId || !viewId) return; const newValues = issueFilters?.filters?.[key] ?? []; if (Array.isArray(value)) { // this validation is majorly for the filter start_date, target_date custom value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); else newValues.splice(newValues.indexOf(val), 1); }); } else { if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); else newValues.push(value); } updateFilters( workspaceSlug.toString(), projectId.toString(), EIssueFilterType.FILTERS, { [key]: newValues }, viewId.toString() ); }, [workspaceSlug, projectId, viewId, issueFilters, updateFilters] ); const handleDisplayFilters = useCallback( (updatedDisplayFilter: Partial) => { if (!workspaceSlug || !projectId || !viewId) return; updateFilters( workspaceSlug.toString(), projectId.toString(), EIssueFilterType.DISPLAY_FILTERS, updatedDisplayFilter, viewId.toString() ); }, [workspaceSlug, projectId, viewId, updateFilters] ); const handleDisplayProperties = useCallback( (property: Partial) => { if (!workspaceSlug || !projectId || !viewId) return; updateFilters( workspaceSlug.toString(), projectId.toString(), EIssueFilterType.DISPLAY_PROPERTIES, property, viewId.toString() ); }, [workspaceSlug, projectId, viewId, updateFilters] ); const viewDetails = viewId ? getViewById(viewId.toString()) : null; const canUserCreateIssue = currentProjectRole && [EUserProjectRoles.ADMIN, EUserProjectRoles.MEMBER].includes(currentProjectRole); return (
) } /> } /> } /> } /> {viewDetails?.name && truncateText(viewDetails.name, 40)} } className="ml-1.5" placement="bottom-start" > {projectViewIds?.map((viewId) => { const view = getViewById(viewId); if (!view) return; return ( {truncateText(view.name, 40)} ); })} } />
handleLayoutChange(layout)} selectedLayout={activeLayout} /> {canUserCreateIssue && ( )}
); });