import { useCallback, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // components import { DisplayFiltersSelection, FiltersDropdown, FilterSelection } from "components/issues"; import { CreateUpdateWorkspaceViewModal } from "components/workspace"; // ui import { Breadcrumbs, Button, LayersIcon, PhotoFilterIcon, Tooltip } from "@plane/ui"; // icons import { List, PlusIcon, Sheet } from "lucide-react"; // types import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions } from "types"; // constants import { ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "constants/issue"; import { EFilterType } from "store/issues/types"; import { EUserWorkspaceRoles } from "constants/workspace"; const GLOBAL_VIEW_LAYOUTS = [ { key: "list", title: "List", link: "/workspace-views", icon: List }, { key: "spreadsheet", title: "Spreadsheet", link: "/workspace-views/all-issues", icon: Sheet }, ]; type Props = { activeLayout: "list" | "spreadsheet"; }; export const GlobalIssuesHeader: React.FC = observer((props) => { const { activeLayout } = props; const [createViewModal, setCreateViewModal] = useState(false); const router = useRouter(); const { workspaceSlug } = router.query as { workspaceSlug: string }; const { workspace: { workspaceLabels }, workspaceMember: { workspaceMembers }, project: { workspaceProjects }, user: { currentWorkspaceRole }, workspaceGlobalIssuesFilter: { issueFilters, updateFilters }, } = useMobxStore(); const handleFiltersUpdate = useCallback( (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!workspaceSlug) return; const newValues = issueFilters?.filters?.[key] ?? []; if (Array.isArray(value)) { value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); }); } else { if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); else newValues.push(value); } updateFilters(workspaceSlug, EFilterType.FILTERS, { [key]: newValues }); }, [workspaceSlug, issueFilters, updateFilters] ); const handleDisplayFilters = useCallback( (updatedDisplayFilter: Partial) => { if (!workspaceSlug) return; updateFilters(workspaceSlug, EFilterType.DISPLAY_FILTERS, updatedDisplayFilter); }, [workspaceSlug, updateFilters] ); const handleDisplayProperties = useCallback( (property: Partial) => { if (!workspaceSlug) return; updateFilters(workspaceSlug, EFilterType.DISPLAY_PROPERTIES, property); }, [workspaceSlug, updateFilters] ); const isAuthorizedUser = !!currentWorkspaceRole && currentWorkspaceRole >= EUserWorkspaceRoles.MEMBER; return ( <> setCreateViewModal(false)} />
) : ( ) } label={`All ${activeLayout === "spreadsheet" ? "Issues" : "Views"}`} />
{GLOBAL_VIEW_LAYOUTS.map((layout) => (
))}
{activeLayout === "spreadsheet" && ( <> m.member)} projects={workspaceProjects ?? undefined} /> )} {isAuthorizedUser && ( )}
); });