2024-03-18 07:21:19 +00:00
|
|
|
import { useState, useRef } from "react";
|
2024-03-25 08:47:34 +00:00
|
|
|
import { Placement } from "@popperjs/core";
|
2024-03-18 07:21:19 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { MoreHorizontal } from "lucide-react";
|
|
|
|
import { TIssue } from "@plane/types";
|
2024-03-18 07:21:19 +00:00
|
|
|
// components
|
|
|
|
import { Tooltip, ControlLink } from "@plane/ui";
|
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { cn } from "@/helpers/common.helper";
|
2024-04-29 06:42:33 +00:00
|
|
|
import { useAppRouter, useIssueDetail, useProject, useProjectState } from "@/hooks/store";
|
2024-03-19 14:38:35 +00:00
|
|
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
2024-03-18 07:21:19 +00:00
|
|
|
// helpers
|
|
|
|
// types
|
2024-03-19 14:38:35 +00:00
|
|
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
2024-03-18 07:21:19 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: TIssue;
|
2024-03-25 08:47:34 +00:00
|
|
|
quickActions: (issue: TIssue, customActionButton?: React.ReactElement, placement?: Placement) => React.ReactNode;
|
2024-03-18 07:21:19 +00:00
|
|
|
isDragging?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const CalendarIssueBlock: React.FC<Props> = observer((props) => {
|
|
|
|
const { issue, quickActions, isDragging = false } = props;
|
|
|
|
// hooks
|
2024-04-29 06:42:33 +00:00
|
|
|
const { workspaceSlug, projectId } = useAppRouter();
|
2024-03-18 07:21:19 +00:00
|
|
|
const { getProjectIdentifierById } = useProject();
|
|
|
|
const { getProjectStates } = useProjectState();
|
|
|
|
const { peekIssue, setPeekIssue } = useIssueDetail();
|
|
|
|
const { isMobile } = usePlatformOS();
|
|
|
|
// states
|
|
|
|
const [isMenuActive, setIsMenuActive] = useState(false);
|
|
|
|
|
|
|
|
const menuActionRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
|
|
|
const stateColor = getProjectStates(issue?.project_id)?.find((state) => state?.id == issue?.state_id)?.color || "";
|
|
|
|
|
|
|
|
const handleIssuePeekOverview = (issue: TIssue) =>
|
|
|
|
workspaceSlug &&
|
|
|
|
issue &&
|
|
|
|
issue.project_id &&
|
|
|
|
issue.id &&
|
2024-04-08 13:08:05 +00:00
|
|
|
peekIssue?.issueId !== issue.id &&
|
2024-03-18 07:21:19 +00:00
|
|
|
setPeekIssue({ workspaceSlug, projectId: issue.project_id, issueId: issue.id });
|
|
|
|
|
|
|
|
useOutsideClickDetector(menuActionRef, () => setIsMenuActive(false));
|
|
|
|
|
|
|
|
const customActionButton = (
|
|
|
|
<div
|
|
|
|
ref={menuActionRef}
|
|
|
|
className={`w-full cursor-pointer rounded p-1 text-custom-sidebar-text-400 hover:bg-custom-background-80 ${
|
|
|
|
isMenuActive ? "bg-custom-background-80 text-custom-text-100" : "text-custom-text-200"
|
|
|
|
}`}
|
|
|
|
onClick={() => setIsMenuActive(!isMenuActive)}
|
|
|
|
>
|
|
|
|
<MoreHorizontal className="h-3.5 w-3.5" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2024-03-25 08:47:34 +00:00
|
|
|
const isMenuActionRefAboveScreenBottom =
|
|
|
|
menuActionRef?.current && menuActionRef?.current?.getBoundingClientRect().bottom < window.innerHeight - 220;
|
|
|
|
|
|
|
|
const placement = isMenuActionRefAboveScreenBottom ? "bottom-end" : "top-end";
|
|
|
|
|
2024-03-18 07:21:19 +00:00
|
|
|
return (
|
|
|
|
<ControlLink
|
2024-04-08 13:08:05 +00:00
|
|
|
id={`issue-${issue.id}`}
|
2024-03-18 07:21:19 +00:00
|
|
|
href={`/${workspaceSlug}/projects/${projectId}/issues/${issue.id}`}
|
|
|
|
target="_blank"
|
|
|
|
onClick={() => handleIssuePeekOverview(issue)}
|
|
|
|
className="w-full cursor-pointer text-sm text-custom-text-100"
|
|
|
|
disabled={!!issue?.tempId}
|
|
|
|
>
|
|
|
|
<>
|
|
|
|
{issue?.tempId !== undefined && (
|
|
|
|
<div className="absolute left-0 top-0 z-[99999] h-full w-full animate-pulse bg-custom-background-100/20" />
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div
|
|
|
|
className={cn(
|
2024-04-29 06:42:33 +00:00
|
|
|
"group/calendar-block flex h-10 w-full items-center justify-between gap-1.5 rounded border-b border-custom-border-200 px-4 py-1.5 hover:border-custom-border-400 md:h-8 md:border-[0.5px] md:px-1 ",
|
2024-03-18 07:21:19 +00:00
|
|
|
{
|
2024-04-29 06:42:33 +00:00
|
|
|
"border-custom-primary-100 bg-custom-background-90 shadow-custom-shadow-rg": isDragging,
|
2024-03-18 07:21:19 +00:00
|
|
|
},
|
|
|
|
{ "bg-custom-background-100 hover:bg-custom-background-90": !isDragging },
|
|
|
|
{
|
|
|
|
"border border-custom-primary-70 hover:border-custom-primary-70": peekIssue?.issueId === issue.id,
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<div className="flex h-full items-center gap-1.5 truncate">
|
|
|
|
<span
|
|
|
|
className="h-full w-0.5 flex-shrink-0 rounded"
|
|
|
|
style={{
|
|
|
|
backgroundColor: stateColor,
|
|
|
|
}}
|
|
|
|
/>
|
2024-04-29 06:42:33 +00:00
|
|
|
<div className="flex-shrink-0 text-sm text-custom-text-300 md:text-xs">
|
2024-03-18 07:21:19 +00:00
|
|
|
{getProjectIdentifierById(issue?.project_id)}-{issue.sequence_id}
|
|
|
|
</div>
|
|
|
|
<Tooltip tooltipContent={issue.name} isMobile={isMobile}>
|
2024-04-29 06:42:33 +00:00
|
|
|
<div className="truncate text-sm font-medium md:text-xs md:font-normal">{issue.name}</div>
|
2024-03-18 07:21:19 +00:00
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
<div
|
2024-04-29 06:42:33 +00:00
|
|
|
className={`h-5 w-5 flex-shrink-0 group-hover/calendar-block:block md:hidden ${
|
2024-03-18 07:21:19 +00:00
|
|
|
isMenuActive ? "!block" : ""
|
|
|
|
}`}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
>
|
2024-03-25 08:47:34 +00:00
|
|
|
{quickActions(issue, customActionButton, placement)}
|
2024-03-18 07:21:19 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
</ControlLink>
|
|
|
|
);
|
|
|
|
});
|