mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
36152ea2fa
* chore: add loading states to layouts * chore: don't show count for 0 inbox issues
96 lines
3.3 KiB
TypeScript
96 lines
3.3 KiB
TypeScript
import React, { useState } from "react";
|
|
import { useRouter } from "next/router";
|
|
import { observer } from "mobx-react-lite";
|
|
import useSWR from "swr";
|
|
// mobx store
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
// components
|
|
import {
|
|
CycleAppliedFiltersRoot,
|
|
CycleCalendarLayout,
|
|
CycleEmptyState,
|
|
CycleGanttLayout,
|
|
CycleKanBanLayout,
|
|
CycleListLayout,
|
|
CycleSpreadsheetLayout,
|
|
} from "components/issues";
|
|
import { TransferIssues, TransferIssuesModal } from "components/cycles";
|
|
// ui
|
|
import { Spinner } from "@plane/ui";
|
|
// helpers
|
|
import { getDateRangeStatus } from "helpers/date-time.helper";
|
|
|
|
type Props = {
|
|
openIssuesListModal: () => void;
|
|
};
|
|
|
|
export const CycleLayoutRoot: React.FC<Props> = observer(({ openIssuesListModal }) => {
|
|
const [transferIssuesModal, setTransferIssuesModal] = useState(false);
|
|
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId, cycleId } = router.query;
|
|
|
|
const {
|
|
issueFilter: issueFilterStore,
|
|
cycle: cycleStore,
|
|
cycleIssue: cycleIssueStore,
|
|
cycleIssueFilter: cycleIssueFilterStore,
|
|
} = useMobxStore();
|
|
|
|
useSWR(workspaceSlug && projectId && cycleId ? `CYCLE_FILTERS_AND_ISSUES_${cycleId.toString()}` : null, async () => {
|
|
if (workspaceSlug && projectId && cycleId) {
|
|
// fetching the project display filters and display properties
|
|
await issueFilterStore.fetchUserProjectFilters(workspaceSlug.toString(), projectId.toString());
|
|
// fetching the cycle filters
|
|
await cycleIssueFilterStore.fetchCycleFilters(workspaceSlug.toString(), projectId.toString(), cycleId.toString());
|
|
|
|
// fetching the cycle issues
|
|
await cycleIssueStore.fetchIssues(workspaceSlug.toString(), projectId.toString(), cycleId.toString());
|
|
}
|
|
});
|
|
|
|
const activeLayout = issueFilterStore.userDisplayFilters.layout;
|
|
|
|
const cycleDetails = cycleId ? cycleStore.cycle_details[cycleId.toString()] : undefined;
|
|
const cycleStatus =
|
|
cycleDetails?.start_date && cycleDetails?.end_date
|
|
? getDateRangeStatus(cycleDetails?.start_date, cycleDetails?.end_date)
|
|
: "draft";
|
|
|
|
const issueCount = cycleIssueStore.getIssuesCount;
|
|
|
|
if (!cycleIssueStore.getIssues)
|
|
return (
|
|
<div className="h-full w-full grid place-items-center">
|
|
<Spinner />
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<TransferIssuesModal handleClose={() => setTransferIssuesModal(false)} isOpen={transferIssuesModal} />
|
|
<div className="relative w-full h-full flex flex-col overflow-hidden">
|
|
{cycleStatus === "completed" && <TransferIssues handleClick={() => setTransferIssuesModal(true)} />}
|
|
<CycleAppliedFiltersRoot />
|
|
{(activeLayout === "list" || activeLayout === "spreadsheet") && issueCount === 0 ? (
|
|
<CycleEmptyState openIssuesListModal={openIssuesListModal} />
|
|
) : (
|
|
<div className="w-full h-full overflow-auto">
|
|
{activeLayout === "list" ? (
|
|
<CycleListLayout />
|
|
) : activeLayout === "kanban" ? (
|
|
<CycleKanBanLayout />
|
|
) : activeLayout === "calendar" ? (
|
|
<CycleCalendarLayout />
|
|
) : activeLayout === "gantt_chart" ? (
|
|
<CycleGanttLayout />
|
|
) : activeLayout === "spreadsheet" ? (
|
|
<CycleSpreadsheetLayout />
|
|
) : null}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
});
|