import { useCallback } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Plus } from "lucide-react"; import Link from "next/link"; // hooks import { useApplication, useEventTracker, useIssues, useLabel, useMember, useProject, useProjectState, useProjectView, useUser, } from "hooks/store"; // components import { DisplayFiltersSelection, FiltersDropdown, FilterSelection, LayoutSelection } from "components/issues"; import { SidebarHamburgerToggle } from "components/core/sidebar/sidebar-menu-hamburger-toggle"; import { BreadcrumbLink } from "components/common"; // ui import { Breadcrumbs, Button, CustomMenu, PhotoFilterIcon } from "@plane/ui"; // helpers import { truncateText } from "helpers/string.helper"; import { renderEmoji } from "helpers/emoji.helper"; // types import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TIssueLayouts } from "@plane/types"; // constants import { EIssuesStoreType, EIssueFilterType, ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "constants/issue"; import { EUserProjectRoles } from "constants/project"; import { DP_APPLIED, DP_REMOVED, elementFromPath, FILTER_APPLIED, FILTER_REMOVED, FILTER_SEARCHED, LAYOUT_CHANGED, LP_UPDATED, } from "constants/event-tracker"; export const ProjectViewIssuesHeader: React.FC = observer(() => { // router const router = useRouter(); const { workspaceSlug, projectId, viewId } = router.query as { workspaceSlug: string; projectId: string; viewId: string; }; // store hooks const { issuesFilter: { issueFilters, updateFilters }, } = useIssues(EIssuesStoreType.PROJECT_VIEW); const { setTrackElement, captureEvent, captureIssuesFilterEvent, captureIssuesDisplayFilterEvent } = 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) return; updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_FILTERS, { layout: layout }, viewId).then(() => captureEvent(LAYOUT_CHANGED, { layout: layout, element: elementFromPath(router.asPath), element_id: viewId, }) ); }, [workspaceSlug, projectId, viewId, updateFilters, captureEvent, router.asPath] ); const handleFiltersUpdate = useCallback( (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!workspaceSlug || !projectId) return; const newValues = issueFilters?.filters?.[key] ?? []; let isFilterRemoved = false; if (Array.isArray(value)) { value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); else isFilterRemoved = true; }); } else { if (issueFilters?.filters?.[key]?.includes(value)) { isFilterRemoved = true; newValues.splice(newValues.indexOf(value), 1); } else newValues.push(value); } updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }, viewId).then(() => { captureIssuesFilterEvent({ eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, payload: { path: router.asPath, filters: issueFilters, element_id: viewId, filter_property: value, filter_type: key, }, }); }); }, [workspaceSlug, projectId, viewId, issueFilters, updateFilters, captureIssuesFilterEvent, router.asPath] ); const handleDisplayFilters = useCallback( (updatedDisplayFilter: Partial) => { if (!workspaceSlug || !projectId) return; updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_FILTERS, updatedDisplayFilter, viewId).then(() => captureIssuesDisplayFilterEvent({ eventName: LP_UPDATED, payload: { property_type: Object.keys(updatedDisplayFilter).join(","), property: Object.values(updatedDisplayFilter)?.[0], path: router.asPath, filters: issueFilters, element_id: viewId, }, }) ); }, [workspaceSlug, projectId, viewId, updateFilters, issueFilters, captureIssuesDisplayFilterEvent, router.asPath] ); const handleDisplayProperties = useCallback( (property: Partial) => { if (!workspaceSlug || !projectId) return; updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_PROPERTIES, property, viewId).then(() => captureIssuesDisplayFilterEvent({ eventName: Object.values(property)?.[0] === true ? DP_APPLIED : DP_REMOVED, payload: { display_property: Object.keys(property).join(","), path: router.asPath, filters: issueFilters, element_id: viewId, }, }) ); }, [workspaceSlug, projectId, viewId, updateFilters, issueFilters, captureIssuesDisplayFilterEvent, router.asPath] ); const viewDetails = viewId ? getViewById(viewId.toString()) : null; const canUserCreateIssue = currentProjectRole && [EUserProjectRoles.ADMIN, EUserProjectRoles.MEMBER].includes(currentProjectRole); return (
{renderEmoji(currentProjectDetails.emoji)} ) : currentProjectDetails?.icon_prop ? (
{renderEmoji(currentProjectDetails.icon_prop)}
) : ( {currentProjectDetails?.name.charAt(0)} ) } /> } /> } /> } /> {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} /> captureIssuesFilterEvent({ eventName: FILTER_SEARCHED, payload: { path: router.asPath, current_filters: issueFilters?.filters, layout: issueFilters?.displayFilters?.layout, element_id: projectId, }, }) } /> {canUserCreateIssue && ( )}
); });