2023-11-06 15:30:36 +00:00
|
|
|
import { FC, useCallback, useState } from "react";
|
2023-10-20 11:37:46 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-10-17 10:53:54 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2023-10-20 11:37:46 +00:00
|
|
|
import { DragDropContext } from "@hello-pangea/dnd";
|
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-10-17 10:53:54 +00:00
|
|
|
// components
|
2023-10-25 14:17:58 +00:00
|
|
|
import { KanBanSwimLanes } from "../swimlanes";
|
|
|
|
import { KanBan } from "../default";
|
2023-10-20 11:37:46 +00:00
|
|
|
import { ProjectIssueQuickActions } from "components/issues";
|
2023-11-06 15:30:36 +00:00
|
|
|
import { Spinner } from "@plane/ui";
|
2023-10-18 14:28:05 +00:00
|
|
|
// constants
|
|
|
|
import { ISSUE_STATE_GROUPS, ISSUE_PRIORITIES } from "constants/issue";
|
2023-10-20 11:37:46 +00:00
|
|
|
// types
|
|
|
|
import { IIssue } from "types";
|
2023-11-23 09:17:04 +00:00
|
|
|
import { EIssueActions } from "../../types";
|
2023-10-17 10:53:54 +00:00
|
|
|
|
|
|
|
export interface IProfileIssuesKanBanLayout {}
|
|
|
|
|
2023-10-18 14:28:05 +00:00
|
|
|
export const ProfileIssuesKanBanLayout: FC = observer(() => {
|
2023-10-17 10:53:54 +00:00
|
|
|
const {
|
2023-10-18 14:28:05 +00:00
|
|
|
workspace: workspaceStore,
|
|
|
|
project: projectStore,
|
2023-11-09 12:26:55 +00:00
|
|
|
projectMember: { projectMembers },
|
2023-11-08 15:01:46 +00:00
|
|
|
projectState: projectStateStore,
|
2023-10-17 10:53:54 +00:00
|
|
|
profileIssues: profileIssuesStore,
|
|
|
|
profileIssueFilters: profileIssueFiltersStore,
|
|
|
|
issueKanBanView: issueKanBanViewStore,
|
2023-10-20 11:37:46 +00:00
|
|
|
issueDetail: issueDetailStore,
|
|
|
|
} = useMobxStore();
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
2023-10-17 10:53:54 +00:00
|
|
|
|
|
|
|
const issues = profileIssuesStore?.getIssues;
|
|
|
|
|
|
|
|
const sub_group_by: string | null = profileIssueFiltersStore?.userDisplayFilters?.sub_group_by || null;
|
|
|
|
|
|
|
|
const group_by: string | null = profileIssueFiltersStore?.userDisplayFilters?.group_by || null;
|
|
|
|
|
2023-11-06 15:30:36 +00:00
|
|
|
const order_by: string | null = profileIssueFiltersStore?.userDisplayFilters?.order_by || null;
|
|
|
|
|
2023-11-02 13:14:02 +00:00
|
|
|
const userDisplayFilters = profileIssueFiltersStore?.userDisplayFilters || null;
|
|
|
|
|
2023-10-31 06:36:11 +00:00
|
|
|
const displayProperties = profileIssueFiltersStore?.userDisplayProperties || null;
|
2023-10-17 10:53:54 +00:00
|
|
|
|
|
|
|
const currentKanBanView: "swimlanes" | "default" = profileIssueFiltersStore?.userDisplayFilters?.sub_group_by
|
|
|
|
? "swimlanes"
|
|
|
|
: "default";
|
|
|
|
|
2023-11-06 15:30:36 +00:00
|
|
|
const [isDragStarted, setIsDragStarted] = useState<boolean>(false);
|
|
|
|
|
2023-11-09 12:26:55 +00:00
|
|
|
// const onDragStart = () => {
|
|
|
|
// setIsDragStarted(true);
|
|
|
|
// };
|
2023-11-06 15:30:36 +00:00
|
|
|
|
2023-10-17 10:53:54 +00:00
|
|
|
const onDragEnd = (result: any) => {
|
2023-11-06 15:30:36 +00:00
|
|
|
setIsDragStarted(false);
|
2023-10-17 10:53:54 +00:00
|
|
|
if (!result) return;
|
|
|
|
|
|
|
|
if (
|
|
|
|
result.destination &&
|
|
|
|
result.source &&
|
|
|
|
result.destination.droppableId === result.source.droppableId &&
|
|
|
|
result.destination.index === result.source.index
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
|
|
|
|
currentKanBanView === "default"
|
|
|
|
? issueKanBanViewStore?.handleDragDrop(result.source, result.destination)
|
|
|
|
: issueKanBanViewStore?.handleSwimlaneDragDrop(result.source, result.destination);
|
|
|
|
};
|
|
|
|
|
2023-10-20 11:37:46 +00:00
|
|
|
const handleIssues = useCallback(
|
2023-11-23 09:17:04 +00:00
|
|
|
(sub_group_by: string | null, group_by: string | null, issue: IIssue, action: EIssueActions) => {
|
2023-10-20 11:37:46 +00:00
|
|
|
if (!workspaceSlug) return;
|
|
|
|
|
2023-11-23 09:17:04 +00:00
|
|
|
if (action === EIssueActions.UPDATE) {
|
2023-10-20 11:37:46 +00:00
|
|
|
profileIssuesStore.updateIssueStructure(group_by, sub_group_by, issue);
|
|
|
|
issueDetailStore.updateIssue(workspaceSlug.toString(), issue.project, issue.id, issue);
|
|
|
|
}
|
2023-11-23 09:17:04 +00:00
|
|
|
if (action === EIssueActions.DELETE) profileIssuesStore.deleteIssue(group_by, sub_group_by, issue);
|
2023-10-20 11:37:46 +00:00
|
|
|
},
|
|
|
|
[profileIssuesStore, issueDetailStore, workspaceSlug]
|
|
|
|
);
|
2023-10-17 10:53:54 +00:00
|
|
|
|
|
|
|
const handleKanBanToggle = (toggle: "groupByHeaderMinMax" | "subgroupByIssuesVisibility", value: string) => {
|
|
|
|
issueKanBanViewStore.handleKanBanToggle(toggle, value);
|
|
|
|
};
|
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
const states = projectStateStore?.projectStates || null;
|
2023-10-18 14:28:05 +00:00
|
|
|
const priorities = ISSUE_PRIORITIES || null;
|
|
|
|
const labels = workspaceStore.workspaceLabels || null;
|
|
|
|
const stateGroups = ISSUE_STATE_GROUPS || null;
|
|
|
|
const projects = projectStore?.workspaceProjects || null;
|
|
|
|
|
2023-10-17 10:53:54 +00:00
|
|
|
return (
|
2023-11-06 15:30:36 +00:00
|
|
|
<>
|
|
|
|
{profileIssuesStore.loader ? (
|
|
|
|
<div className="w-full h-full flex justify-center items-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className={`relative min-w-full w-max min-h-full h-max bg-custom-background-90 px-3`}>
|
|
|
|
<DragDropContext onDragEnd={onDragEnd}>
|
|
|
|
{currentKanBanView === "default" ? (
|
|
|
|
<KanBan
|
2023-11-23 09:17:04 +00:00
|
|
|
issues={{}}
|
|
|
|
issueIds={[]}
|
2023-11-06 15:30:36 +00:00
|
|
|
sub_group_by={sub_group_by}
|
|
|
|
group_by={group_by}
|
|
|
|
order_by={order_by}
|
|
|
|
handleIssues={handleIssues}
|
|
|
|
quickActions={(sub_group_by, group_by, issue) => (
|
|
|
|
<ProjectIssueQuickActions
|
|
|
|
issue={issue}
|
2023-11-23 09:17:04 +00:00
|
|
|
handleDelete={async () => handleIssues(sub_group_by, group_by, issue, EIssueActions.DELETE)}
|
|
|
|
handleUpdate={async (data) => handleIssues(sub_group_by, group_by, data, EIssueActions.UPDATE)}
|
2023-11-06 15:30:36 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
displayProperties={displayProperties}
|
|
|
|
kanBanToggle={issueKanBanViewStore?.kanBanToggle}
|
|
|
|
handleKanBanToggle={handleKanBanToggle}
|
|
|
|
states={states}
|
|
|
|
stateGroups={stateGroups}
|
|
|
|
priorities={priorities}
|
|
|
|
labels={labels}
|
2023-11-09 12:26:55 +00:00
|
|
|
members={projectMembers?.map((m) => m.member) ?? null}
|
2023-11-06 15:30:36 +00:00
|
|
|
projects={projects}
|
|
|
|
showEmptyGroup={userDisplayFilters?.show_empty_groups || true}
|
|
|
|
isDragStarted={isDragStarted}
|
2023-10-20 11:37:46 +00:00
|
|
|
/>
|
2023-11-06 15:30:36 +00:00
|
|
|
) : (
|
|
|
|
<KanBanSwimLanes
|
2023-11-23 09:17:04 +00:00
|
|
|
issues={{}}
|
|
|
|
issueIds={[]}
|
2023-11-06 15:30:36 +00:00
|
|
|
sub_group_by={sub_group_by}
|
|
|
|
group_by={group_by}
|
|
|
|
order_by={order_by}
|
|
|
|
handleIssues={handleIssues}
|
|
|
|
quickActions={(sub_group_by, group_by, issue) => (
|
|
|
|
<ProjectIssueQuickActions
|
|
|
|
issue={issue}
|
2023-11-23 09:17:04 +00:00
|
|
|
handleDelete={async () => handleIssues(sub_group_by, group_by, issue, EIssueActions.DELETE)}
|
|
|
|
handleUpdate={async (data) => handleIssues(sub_group_by, group_by, data, EIssueActions.UPDATE)}
|
2023-11-06 15:30:36 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
displayProperties={displayProperties}
|
|
|
|
kanBanToggle={issueKanBanViewStore?.kanBanToggle}
|
|
|
|
handleKanBanToggle={handleKanBanToggle}
|
|
|
|
states={states}
|
|
|
|
stateGroups={stateGroups}
|
|
|
|
priorities={priorities}
|
|
|
|
labels={labels}
|
2023-11-09 12:26:55 +00:00
|
|
|
members={projectMembers?.map((m) => m.member) ?? null}
|
2023-11-06 15:30:36 +00:00
|
|
|
projects={projects}
|
|
|
|
showEmptyGroup={userDisplayFilters?.show_empty_groups || true}
|
|
|
|
isDragStarted={isDragStarted}
|
2023-10-20 11:37:46 +00:00
|
|
|
/>
|
|
|
|
)}
|
2023-11-06 15:30:36 +00:00
|
|
|
</DragDropContext>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
2023-10-17 10:53:54 +00:00
|
|
|
);
|
|
|
|
});
|