import { useCallback, useState } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Briefcase, Circle, ExternalLink, Plus } from "lucide-react"; // hooks import { useApplication, useEventTracker, useLabel, useProject, useProjectState, useUser, useMember, } from "hooks/store"; // components import { DisplayFiltersSelection, FiltersDropdown, FilterSelection, LayoutSelection } from "components/issues"; import { ProjectAnalyticsModal } from "components/analytics"; import { SidebarHamburgerToggle } from "components/core/sidebar/sidebar-menu-hamburger-toggle"; import { BreadcrumbLink } from "components/common"; // ui import { Breadcrumbs, Button, LayersIcon } from "@plane/ui"; // types import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TIssueLayouts } from "@plane/types"; // constants import { EIssueFilterType, EIssuesStoreType, ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "constants/issue"; import { DP_APPLIED, DP_REMOVED, elementFromPath, FILTER_APPLIED, FILTER_REMOVED, FILTER_SEARCHED, LAYOUT_CHANGED, LP_UPDATED, } from "constants/event-tracker"; // helper import { renderEmoji } from "helpers/emoji.helper"; import { EUserProjectRoles } from "constants/project"; import { useIssues } from "hooks/store/use-issues"; import { IssuesMobileHeader } from "components/issues/issues-mobile-header"; export const ProjectIssuesHeader: React.FC = observer(() => { // states const [analyticsModal, setAnalyticsModal] = useState(false); // router const router = useRouter(); const { workspaceSlug, projectId } = router.query as { workspaceSlug: string; projectId: string }; // store hooks const { project: { projectMemberIds }, } = useMember(); const { issuesFilter: { issueFilters, updateFilters }, } = useIssues(EIssuesStoreType.PROJECT); const { commandPalette: { toggleCreateIssueModal }, } = useApplication(); const { captureEvent, setTrackElement, captureIssuesFilterEvent, captureIssuesDisplayFilterEvent } = useEventTracker(); const { membership: { currentProjectRole }, } = useUser(); const { currentProjectDetails } = useProject(); const { projectStates } = useProjectState(); const { projectLabels } = useLabel(); const activeLayout = issueFilters?.displayFilters?.layout; 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)) { newValues.splice(newValues.indexOf(value), 1); isFilterRemoved = true; } else newValues.push(value); } updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }).then(() => captureIssuesFilterEvent({ eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, payload: { path: router.asPath, filters: issueFilters, element_id: projectId, filter_property: value, filter_type: key, }, }) ); }, [workspaceSlug, projectId, issueFilters, updateFilters] ); const handleLayoutChange = useCallback( (layout: TIssueLayouts) => { if (!workspaceSlug || !projectId) return; updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_FILTERS, { layout: layout }).then(() => captureEvent(LAYOUT_CHANGED, { layout: layout, element: elementFromPath(router.asPath), element_id: projectId, }) ); }, [workspaceSlug, projectId, updateFilters] ); const handleDisplayFilters = useCallback( (updatedDisplayFilter: Partial) => { if (!workspaceSlug || !projectId) return; updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_FILTERS, updatedDisplayFilter).then(() => captureIssuesDisplayFilterEvent({ eventName: LP_UPDATED, payload: { property_type: Object.keys(updatedDisplayFilter).join(","), property: Object.values(updatedDisplayFilter)?.[0], path: router.asPath, filters: issueFilters, element_id: projectId, }, }) ); }, [workspaceSlug, projectId, updateFilters, issueFilters] ); const handleDisplayProperties = useCallback( (property: Partial) => { if (!workspaceSlug || !projectId) return; updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_PROPERTIES, property).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: projectId, }, }); }); }, [workspaceSlug, projectId, updateFilters, issueFilters] ); const deployUrl = process.env.NEXT_PUBLIC_DEPLOY_URL; const canUserCreateIssue = currentProjectRole && [EUserProjectRoles.ADMIN, EUserProjectRoles.MEMBER].includes(currentProjectRole); return ( <> setAnalyticsModal(false)} projectDetails={currentProjectDetails ?? undefined} />
router.back()}> {renderEmoji(currentProjectDetails.emoji)} ) : currentProjectDetails?.icon_prop ? (
{renderEmoji(currentProjectDetails.icon_prop)}
) : ( {currentProjectDetails?.name.charAt(0)} ) ) : ( ) } /> } /> } /> } />
{currentProjectDetails?.is_deployed && deployUrl && ( Public )}
handleLayoutChange(layout)} selectedLayout={activeLayout} /> captureIssuesFilterEvent({ eventName: FILTER_SEARCHED, payload: { path: router.asPath, current_filters: issueFilters?.filters, layout: issueFilters?.displayFilters?.layout, element_id: projectId, }, }) } />
{canUserCreateIssue && ( <> )}
); });