From b45ed5c34ca458e60c3a6fec6649ca6f04249f35 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Thu, 1 Feb 2024 13:56:59 +0530 Subject: [PATCH] chore: add arrow navigation position logic --- web/components/gantt-chart/contexts/index.tsx | 9 +++- .../gantt-chart/helpers/draggable.tsx | 48 ++++++++++++------- .../gantt-chart/sidebar/sidebar.tsx | 8 ++-- .../issues/issue-layouts/gantt/blocks.tsx | 7 ++- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/web/components/gantt-chart/contexts/index.tsx b/web/components/gantt-chart/contexts/index.tsx index ed05c3676..ca8a6b9d5 100644 --- a/web/components/gantt-chart/contexts/index.tsx +++ b/web/components/gantt-chart/contexts/index.tsx @@ -47,7 +47,14 @@ export const ChartContextProvider: React.FC<{ children: React.ReactNode }> = ({ return ( {children} diff --git a/web/components/gantt-chart/helpers/draggable.tsx b/web/components/gantt-chart/helpers/draggable.tsx index 81d006f41..e3f6bc3d2 100644 --- a/web/components/gantt-chart/helpers/draggable.tsx +++ b/web/components/gantt-chart/helpers/draggable.tsx @@ -1,9 +1,9 @@ import React, { useEffect, useRef, useState } from "react"; import { ArrowLeft, ArrowRight } from "lucide-react"; // hooks -import { useChart } from "../hooks"; -// types -import { IGanttBlock } from "../types"; +import { IGanttBlock, useChart } from "components/gantt-chart"; +// helpers +import { cn } from "helpers/common.helper"; type Props = { block: IGanttBlock; @@ -201,10 +201,8 @@ export const ChartDraggable: React.FC = (props) => { }; // scroll to a hidden block const handleScrollToBlock = () => { - const scrollContainer = document.querySelector("#scroll-container") as HTMLElement; - + const scrollContainer = document.querySelector("#scroll-container") as HTMLDivElement; if (!scrollContainer || !block.position) return; - // update container's scroll position to the block's position scrollContainer.scrollLeft = block.position.marginLeft - 4; }; @@ -225,13 +223,18 @@ export const ChartDraggable: React.FC = (props) => { const textDisplacement = scrollLeft - (block.position?.marginLeft ?? 0); + console.log("scrollLeft", scrollLeft); + return ( <> {/* move to left side hidden block button */} {isBlockHiddenOnLeft && (
@@ -239,8 +242,11 @@ export const ChartDraggable: React.FC = (props) => { {/* move to right side hidden block button */} {isBlockHiddenOnRight && (
@@ -261,17 +267,22 @@ export const ChartDraggable: React.FC = (props) => { onMouseDown={handleBlockLeftResize} onMouseEnter={() => setIsLeftResizing(true)} onMouseLeave={() => setIsLeftResizing(false)} - className="absolute -left-2.5 top-1/2 z-[3] h-full w-6 -translate-y-1/2 cursor-col-resize rounded-md" + className="absolute -left-2.5 top-1/2 -translate-y-1/2 z-[3] h-full w-6 cursor-col-resize rounded-md" />
)}
{blockToRender(block.data, textDisplacement)} @@ -283,12 +294,15 @@ export const ChartDraggable: React.FC = (props) => { onMouseDown={handleBlockRightResize} onMouseEnter={() => setIsRightResizing(true)} onMouseLeave={() => setIsRightResizing(false)} - className="absolute -right-2.5 top-1/2 z-[2] h-full w-6 -translate-y-1/2 cursor-col-resize rounded-md" + className="absolute -right-2.5 top-1/2 -translate-y-1/2 z-[2] h-full w-6 cursor-col-resize rounded-md" />
)} diff --git a/web/components/gantt-chart/sidebar/sidebar.tsx b/web/components/gantt-chart/sidebar/sidebar.tsx index f4d06c8a3..b140f72eb 100644 --- a/web/components/gantt-chart/sidebar/sidebar.tsx +++ b/web/components/gantt-chart/sidebar/sidebar.tsx @@ -157,13 +157,13 @@ export const IssueGanttSidebar: React.FC = (props) => {
-
- {duration && ( + {duration && ( +
{duration} day{duration > 1 ? "s" : ""} - )} -
+
+ )}
diff --git a/web/components/issues/issue-layouts/gantt/blocks.tsx b/web/components/issues/issue-layouts/gantt/blocks.tsx index 9d73eceea..210a4a5d9 100644 --- a/web/components/issues/issue-layouts/gantt/blocks.tsx +++ b/web/components/issues/issue-layouts/gantt/blocks.tsx @@ -61,7 +61,7 @@ export const IssueGanttBlock = ({ data, textDisplacement }: { data: TIssue; text // rendering issues on gantt sidebar export const IssueGanttSidebarBlock = ({ data }: { data: TIssue }) => { // hooks - const { getProjectStates } = useProjectState(); + const { getStateById } = useProjectState(); const { getProjectById } = useProject(); const { router: { workspaceSlug }, @@ -75,8 +75,7 @@ export const IssueGanttSidebarBlock = ({ data }: { data: TIssue }) => { data.id && setPeekIssue({ workspaceSlug, projectId: data.project_id, issueId: data.id }); - const currentStateDetails = - getProjectStates(data?.project_id)?.find((state) => state?.id == data?.state_id) || undefined; + const currentStateDetails = getStateById(data?.state_id); return ( { className="w-full line-clamp-1 cursor-pointer text-sm text-custom-text-100" >
- {currentStateDetails != undefined && ( + {currentStateDetails && ( )}