Skip to content

Commit

Permalink
dev: show all issues on the gantt chart (#3487)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryan610 authored Jan 30, 2024
1 parent d53a086 commit 9debd81
Show file tree
Hide file tree
Showing 30 changed files with 234 additions and 166 deletions.
4 changes: 1 addition & 3 deletions packages/types/src/view-props.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export type TIssueParams =
| "order_by"
| "type"
| "sub_issue"
| "show_empty_groups"
| "start_target_date";
| "show_empty_groups";

export type TCalendarLayouts = "month" | "week";

Expand Down Expand Up @@ -93,7 +92,6 @@ export interface IIssueDisplayFilterOptions {
layout?: TIssueLayouts;
order_by?: TIssueOrderByOptions;
show_empty_groups?: boolean;
start_target_date?: boolean;
sub_issue?: boolean;
type?: TIssueTypeFilters;
}
Expand Down
6 changes: 3 additions & 3 deletions web/components/core/activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const IssueLink = ({ activity }: { activity: IIssueActivity }) => {
}`}`}
target={activity.issue === null ? "_self" : "_blank"}
rel={activity.issue === null ? "" : "noopener noreferrer"}
className="inline-flex items-center gap-1 font-medium text-custom-text-100 hover:underline whitespace-nowrap"
className="inline-flex items-center gap-1 font-medium text-custom-text-100 hover:underline"
>
{`${activity.project_detail.identifier}-${activity.issue_detail.sequence_id}`}{" "}
<span className="whitespace-nowrap">{`${activity.project_detail.identifier}-${activity.issue_detail.sequence_id}`}</span>{" "}
<span className="font-normal">{activity.issue_detail?.name}</span>
</a>
) : (
Expand Down Expand Up @@ -267,7 +267,7 @@ const activityDetails: {
<span className="flex-shrink truncate font-medium text-custom-text-100">{activity.new_value}</span>
</span>
{showIssue && (
<span>
<span className="">
{" "}
to <IssueLink activity={activity} />
</span>
Expand Down
2 changes: 1 addition & 1 deletion web/components/dashboard/widgets/overview-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const OverviewStatsWidget: React.FC<WidgetProps> = observer((props) => {
)}
>
<h5 className="font-semibold text-xl">{stat.count}</h5>
<p className="text-custom-text-300">{stat.title}</p>
<p className="text-custom-text-300 text-sm xl:text-base">{stat.title}</p>
</Link>
</div>
);
Expand Down
23 changes: 0 additions & 23 deletions web/components/dnd/StrictModeDroppable.tsx

This file was deleted.

52 changes: 30 additions & 22 deletions web/components/gantt-chart/blocks/blocks-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC } from "react";
// hooks
import { useChart } from "../hooks";
// helpers
import { ChartDraggable } from "../helpers/draggable";
import { ChartAddBlock, ChartDraggable } from "components/gantt-chart";
import { renderFormattedPayloadDate } from "helpers/date-time.helper";
// types
import { IBlockUpdateData, IGanttBlock } from "../types";
Expand All @@ -15,6 +15,7 @@ export type GanttChartBlocksProps = {
enableBlockLeftResize: boolean;
enableBlockRightResize: boolean;
enableBlockMove: boolean;
showAllBlocks: boolean;
};

export const GanttChartBlocks: FC<GanttChartBlocksProps> = (props) => {
Expand All @@ -26,6 +27,7 @@ export const GanttChartBlocks: FC<GanttChartBlocksProps> = (props) => {
enableBlockLeftResize,
enableBlockRightResize,
enableBlockMove,
showAllBlocks,
} = props;

const { activeBlock, dispatch } = useChart();
Expand All @@ -45,6 +47,8 @@ export const GanttChartBlocks: FC<GanttChartBlocksProps> = (props) => {
totalBlockShifts: number,
dragDirection: "left" | "right" | "move"
) => {
if (!block.start_date || !block.target_date) return;

const originalStartDate = new Date(block.start_date);
const updatedStartDate = new Date(originalStartDate);

Expand Down Expand Up @@ -75,27 +79,31 @@ export const GanttChartBlocks: FC<GanttChartBlocksProps> = (props) => {
>
{blocks &&
blocks.length > 0 &&
blocks.map(
(block) =>
block.start_date &&
block.target_date && (
<div
key={`block-${block.id}`}
className={`h-11 ${activeBlock?.id === block.id ? "bg-custom-background-80" : ""}`}
onMouseEnter={() => updateActiveBlock(block)}
onMouseLeave={() => updateActiveBlock(null)}
>
<ChartDraggable
block={block}
blockToRender={blockToRender}
handleBlock={(...args) => handleChartBlockPosition(block, ...args)}
enableBlockLeftResize={enableBlockLeftResize}
enableBlockRightResize={enableBlockRightResize}
enableBlockMove={enableBlockMove}
/>
</div>
)
)}
blocks.map((block) => {
// hide the block if it doesn't have start and target dates and showAllBlocks is false
if (!showAllBlocks && !(block.start_date && block.target_date)) return;

const isBlockVisibleOnChart = block.start_date && block.target_date;

return (
<div
key={`block-${block.id}`}
className={`h-11 ${activeBlock?.id === block.id ? "bg-custom-background-80" : ""}`}
onMouseEnter={() => updateActiveBlock(block)}
onMouseLeave={() => updateActiveBlock(null)}
>
{!isBlockVisibleOnChart && <ChartAddBlock block={block} blockUpdateHandler={blockUpdateHandler} />}
<ChartDraggable
block={block}
blockToRender={blockToRender}
handleBlock={(...args) => handleChartBlockPosition(block, ...args)}
enableBlockLeftResize={enableBlockLeftResize}
enableBlockRightResize={enableBlockRightResize}
enableBlockMove={enableBlockMove}
/>
</div>
);
})}
</div>
);
};
32 changes: 18 additions & 14 deletions web/components/gantt-chart/chart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,25 @@ type ChartViewRootProps = {
enableBlockMove: boolean;
enableReorder: boolean;
bottomSpacing: boolean;
showAllBlocks: boolean;
};

export const ChartViewRoot: FC<ChartViewRootProps> = ({
border,
title,
blocks = null,
loaderTitle,
blockUpdateHandler,
sidebarToRender,
blockToRender,
enableBlockLeftResize,
enableBlockRightResize,
enableBlockMove,
enableReorder,
bottomSpacing,
}) => {
export const ChartViewRoot: FC<ChartViewRootProps> = (props) => {
const {
border,
title,
blocks = null,
loaderTitle,
blockUpdateHandler,
sidebarToRender,
blockToRender,
enableBlockLeftResize,
enableBlockRightResize,
enableBlockMove,
enableReorder,
bottomSpacing,
showAllBlocks,
} = props;
// states
const [itemsContainerWidth, setItemsContainerWidth] = useState<number>(0);
const [fullScreenMode, setFullScreenMode] = useState<boolean>(false);
Expand Down Expand Up @@ -311,6 +314,7 @@ export const ChartViewRoot: FC<ChartViewRootProps> = ({
enableBlockLeftResize={enableBlockLeftResize}
enableBlockRightResize={enableBlockRightResize}
enableBlockMove={enableBlockMove}
showAllBlocks={showAllBlocks}
/>
)}
</div>
Expand Down
1 change: 0 additions & 1 deletion web/components/gantt-chart/chart/month.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FC } from "react";

// hooks
import { useChart } from "../hooks";
// types
Expand Down
91 changes: 91 additions & 0 deletions web/components/gantt-chart/helpers/add-block.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { useEffect, useRef, useState } from "react";
import { addDays } from "date-fns";
import { Plus } from "lucide-react";
// hooks
import { useChart } from "../hooks";
// ui
import { Tooltip } from "@plane/ui";
// helpers
import { renderFormattedDate, renderFormattedPayloadDate } from "helpers/date-time.helper";
// types
import { IBlockUpdateData, IGanttBlock } from "../types";

type Props = {
block: IGanttBlock;
blockUpdateHandler: (block: any, payload: IBlockUpdateData) => void;
};

export const ChartAddBlock: React.FC<Props> = (props) => {
const { block, blockUpdateHandler } = props;
// states
const [isButtonVisible, setIsButtonVisible] = useState(false);
const [buttonXPosition, setButtonXPosition] = useState(0);
const [buttonStartDate, setButtonStartDate] = useState<Date | null>(null);
// refs
const containerRef = useRef<HTMLDivElement>(null);
// chart hook
const { currentViewData } = useChart();

const handleButtonClick = () => {
if (!currentViewData) return;

const { startDate: chartStartDate, width } = currentViewData.data;
const columnNumber = buttonXPosition / width;

const startDate = addDays(chartStartDate, columnNumber);
const endDate = addDays(startDate, 1);

blockUpdateHandler(block.data, {
start_date: renderFormattedPayloadDate(startDate) ?? undefined,
target_date: renderFormattedPayloadDate(endDate) ?? undefined,
});
};

useEffect(() => {
const container = containerRef.current;

if (!container) return;

const handleMouseMove = (e: MouseEvent) => {
if (!currentViewData) return;

setButtonXPosition(e.offsetX);

const { startDate: chartStartDate, width } = currentViewData.data;
const columnNumber = buttonXPosition / width;

const startDate = addDays(chartStartDate, columnNumber);
setButtonStartDate(startDate);
};

container.addEventListener("mousemove", handleMouseMove);

return () => {
container?.removeEventListener("mousemove", handleMouseMove);
};
}, [buttonXPosition, currentViewData]);

return (
<div
className="relative h-full w-full"
onMouseEnter={() => setIsButtonVisible(true)}
onMouseLeave={() => setIsButtonVisible(false)}
>
<div ref={containerRef} className="h-full w-full" />
{isButtonVisible && (
<Tooltip tooltipContent={buttonStartDate && renderFormattedDate(buttonStartDate)}>
<button
type="button"
className="absolute top-1/2 -translate-x-1/2 -translate-y-1/2 h-8 w-8 bg-custom-background-80 p-1.5 rounded border border-custom-border-300 grid place-items-center text-custom-text-200 hover:text-custom-text-100"
style={{
marginLeft: `${buttonXPosition}px`,
}}
onClick={handleButtonClick}
>
<Plus className="h-3.5 w-3.5" />
</button>
</Tooltip>
)}
</div>
);
};
19 changes: 8 additions & 11 deletions web/components/gantt-chart/helpers/block-structure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { TIssue } from "@plane/types";
import { IGanttBlock } from "components/gantt-chart";

export const renderIssueBlocksStructure = (blocks: TIssue[]): IGanttBlock[] =>
blocks && blocks.length > 0
? blocks
.filter((b) => new Date(b?.start_date ?? "") <= new Date(b?.target_date ?? ""))
.map((block) => ({
data: block,
id: block.id,
sort_order: block.sort_order,
start_date: new Date(block.start_date ?? ""),
target_date: new Date(block.target_date ?? ""),
}))
: [];
blocks &&
blocks.map((block) => ({
data: block,
id: block.id,
sort_order: block.sort_order,
start_date: block.start_date ? new Date(block.start_date) : null,
target_date: block.target_date ? new Date(block.target_date) : null,
}));
Loading

0 comments on commit 9debd81

Please sign in to comment.