2023-09-26 14:26:59 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
// hooks
|
2023-09-28 15:04:57 +00:00
|
|
|
import { useWorkspaceView } from "hooks/use-workspace-view";
|
2023-09-26 14:26:59 +00:00
|
|
|
// components
|
2023-09-28 15:04:57 +00:00
|
|
|
import { GlobalSelectFilters } from "components/workspace/views/global-select-filters";
|
2023-09-26 14:26:59 +00:00
|
|
|
// 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, workspaceViewId } = router.query;
|
|
|
|
|
2023-09-28 15:04:57 +00:00
|
|
|
const { filters, handleFilters } = useWorkspaceView();
|
2023-09-26 14:26:59 +00:00
|
|
|
|
|
|
|
const isWorkspaceViewPath = router.pathname.includes("workspace-views/all-issues");
|
|
|
|
|
|
|
|
const showFilters = isWorkspaceViewPath || workspaceViewId;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<div className="flex items-center gap-x- px-1 py-0.5 rounded bg-custom-sidebar-background-90 ">
|
|
|
|
{issueViewOptions.map((option) => (
|
|
|
|
<Tooltip
|
|
|
|
key={option.type}
|
|
|
|
tooltipContent={
|
|
|
|
<span className="capitalize">{replaceUnderscoreIfSnakeCase(option.type)} View</span>
|
|
|
|
}
|
|
|
|
position="bottom"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`grid h-7 w-7 place-items-center rounded p-1 outline-none hover:bg-custom-sidebar-background-100 duration-300 ${
|
2023-09-28 15:04:57 +00:00
|
|
|
filters.display_filters?.layout === option.type
|
2023-09-26 14:26:59 +00:00
|
|
|
? "bg-custom-sidebar-background-100 shadow-sm"
|
|
|
|
: "text-custom-sidebar-text-200"
|
|
|
|
}`}
|
|
|
|
onClick={() => {
|
2023-09-28 15:04:57 +00:00
|
|
|
handleFilters("display_filters", { layout: option.type }, true);
|
2023-09-26 14:26:59 +00:00
|
|
|
if (option.type === "spreadsheet")
|
|
|
|
router.push(`/${workspaceSlug}/workspace-views/all-issues`);
|
|
|
|
else router.push(`/${workspaceSlug}/workspace-views`);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option.Icon
|
|
|
|
sx={{
|
|
|
|
fontSize: 16,
|
|
|
|
}}
|
|
|
|
className={option.type === "spreadsheet" ? "h-4 w-4" : ""}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{showFilters && (
|
|
|
|
<>
|
2023-09-28 15:04:57 +00:00
|
|
|
<GlobalSelectFilters
|
|
|
|
filters={filters.filters}
|
2023-09-26 14:26:59 +00:00
|
|
|
onSelect={(option) => {
|
2023-09-28 15:04:57 +00:00
|
|
|
const key = option.key as keyof typeof filters.filters;
|
2023-09-26 14:26:59 +00:00
|
|
|
|
|
|
|
if (key === "start_date" || key === "target_date") {
|
|
|
|
const valueExists = checkIfArraysHaveSameElements(
|
2023-09-28 15:04:57 +00:00
|
|
|
filters.filters?.[key] ?? [],
|
2023-09-26 14:26:59 +00:00
|
|
|
option.value
|
|
|
|
);
|
|
|
|
|
2023-09-28 15:04:57 +00:00
|
|
|
handleFilters("filters", {
|
|
|
|
...filters,
|
2023-09-26 14:26:59 +00:00
|
|
|
[key]: valueExists ? null : option.value,
|
|
|
|
});
|
|
|
|
} else {
|
2023-09-28 15:04:57 +00:00
|
|
|
if (!filters?.filters?.[key]?.includes(option.value))
|
|
|
|
handleFilters("filters", {
|
|
|
|
...filters,
|
|
|
|
[key]: [...((filters?.filters?.[key] as any[]) ?? []), option.value],
|
2023-09-26 14:26:59 +00:00
|
|
|
});
|
2023-09-28 15:04:57 +00:00
|
|
|
else {
|
|
|
|
handleFilters("filters", {
|
|
|
|
...filters,
|
|
|
|
[key]: (filters?.filters?.[key] as any[])?.filter(
|
|
|
|
(item) => item !== option.value
|
|
|
|
),
|
2023-09-26 14:26:59 +00:00
|
|
|
});
|
2023-09-28 15:04:57 +00:00
|
|
|
}
|
2023-09-26 14:26:59 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
direction="left"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|