import React from "react"; import { useRouter } from "next/router"; // hooks import { useWorkspaceView } from "hooks/use-workspace-view"; // components import { GlobalSelectFilters } from "components/workspace/views/global-select-filters"; // ui import { Tooltip } from "components/ui"; // icons import { FormatListBulletedOutlined } from "@mui/icons-material"; import { CreditCard } from "lucide-react"; // helpers import { replaceUnderscoreIfSnakeCase } from "helpers/string.helper"; import { checkIfArraysHaveSameElements } from "helpers/array.helper"; // types import { TIssueViewOptions } from "types"; const issueViewOptions: { type: TIssueViewOptions; Icon: any }[] = [ { type: "list", Icon: FormatListBulletedOutlined, }, { type: "spreadsheet", Icon: CreditCard, }, ]; export const WorkspaceIssuesViewOptions: React.FC = () => { const router = useRouter(); const { workspaceSlug, globalViewId } = router.query; const { filters, handleFilters } = useWorkspaceView(); const isWorkspaceViewPath = router.pathname.includes("workspace-views/all-issues"); const showFilters = isWorkspaceViewPath || globalViewId; return (
{issueViewOptions.map((option) => ( {replaceUnderscoreIfSnakeCase(option.type)} View } position="bottom" > ))}
{showFilters && ( <> { const key = option.key as keyof typeof filters.filters; if (key === "start_date" || key === "target_date") { const valueExists = checkIfArraysHaveSameElements( filters.filters?.[key] ?? [], option.value ); handleFilters("filters", { ...filters, [key]: valueExists ? null : option.value, }); } else { if (!filters?.filters?.[key]?.includes(option.value)) handleFilters("filters", { ...filters, [key]: [...((filters?.filters?.[key] as any[]) ?? []), option.value], }); else { handleFilters("filters", { ...filters, [key]: (filters?.filters?.[key] as any[])?.filter( (item) => item !== option.value ), }); } } }} direction="left" /> )}
); };