import { useCallback, useState } from "react"; import { observer } from "mobx-react"; import Link from "next/link"; import { useRouter } from "next/router"; // icons import { ArrowRight, PanelRight, Plus } from "lucide-react"; import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TIssueLayouts } from "@plane/types"; // ui import { Breadcrumbs, Button, CustomMenu, DiceIcon, Tooltip } from "@plane/ui"; // components import { ProjectAnalyticsModal } from "@/components/analytics"; import { BreadcrumbLink } from "@/components/common"; import { DisplayFiltersSelection, FiltersDropdown, FilterSelection, LayoutSelection } from "@/components/issues"; import { ProjectLogo } from "@/components/project"; // constants import { DP_APPLIED, DP_REMOVED, E_MODULE_ISSUES, elementFromPath, FILTER_APPLIED, FILTER_REMOVED, FILTER_SEARCHED, LAYOUT_CHANGED, LP_UPDATED, } from "@/constants/event-tracker"; import { EIssuesStoreType, EIssueFilterType, ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "@/constants/issue"; import { EUserProjectRoles } from "@/constants/project"; // helpers import { cn } from "@/helpers/common.helper"; import { truncateText } from "@/helpers/string.helper"; // hooks import { useEventTracker, useLabel, useMember, useModule, useProject, useProjectState, useUser, useIssues, useCommandPalette, } from "@/hooks/store"; import { useIssuesActions } from "@/hooks/use-issues-actions"; import useLocalStorage from "@/hooks/use-local-storage"; import { usePlatformOS } from "@/hooks/use-platform-os"; const ModuleDropdownOption: React.FC<{ moduleId: string }> = ({ moduleId }) => { // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { getModuleById } = useModule(); // derived values const moduleDetail = getModuleById(moduleId); if (!moduleDetail) return null; return ( {truncateText(moduleDetail.name, 40)} ); }; export const ModuleIssuesHeader: React.FC = observer(() => { // states const [analyticsModal, setAnalyticsModal] = useState(false); // router const router = useRouter(); const { workspaceSlug, projectId, moduleId } = router.query; // hooks const { isMobile } = usePlatformOS(); // store hooks const { issuesFilter: { issueFilters }, } = useIssues(EIssuesStoreType.MODULE); const { updateFilters } = useIssuesActions(EIssuesStoreType.MODULE); const { projectModuleIds, getModuleById } = useModule(); const { setTrackElement, captureEvent, captureIssuesFilterEvent, captureIssuesDisplayFilterEvent } = useEventTracker(); const { toggleCreateIssueModal } = useCommandPalette(); const { membership: { currentProjectRole }, } = useUser(); const { currentProjectDetails } = useProject(); const { projectLabels } = useLabel(); const { projectStates } = useProjectState(); const { project: { projectMemberIds }, } = useMember(); const { setValue, storedValue } = useLocalStorage("module_sidebar_collapsed", "false"); const isSidebarCollapsed = storedValue ? (storedValue === "true" ? true : false) : false; const toggleSidebar = () => { setValue(`${!isSidebarCollapsed}`); }; const activeLayout = issueFilters?.displayFilters?.layout; const handleLayoutChange = useCallback( (layout: TIssueLayouts) => { if (!projectId) return; updateFilters(projectId.toString(), EIssueFilterType.DISPLAY_FILTERS, { layout: layout }).then(() => captureEvent(LAYOUT_CHANGED, { layout: layout, ...elementFromPath(router.asPath), }) ); }, [projectId, updateFilters, captureEvent, router.asPath] ); const handleFiltersUpdate = useCallback( (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!projectId) return; const newValues = Array.from(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); } const event = (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED; updateFilters(projectId.toString(), EIssueFilterType.FILTERS, { [key]: newValues }).then(() => { captureIssuesFilterEvent({ eventName: event, payload: { routePath: router.asPath, filters: issueFilters, filter_property: value, filter_type: key, }, }); }); }, [projectId, issueFilters, updateFilters, captureIssuesFilterEvent, router.asPath] ); const handleDisplayFilters = useCallback( (updatedDisplayFilter: Partial) => { if (!projectId) return; updateFilters(projectId.toString(), EIssueFilterType.DISPLAY_FILTERS, updatedDisplayFilter).then(() => captureIssuesDisplayFilterEvent({ eventName: LP_UPDATED, payload: { property_type: Object.keys(updatedDisplayFilter).join(","), property: Object.values(updatedDisplayFilter)?.[0], routePath: router.asPath, filters: issueFilters, }, }) ); }, [projectId, updateFilters, captureIssuesDisplayFilterEvent, router.asPath] ); const handleDisplayProperties = useCallback( (property: Partial) => { if (!projectId) return; updateFilters(projectId.toString(), EIssueFilterType.DISPLAY_PROPERTIES, property).then(() => captureIssuesDisplayFilterEvent({ eventName: Object.values(property)?.[0] === true ? DP_APPLIED : DP_REMOVED, payload: { display_property: Object.keys(property).join(","), routePath: router.asPath, filters: issueFilters, }, }) ); }, [projectId, updateFilters, captureIssuesDisplayFilterEvent, router.asPath] ); // derived values const moduleDetails = moduleId ? getModuleById(moduleId.toString()) : undefined; const canUserCreateIssue = currentProjectRole && [EUserProjectRoles.ADMIN, EUserProjectRoles.MEMBER].includes(currentProjectRole); const issueCount = moduleDetails ? issueFilters?.displayFilters?.sub_issue && moduleDetails.sub_issues ? moduleDetails.total_issues + moduleDetails.sub_issues : moduleDetails.total_issues : undefined; return ( <> setAnalyticsModal(false)} moduleDetails={moduleDetails ?? undefined} />
) } /> ... } /> } /> } />

{moduleDetails?.name && moduleDetails.name}

{issueCount && issueCount > 0 ? ( 1 ? "issues" : "issue" } in this module`} position="bottom" > {issueCount} ) : null}
} className="ml-1.5 flex-shrink-0" placement="bottom-start" > {projectModuleIds?.map((moduleId) => )} } />
handleLayoutChange(layout)} selectedLayout={activeLayout} /> captureIssuesFilterEvent({ eventName: FILTER_SEARCHED, payload: { routePath: router.asPath, current_filters: issueFilters?.filters, layout: issueFilters?.displayFilters?.layout, }, }) } cycleViewDisabled={!currentProjectDetails?.cycle_view} moduleViewDisabled={!currentProjectDetails?.module_view} />
{canUserCreateIssue && ( <> )}
); });