mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
535731141f
* chore: implemented cycles list filters and ordering * chore: active cycle tab updated * refactor: cycles folder structure * fix: name search inout auto-focus * fix: cycles ordering * refactor: move cycle filters logic to mobx store from local storage * chore: show completed cycles in a disclosure * chore: added completed cycles count * refactor: cycles mapping logic --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import { FC } from "react";
|
|
import { observer } from "mobx-react-lite";
|
|
import { useRouter } from "next/router";
|
|
// hooks
|
|
import { CycleGanttBlock } from "components/cycles";
|
|
import { GanttChartRoot, IBlockUpdateData, CycleGanttSidebar } from "components/gantt-chart";
|
|
import { useCycle } from "hooks/store";
|
|
// components
|
|
// types
|
|
import { ICycle } from "@plane/types";
|
|
// constants
|
|
|
|
type Props = {
|
|
workspaceSlug: string;
|
|
cycleIds: string[];
|
|
};
|
|
|
|
export const CyclesListGanttChartView: FC<Props> = observer((props) => {
|
|
const { cycleIds } = props;
|
|
// router
|
|
const router = useRouter();
|
|
const { workspaceSlug } = router.query;
|
|
// store hooks
|
|
const { getCycleById, updateCycleDetails } = useCycle();
|
|
|
|
const handleCycleUpdate = async (cycle: ICycle, data: IBlockUpdateData) => {
|
|
if (!workspaceSlug || !cycle) return;
|
|
|
|
const payload: any = { ...data };
|
|
if (data.sort_order) payload.sort_order = data.sort_order.newSortOrder;
|
|
|
|
await updateCycleDetails(workspaceSlug.toString(), cycle.project_id, cycle.id, payload);
|
|
};
|
|
|
|
const blockFormat = (blocks: (ICycle | null)[]) => {
|
|
if (!blocks) return [];
|
|
|
|
const filteredBlocks = blocks.filter((b) => b !== null && b.start_date && b.end_date);
|
|
|
|
const structuredBlocks = filteredBlocks.map((block) => ({
|
|
data: block,
|
|
id: block?.id ?? "",
|
|
sort_order: block?.sort_order ?? 0,
|
|
start_date: new Date(block?.start_date ?? ""),
|
|
target_date: new Date(block?.end_date ?? ""),
|
|
}));
|
|
|
|
return structuredBlocks;
|
|
};
|
|
|
|
return (
|
|
<div className="h-full w-full overflow-y-auto">
|
|
<GanttChartRoot
|
|
title="Cycles"
|
|
loaderTitle="Cycles"
|
|
blocks={cycleIds ? blockFormat(cycleIds.map((c) => getCycleById(c))) : null}
|
|
blockUpdateHandler={(block, payload) => handleCycleUpdate(block, payload)}
|
|
sidebarToRender={(props) => <CycleGanttSidebar {...props} />}
|
|
blockToRender={(data: ICycle) => <CycleGanttBlock cycleId={data.id} />}
|
|
enableBlockLeftResize={false}
|
|
enableBlockRightResize={false}
|
|
enableBlockMove={false}
|
|
enableReorder={false}
|
|
/>
|
|
</div>
|
|
);
|
|
});
|