mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
3a6d72e4b6
* chore: workspace view types, services and hooks added * style: spreadsheet view revamp and code refactor * feat: workspace view * fix: build fix * chore: sidebar workspace issues redirection updated
122 lines
3.9 KiB
TypeScript
122 lines
3.9 KiB
TypeScript
import React from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// hooks
|
|
import useMyIssuesFilters from "hooks/my-issues/use-my-issues-filter";
|
|
import useWorkspaceIssuesFilters from "hooks/use-worskpace-issue-filter";
|
|
// components
|
|
import { MyIssuesSelectFilters } from "components/issues";
|
|
// 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;
|
|
|
|
const { displayFilters, setDisplayFilters } = useMyIssuesFilters(workspaceSlug?.toString());
|
|
|
|
const { filters, setFilters } = useWorkspaceIssuesFilters(
|
|
workspaceSlug?.toString(),
|
|
workspaceViewId?.toString()
|
|
);
|
|
|
|
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 ${
|
|
displayFilters?.layout === option.type
|
|
? "bg-custom-sidebar-background-100 shadow-sm"
|
|
: "text-custom-sidebar-text-200"
|
|
}`}
|
|
onClick={() => {
|
|
setDisplayFilters({ layout: option.type });
|
|
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 && (
|
|
<>
|
|
<MyIssuesSelectFilters
|
|
filters={filters}
|
|
onSelect={(option) => {
|
|
const key = option.key as keyof typeof filters;
|
|
|
|
if (key === "start_date" || key === "target_date") {
|
|
const valueExists = checkIfArraysHaveSameElements(
|
|
filters?.[key] ?? [],
|
|
option.value
|
|
);
|
|
|
|
setFilters({
|
|
[key]: valueExists ? null : option.value,
|
|
});
|
|
} else {
|
|
const valueExists = filters[key]?.includes(option.value);
|
|
|
|
if (valueExists)
|
|
setFilters({
|
|
[option.key]: ((filters[key] ?? []) as any[])?.filter(
|
|
(val) => val !== option.value
|
|
),
|
|
});
|
|
else
|
|
setFilters({
|
|
[option.key]: [...((filters[key] ?? []) as any[]), option.value],
|
|
});
|
|
}
|
|
}}
|
|
direction="left"
|
|
height="rg"
|
|
/>
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|