2023-02-05 11:27:37 +00:00
|
|
|
import { useCallback, useState } from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR, { mutate } from "swr";
|
|
|
|
|
|
|
|
// react-beautiful-dnd
|
2023-02-13 05:02:02 +00:00
|
|
|
import { DragDropContext, DropResult } from "react-beautiful-dnd";
|
2023-02-05 11:27:37 +00:00
|
|
|
// services
|
|
|
|
import issuesService from "services/issues.service";
|
|
|
|
import stateService from "services/state.service";
|
|
|
|
import projectService from "services/project.service";
|
2023-02-05 16:31:23 +00:00
|
|
|
import modulesService from "services/modules.service";
|
2023-03-23 19:41:42 +00:00
|
|
|
import viewsService from "services/views.service";
|
2023-02-05 11:27:37 +00:00
|
|
|
// hooks
|
2023-03-22 12:48:19 +00:00
|
|
|
import useToast from "hooks/use-toast";
|
2023-03-15 06:14:44 +00:00
|
|
|
import useIssuesView from "hooks/use-issues-view";
|
2023-02-05 11:27:37 +00:00
|
|
|
// components
|
2023-02-08 13:21:03 +00:00
|
|
|
import { AllLists, AllBoards } from "components/core";
|
2023-02-05 11:27:37 +00:00
|
|
|
import { CreateUpdateIssueModal, DeleteIssueModal } from "components/issues";
|
2023-02-13 05:02:02 +00:00
|
|
|
import StrictModeDroppable from "components/dnd/StrictModeDroppable";
|
2023-03-16 08:37:19 +00:00
|
|
|
import { CreateUpdateViewModal } from "components/views";
|
2023-03-17 05:10:38 +00:00
|
|
|
// ui
|
2023-03-22 13:36:36 +00:00
|
|
|
import { Avatar, EmptySpace, EmptySpaceItem, PrimaryButton, Spinner } from "components/ui";
|
2023-02-13 05:02:02 +00:00
|
|
|
// icons
|
2023-03-22 11:28:32 +00:00
|
|
|
import {
|
|
|
|
ListBulletIcon,
|
|
|
|
PlusIcon,
|
|
|
|
RectangleStackIcon,
|
|
|
|
TrashIcon,
|
|
|
|
XMarkIcon,
|
|
|
|
} from "@heroicons/react/24/outline";
|
2023-03-28 13:18:57 +00:00
|
|
|
import { ExclamationIcon, getStateGroupIcon } from "components/icons";
|
2023-02-08 13:21:03 +00:00
|
|
|
// helpers
|
|
|
|
import { getStatesList } from "helpers/state.helper";
|
2023-02-05 11:27:37 +00:00
|
|
|
// types
|
2023-03-16 08:37:19 +00:00
|
|
|
import {
|
|
|
|
CycleIssueResponse,
|
|
|
|
IIssue,
|
|
|
|
IIssueFilterOptions,
|
|
|
|
ModuleIssueResponse,
|
|
|
|
UserAuth,
|
|
|
|
} from "types";
|
2023-02-05 11:27:37 +00:00
|
|
|
// fetch-keys
|
|
|
|
import {
|
|
|
|
CYCLE_ISSUES,
|
2023-03-15 06:14:44 +00:00
|
|
|
CYCLE_ISSUES_WITH_PARAMS,
|
2023-02-05 11:27:37 +00:00
|
|
|
MODULE_ISSUES,
|
2023-03-15 06:14:44 +00:00
|
|
|
MODULE_ISSUES_WITH_PARAMS,
|
|
|
|
PROJECT_ISSUES_LIST_WITH_PARAMS,
|
2023-02-05 11:27:37 +00:00
|
|
|
PROJECT_MEMBERS,
|
|
|
|
STATE_LIST,
|
2023-03-23 19:41:42 +00:00
|
|
|
VIEW_DETAILS,
|
2023-02-05 11:27:37 +00:00
|
|
|
} from "constants/fetch-keys";
|
2023-03-22 09:17:13 +00:00
|
|
|
import { getPriorityIcon } from "components/icons/priority-icon";
|
2023-02-05 11:27:37 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
type?: "issue" | "cycle" | "module";
|
|
|
|
openIssuesListModal?: () => void;
|
2023-03-23 17:12:08 +00:00
|
|
|
isCompleted?: boolean;
|
2023-02-05 11:27:37 +00:00
|
|
|
userAuth: UserAuth;
|
|
|
|
};
|
|
|
|
|
2023-03-23 17:12:08 +00:00
|
|
|
export const IssuesView: React.FC<Props> = ({
|
|
|
|
type = "issue",
|
|
|
|
openIssuesListModal,
|
|
|
|
isCompleted = false,
|
|
|
|
userAuth,
|
|
|
|
}) => {
|
2023-02-05 11:27:37 +00:00
|
|
|
// create issue modal
|
|
|
|
const [createIssueModal, setCreateIssueModal] = useState(false);
|
2023-03-16 08:37:19 +00:00
|
|
|
const [createViewModal, setCreateViewModal] = useState<any>(null);
|
2023-02-05 11:27:37 +00:00
|
|
|
const [preloadedData, setPreloadedData] = useState<
|
|
|
|
(Partial<IIssue> & { actionType: "createIssue" | "edit" | "delete" }) | undefined
|
|
|
|
>(undefined);
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
// update issue modal
|
2023-02-05 11:27:37 +00:00
|
|
|
const [editIssueModal, setEditIssueModal] = useState(false);
|
|
|
|
const [issueToEdit, setIssueToEdit] = useState<
|
|
|
|
(IIssue & { actionType: "edit" | "delete" }) | undefined
|
|
|
|
>(undefined);
|
|
|
|
|
|
|
|
// delete issue modal
|
|
|
|
const [deleteIssueModal, setDeleteIssueModal] = useState(false);
|
|
|
|
const [issueToDelete, setIssueToDelete] = useState<IIssue | null>(null);
|
|
|
|
|
2023-02-13 05:02:02 +00:00
|
|
|
// trash box
|
|
|
|
const [trashBox, setTrashBox] = useState(false);
|
|
|
|
|
2023-02-05 11:27:37 +00:00
|
|
|
const router = useRouter();
|
2023-03-22 09:17:13 +00:00
|
|
|
const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query;
|
2023-02-05 11:27:37 +00:00
|
|
|
|
2023-03-22 12:48:19 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2023-02-20 13:49:46 +00:00
|
|
|
const {
|
|
|
|
groupedByIssues,
|
2023-03-15 06:14:44 +00:00
|
|
|
issueView,
|
2023-02-20 13:49:46 +00:00
|
|
|
groupByProperty: selectedGroup,
|
|
|
|
orderBy,
|
2023-03-15 06:14:44 +00:00
|
|
|
filters,
|
2023-03-23 18:06:52 +00:00
|
|
|
isNotEmpty,
|
2023-03-15 06:14:44 +00:00
|
|
|
setFilters,
|
2023-03-16 12:45:08 +00:00
|
|
|
params,
|
2023-03-15 06:14:44 +00:00
|
|
|
} = useIssuesView();
|
2023-02-05 11:27:37 +00:00
|
|
|
|
2023-02-08 13:21:03 +00:00
|
|
|
const { data: stateGroups } = useSWR(
|
2023-02-05 11:27:37 +00:00
|
|
|
workspaceSlug && projectId ? STATE_LIST(projectId as string) : null,
|
|
|
|
workspaceSlug
|
|
|
|
? () => stateService.getStates(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
2023-02-08 13:21:03 +00:00
|
|
|
const states = getStatesList(stateGroups ?? {});
|
2023-02-05 11:27:37 +00:00
|
|
|
|
|
|
|
const { data: members } = useSWR(
|
|
|
|
projectId ? PROJECT_MEMBERS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.projectMembers(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-02-13 05:02:02 +00:00
|
|
|
const handleDeleteIssue = useCallback(
|
|
|
|
(issue: IIssue) => {
|
|
|
|
setDeleteIssueModal(true);
|
|
|
|
setIssueToDelete(issue);
|
|
|
|
},
|
|
|
|
[setDeleteIssueModal, setIssueToDelete]
|
|
|
|
);
|
|
|
|
|
2023-02-05 11:27:37 +00:00
|
|
|
const handleOnDragEnd = useCallback(
|
|
|
|
(result: DropResult) => {
|
2023-02-13 05:02:02 +00:00
|
|
|
setTrashBox(false);
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
if (!result.destination || !workspaceSlug || !projectId || !groupedByIssues) return;
|
2023-02-05 11:27:37 +00:00
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
const { source, destination } = result;
|
|
|
|
|
|
|
|
const draggedItem = groupedByIssues[source.droppableId][source.index];
|
|
|
|
|
2023-02-13 05:02:02 +00:00
|
|
|
if (destination.droppableId === "trashBox") {
|
|
|
|
handleDeleteIssue(draggedItem);
|
|
|
|
} else {
|
2023-02-20 13:49:46 +00:00
|
|
|
if (orderBy === "sort_order") {
|
2023-02-21 09:26:32 +00:00
|
|
|
let newSortOrder = draggedItem.sort_order;
|
|
|
|
|
2023-02-20 13:49:46 +00:00
|
|
|
const destinationGroupArray = groupedByIssues[destination.droppableId];
|
|
|
|
|
2023-02-21 05:53:50 +00:00
|
|
|
if (destinationGroupArray.length !== 0) {
|
2023-02-21 13:41:54 +00:00
|
|
|
// check if dropping in the same group
|
|
|
|
if (source.droppableId === destination.droppableId) {
|
|
|
|
// check if dropping at beginning
|
|
|
|
if (destination.index === 0)
|
|
|
|
newSortOrder = destinationGroupArray[0].sort_order - 10000;
|
|
|
|
// check if dropping at last
|
|
|
|
else if (destination.index === destinationGroupArray.length - 1)
|
|
|
|
newSortOrder =
|
|
|
|
destinationGroupArray[destinationGroupArray.length - 1].sort_order + 10000;
|
|
|
|
else {
|
|
|
|
if (destination.index > source.index)
|
|
|
|
newSortOrder =
|
|
|
|
(destinationGroupArray[source.index + 1].sort_order +
|
|
|
|
destinationGroupArray[source.index + 2].sort_order) /
|
|
|
|
2;
|
|
|
|
else if (destination.index < source.index)
|
|
|
|
newSortOrder =
|
|
|
|
(destinationGroupArray[source.index - 1].sort_order +
|
|
|
|
destinationGroupArray[source.index - 2].sort_order) /
|
|
|
|
2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// check if dropping at beginning
|
|
|
|
if (destination.index === 0)
|
|
|
|
newSortOrder = destinationGroupArray[0].sort_order - 10000;
|
|
|
|
// check if dropping at last
|
|
|
|
else if (destination.index === destinationGroupArray.length)
|
|
|
|
newSortOrder =
|
|
|
|
destinationGroupArray[destinationGroupArray.length - 1].sort_order + 10000;
|
|
|
|
else
|
|
|
|
newSortOrder =
|
|
|
|
(destinationGroupArray[destination.index - 1].sort_order +
|
|
|
|
destinationGroupArray[destination.index].sort_order) /
|
|
|
|
2;
|
|
|
|
}
|
2023-02-21 05:53:50 +00:00
|
|
|
}
|
2023-02-21 09:26:32 +00:00
|
|
|
|
|
|
|
draggedItem.sort_order = newSortOrder;
|
2023-02-20 13:49:46 +00:00
|
|
|
}
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
const destinationGroup = destination.droppableId; // destination group id
|
|
|
|
|
2023-02-21 05:53:50 +00:00
|
|
|
if (orderBy === "sort_order" || source.droppableId !== destination.droppableId) {
|
2023-03-15 06:14:44 +00:00
|
|
|
// different group/column;
|
2023-02-13 05:02:02 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
// source.droppableId !== destination.droppableId -> even if order by is not sort_order,
|
|
|
|
// if the issue is moved to a different group, then we will change the group of the
|
|
|
|
// dragged item(or issue)
|
2023-02-13 05:02:02 +00:00
|
|
|
|
2023-02-21 09:26:32 +00:00
|
|
|
if (selectedGroup === "priority") draggedItem.priority = destinationGroup;
|
2023-03-15 06:14:44 +00:00
|
|
|
else if (selectedGroup === "state") draggedItem.state = destinationGroup;
|
|
|
|
}
|
2023-02-21 09:26:32 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
const sourceGroup = source.droppableId; // source group id
|
2023-02-21 09:26:32 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
// TODO: move this mutation logic to a separate function
|
|
|
|
if (cycleId)
|
|
|
|
mutate<{
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
}>(
|
2023-03-16 12:45:08 +00:00
|
|
|
CYCLE_ISSUES_WITH_PARAMS(cycleId as string, params),
|
2023-03-15 06:14:44 +00:00
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
2023-02-21 09:26:32 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
const sourceGroupArray = prevData[sourceGroup];
|
2023-03-23 13:22:18 +00:00
|
|
|
const destinationGroupArray = groupedByIssues[destinationGroup];
|
2023-02-05 11:27:37 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
sourceGroupArray.splice(source.index, 1);
|
|
|
|
destinationGroupArray.splice(destination.index, 0, draggedItem);
|
2023-02-05 11:27:37 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
[sourceGroup]: sourceGroupArray,
|
|
|
|
[destinationGroup]: destinationGroupArray,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
else if (moduleId)
|
|
|
|
mutate<{
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
}>(
|
2023-03-16 12:45:08 +00:00
|
|
|
MODULE_ISSUES_WITH_PARAMS(moduleId as string, params),
|
2023-02-21 09:26:32 +00:00
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
const sourceGroupArray = prevData[sourceGroup];
|
2023-03-23 13:22:18 +00:00
|
|
|
const destinationGroupArray = groupedByIssues[destinationGroup];
|
2023-02-21 09:26:32 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
sourceGroupArray.splice(source.index, 1);
|
|
|
|
destinationGroupArray.splice(destination.index, 0, draggedItem);
|
2023-02-21 09:26:32 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
[sourceGroup]: sourceGroupArray,
|
|
|
|
[destinationGroup]: destinationGroupArray,
|
|
|
|
};
|
2023-02-21 09:26:32 +00:00
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2023-03-15 06:14:44 +00:00
|
|
|
else
|
|
|
|
mutate<{ [key: string]: IIssue[] }>(
|
2023-03-16 12:45:08 +00:00
|
|
|
PROJECT_ISSUES_LIST_WITH_PARAMS(projectId as string, params),
|
2023-03-15 06:14:44 +00:00
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
2023-02-21 09:26:32 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
const sourceGroupArray = prevData[sourceGroup];
|
2023-03-23 13:22:18 +00:00
|
|
|
const destinationGroupArray = groupedByIssues[destinationGroup];
|
2023-03-15 06:14:44 +00:00
|
|
|
|
|
|
|
sourceGroupArray.splice(source.index, 1);
|
|
|
|
destinationGroupArray.splice(destination.index, 0, draggedItem);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
[sourceGroup]: sourceGroupArray,
|
|
|
|
[destinationGroup]: destinationGroupArray,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
// patch request
|
|
|
|
issuesService
|
|
|
|
.patchIssue(workspaceSlug as string, projectId as string, draggedItem.id, {
|
|
|
|
priority: draggedItem.priority,
|
|
|
|
state: draggedItem.state,
|
|
|
|
sort_order: draggedItem.sort_order,
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
if (cycleId) mutate(CYCLE_ISSUES(cycleId as string));
|
|
|
|
if (moduleId) mutate(MODULE_ISSUES(moduleId as string));
|
2023-03-16 12:45:08 +00:00
|
|
|
mutate(PROJECT_ISSUES_LIST_WITH_PARAMS(projectId as string, params));
|
2023-03-15 06:14:44 +00:00
|
|
|
});
|
2023-02-05 11:27:37 +00:00
|
|
|
}
|
|
|
|
},
|
2023-02-13 05:02:02 +00:00
|
|
|
[
|
|
|
|
workspaceSlug,
|
|
|
|
cycleId,
|
|
|
|
moduleId,
|
|
|
|
groupedByIssues,
|
|
|
|
projectId,
|
|
|
|
selectedGroup,
|
2023-02-20 13:49:46 +00:00
|
|
|
orderBy,
|
2023-02-13 05:02:02 +00:00
|
|
|
handleDeleteIssue,
|
2023-03-16 12:45:08 +00:00
|
|
|
params,
|
2023-02-13 05:02:02 +00:00
|
|
|
]
|
2023-02-05 11:27:37 +00:00
|
|
|
);
|
|
|
|
|
2023-02-13 05:02:02 +00:00
|
|
|
const addIssueToState = useCallback(
|
2023-03-15 06:14:44 +00:00
|
|
|
(groupTitle: string) => {
|
2023-02-13 05:02:02 +00:00
|
|
|
setCreateIssueModal(true);
|
|
|
|
if (selectedGroup)
|
|
|
|
setPreloadedData({
|
|
|
|
[selectedGroup]: groupTitle,
|
|
|
|
actionType: "createIssue",
|
|
|
|
});
|
|
|
|
else setPreloadedData({ actionType: "createIssue" });
|
|
|
|
},
|
|
|
|
[setCreateIssueModal, setPreloadedData, selectedGroup]
|
|
|
|
);
|
|
|
|
|
2023-03-04 21:54:24 +00:00
|
|
|
const makeIssueCopy = useCallback(
|
|
|
|
(issue: IIssue) => {
|
|
|
|
setCreateIssueModal(true);
|
|
|
|
|
|
|
|
setPreloadedData({ ...issue, name: `${issue.name} (Copy)`, actionType: "createIssue" });
|
|
|
|
},
|
|
|
|
[setCreateIssueModal, setPreloadedData]
|
|
|
|
);
|
|
|
|
|
2023-02-13 05:02:02 +00:00
|
|
|
const handleEditIssue = useCallback(
|
|
|
|
(issue: IIssue) => {
|
|
|
|
setEditIssueModal(true);
|
|
|
|
setIssueToEdit({
|
|
|
|
...issue,
|
|
|
|
actionType: "edit",
|
|
|
|
cycle: issue.issue_cycle ? issue.issue_cycle.cycle : null,
|
|
|
|
module: issue.issue_module ? issue.issue_module.module : null,
|
2023-02-05 16:31:23 +00:00
|
|
|
});
|
2023-02-13 05:02:02 +00:00
|
|
|
},
|
|
|
|
[setEditIssueModal, setIssueToEdit]
|
|
|
|
);
|
|
|
|
|
|
|
|
const removeIssueFromCycle = useCallback(
|
|
|
|
(bridgeId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
|
|
|
mutate<CycleIssueResponse[]>(
|
|
|
|
CYCLE_ISSUES(cycleId as string),
|
|
|
|
(prevData) => prevData?.filter((p) => p.id !== bridgeId),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
issuesService
|
|
|
|
.removeIssueFromCycle(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
cycleId as string,
|
|
|
|
bridgeId
|
|
|
|
)
|
|
|
|
.then((res) => {
|
|
|
|
console.log(res);
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[workspaceSlug, projectId, cycleId]
|
|
|
|
);
|
|
|
|
|
|
|
|
const removeIssueFromModule = useCallback(
|
|
|
|
(bridgeId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
|
|
|
mutate<ModuleIssueResponse[]>(
|
|
|
|
MODULE_ISSUES(moduleId as string),
|
|
|
|
(prevData) => prevData?.filter((p) => p.id !== bridgeId),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
modulesService
|
|
|
|
.removeIssueFromModule(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
moduleId as string,
|
|
|
|
bridgeId
|
|
|
|
)
|
|
|
|
.then((res) => {
|
|
|
|
console.log(res);
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[workspaceSlug, projectId, moduleId]
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleTrashBox = useCallback(
|
|
|
|
(isDragging: boolean) => {
|
|
|
|
if (isDragging && !trashBox) setTrashBox(true);
|
|
|
|
},
|
|
|
|
[trashBox, setTrashBox]
|
|
|
|
);
|
2023-02-05 16:31:23 +00:00
|
|
|
|
2023-03-22 09:17:13 +00:00
|
|
|
const nullFilters = Object.keys(filters).filter(
|
|
|
|
(key) => filters[key as keyof IIssueFilterOptions] === null
|
|
|
|
);
|
|
|
|
|
2023-02-05 11:27:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-03-16 08:37:19 +00:00
|
|
|
<CreateUpdateViewModal
|
|
|
|
isOpen={createViewModal !== null}
|
|
|
|
handleClose={() => setCreateViewModal(null)}
|
|
|
|
preLoadedData={createViewModal}
|
|
|
|
/>
|
2023-02-05 11:27:37 +00:00
|
|
|
<CreateUpdateIssueModal
|
|
|
|
isOpen={createIssueModal && preloadedData?.actionType === "createIssue"}
|
|
|
|
handleClose={() => setCreateIssueModal(false)}
|
|
|
|
prePopulateData={{
|
|
|
|
...preloadedData,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<CreateUpdateIssueModal
|
|
|
|
isOpen={editIssueModal && issueToEdit?.actionType !== "delete"}
|
|
|
|
prePopulateData={{ ...issueToEdit }}
|
|
|
|
handleClose={() => setEditIssueModal(false)}
|
|
|
|
data={issueToEdit}
|
|
|
|
/>
|
|
|
|
<DeleteIssueModal
|
|
|
|
handleClose={() => setDeleteIssueModal(false)}
|
|
|
|
isOpen={deleteIssueModal}
|
|
|
|
data={issueToDelete}
|
|
|
|
/>
|
2023-03-24 18:01:56 +00:00
|
|
|
<div className="mb-5 -mt-4">
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
<div className="flex flex-wrap items-center gap-3 text-xs">
|
|
|
|
{Object.keys(filters).map((key) => {
|
|
|
|
if (filters[key as keyof typeof filters] !== null)
|
|
|
|
return (
|
|
|
|
<div key={key} className="flex items-center gap-x-2 rounded bg-white px-2 py-1">
|
|
|
|
<span className="font-medium capitalize text-gray-500">{key}:</span>
|
|
|
|
{filters[key as keyof IIssueFilterOptions] === null ||
|
|
|
|
(filters[key as keyof IIssueFilterOptions]?.length ?? 0) <= 0 ? (
|
|
|
|
<span>None</span>
|
|
|
|
) : Array.isArray(filters[key as keyof IIssueFilterOptions]) ? (
|
|
|
|
<div className="space-x-2">
|
|
|
|
{key === "state" ? (
|
|
|
|
<div className="flex items-center gap-x-1">
|
|
|
|
{filters.state?.map((stateId: any) => {
|
|
|
|
const state = states?.find((s) => s.id === stateId);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<p
|
|
|
|
key={state?.id}
|
|
|
|
className="inline-flex items-center gap-x-1 rounded-full px-2 py-0.5 font-medium text-white"
|
|
|
|
style={{
|
|
|
|
color: state?.color,
|
|
|
|
backgroundColor: `${state?.color}20`,
|
|
|
|
}}
|
2023-03-16 08:37:19 +00:00
|
|
|
>
|
2023-03-24 18:01:56 +00:00
|
|
|
<span>
|
|
|
|
{getStateGroupIcon(
|
|
|
|
state?.group ?? "backlog",
|
|
|
|
"12",
|
|
|
|
"12",
|
|
|
|
state?.color
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
<span>{state?.name ?? ""}</span>
|
|
|
|
<span
|
|
|
|
className="cursor-pointer"
|
|
|
|
onClick={() =>
|
|
|
|
setFilters(
|
|
|
|
{
|
|
|
|
state: filters.state?.filter((s: any) => s !== stateId),
|
|
|
|
},
|
|
|
|
!Boolean(viewId)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() =>
|
|
|
|
setFilters({
|
|
|
|
state: null,
|
|
|
|
})
|
|
|
|
}
|
2023-03-22 09:17:13 +00:00
|
|
|
>
|
2023-03-24 18:01:56 +00:00
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
) : key === "priority" ? (
|
|
|
|
<div className="flex items-center gap-x-1">
|
|
|
|
{filters.priority?.map((priority: any) => (
|
2023-03-22 09:17:13 +00:00
|
|
|
<p
|
2023-03-24 18:01:56 +00:00
|
|
|
key={priority}
|
|
|
|
className={`inline-flex items-center gap-x-1 rounded-full px-2 py-0.5 font-medium capitalize text-white ${
|
|
|
|
priority === "urgent"
|
|
|
|
? "bg-red-100 text-red-600 hover:bg-red-100"
|
|
|
|
: priority === "high"
|
|
|
|
? "bg-orange-100 text-orange-500 hover:bg-orange-100"
|
|
|
|
: priority === "medium"
|
|
|
|
? "bg-yellow-100 text-yellow-500 hover:bg-yellow-100"
|
|
|
|
: priority === "low"
|
|
|
|
? "bg-green-100 text-green-500 hover:bg-green-100"
|
|
|
|
: "bg-gray-100"
|
|
|
|
}`}
|
2023-03-22 09:17:13 +00:00
|
|
|
>
|
2023-03-24 18:01:56 +00:00
|
|
|
<span>{getPriorityIcon(priority)}</span>
|
|
|
|
<span>{priority}</span>
|
2023-03-22 09:17:13 +00:00
|
|
|
<span
|
|
|
|
className="cursor-pointer"
|
|
|
|
onClick={() =>
|
2023-03-22 12:48:19 +00:00
|
|
|
setFilters(
|
|
|
|
{
|
2023-03-24 18:01:56 +00:00
|
|
|
priority: filters.priority?.filter(
|
|
|
|
(p: any) => p !== priority
|
2023-03-22 12:48:19 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
!Boolean(viewId)
|
|
|
|
)
|
2023-03-22 09:17:13 +00:00
|
|
|
}
|
2023-03-16 10:57:18 +00:00
|
|
|
>
|
2023-03-22 09:17:13 +00:00
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</span>
|
|
|
|
</p>
|
2023-03-24 18:01:56 +00:00
|
|
|
))}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() =>
|
|
|
|
setFilters({
|
|
|
|
priority: null,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
) : key === "assignees" ? (
|
|
|
|
<div className="flex items-center gap-x-1">
|
|
|
|
{filters.assignees?.map((memberId: string) => {
|
|
|
|
const member = members?.find((m) => m.member.id === memberId)?.member;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<p
|
|
|
|
key={memberId}
|
|
|
|
className="inline-flex items-center gap-x-1 rounded-full border px-2 py-0.5 font-medium capitalize"
|
|
|
|
>
|
|
|
|
<Avatar user={member} />
|
|
|
|
<span>{member?.first_name}</span>
|
|
|
|
<span
|
|
|
|
className="cursor-pointer"
|
|
|
|
onClick={() =>
|
|
|
|
setFilters(
|
|
|
|
{
|
|
|
|
assignees: filters.assignees?.filter(
|
|
|
|
(p: any) => p !== memberId
|
|
|
|
),
|
|
|
|
},
|
|
|
|
!Boolean(viewId)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() =>
|
|
|
|
setFilters({
|
|
|
|
assignees: null,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
) : (key as keyof IIssueFilterOptions) === "created_by" ? (
|
|
|
|
<div className="flex items-center gap-x-1">
|
|
|
|
{filters.created_by?.map((memberId: string) => {
|
|
|
|
const member = members?.find((m) => m.member.id === memberId)?.member;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<p
|
|
|
|
key={memberId}
|
|
|
|
className="inline-flex items-center gap-x-1 rounded-full border px-2 py-0.5 font-medium capitalize"
|
|
|
|
>
|
|
|
|
<Avatar user={member} />
|
|
|
|
<span>{member?.first_name}</span>
|
|
|
|
<span
|
|
|
|
className="cursor-pointer"
|
|
|
|
onClick={() =>
|
|
|
|
setFilters(
|
|
|
|
{
|
|
|
|
assignees: filters.created_by?.filter(
|
|
|
|
(p: any) => p !== memberId
|
|
|
|
),
|
|
|
|
},
|
|
|
|
!Boolean(viewId)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() =>
|
|
|
|
setFilters({
|
|
|
|
created_by: null,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
(filters[key as keyof IIssueFilterOptions] as any)?.join(", ")
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<span className="capitalize">{filters[key as keyof typeof filters]}</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{Object.keys(filters).length > 0 &&
|
|
|
|
nullFilters.length !== Object.keys(filters).length && (
|
|
|
|
<PrimaryButton
|
|
|
|
onClick={() => {
|
|
|
|
if (viewId) {
|
|
|
|
setFilters({}, true);
|
|
|
|
setToastAlert({
|
|
|
|
title: "View updated",
|
|
|
|
message: "Your view has been updated",
|
|
|
|
type: "success",
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
setCreateViewModal({
|
|
|
|
query: filters,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
className="flex items-center gap-2 text-sm"
|
|
|
|
>
|
|
|
|
{!viewId && <PlusIcon className="h-4 w-4" />}
|
|
|
|
{viewId ? "Update" : "Save"} view
|
|
|
|
</PrimaryButton>
|
|
|
|
)}
|
2023-03-16 08:37:19 +00:00
|
|
|
</div>
|
2023-03-24 05:26:06 +00:00
|
|
|
{Object.keys(filters).length > 0 && nullFilters.length !== Object.keys(filters).length && (
|
2023-03-24 18:01:56 +00:00
|
|
|
<button
|
|
|
|
onClick={() =>
|
|
|
|
setFilters({
|
|
|
|
state: null,
|
|
|
|
priority: null,
|
|
|
|
assignees: null,
|
|
|
|
labels: null,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
className="mt-2 flex items-center gap-x-1 text-xs"
|
2023-03-24 05:26:06 +00:00
|
|
|
>
|
2023-03-24 18:01:56 +00:00
|
|
|
<span>Clear all filters</span>
|
|
|
|
<XMarkIcon className="h-4 w-4" />
|
|
|
|
</button>
|
2023-03-24 05:26:06 +00:00
|
|
|
)}
|
2023-02-13 05:02:02 +00:00
|
|
|
</div>
|
2023-03-15 06:14:44 +00:00
|
|
|
<DragDropContext onDragEnd={handleOnDragEnd}>
|
|
|
|
<StrictModeDroppable droppableId="trashBox">
|
|
|
|
{(provided, snapshot) => (
|
|
|
|
<div
|
|
|
|
className={`${
|
|
|
|
trashBox ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0"
|
|
|
|
} fixed top-9 right-9 z-20 flex h-28 w-96 flex-col items-center justify-center gap-2 rounded border-2 border-red-500 bg-red-100 p-3 text-xs font-medium italic text-red-500 ${
|
|
|
|
snapshot.isDraggingOver ? "bg-red-500 text-white" : ""
|
|
|
|
} duration-200`}
|
|
|
|
ref={provided.innerRef}
|
|
|
|
{...provided.droppableProps}
|
|
|
|
>
|
|
|
|
<TrashIcon className="h-4 w-4" />
|
|
|
|
Drop issue here to delete
|
|
|
|
{provided.placeholder}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</StrictModeDroppable>
|
|
|
|
{groupedByIssues ? (
|
2023-03-23 18:06:52 +00:00
|
|
|
isNotEmpty ? (
|
2023-03-15 06:14:44 +00:00
|
|
|
<>
|
2023-03-28 13:18:57 +00:00
|
|
|
{isCompleted && (
|
|
|
|
<div className="flex items-center gap-2 text-sm mb-4 text-gray-500">
|
|
|
|
<ExclamationIcon height={14} width={14} />
|
|
|
|
<span>Completed cycles are not editable.</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-03-15 06:14:44 +00:00
|
|
|
{issueView === "list" ? (
|
|
|
|
<AllLists
|
|
|
|
type={type}
|
|
|
|
states={states}
|
|
|
|
addIssueToState={addIssueToState}
|
|
|
|
makeIssueCopy={makeIssueCopy}
|
|
|
|
handleEditIssue={handleEditIssue}
|
|
|
|
handleDeleteIssue={handleDeleteIssue}
|
|
|
|
openIssuesListModal={type !== "issue" ? openIssuesListModal : null}
|
|
|
|
removeIssue={
|
|
|
|
type === "cycle"
|
|
|
|
? removeIssueFromCycle
|
|
|
|
: type === "module"
|
|
|
|
? removeIssueFromModule
|
|
|
|
: null
|
|
|
|
}
|
2023-03-23 17:12:08 +00:00
|
|
|
isCompleted={isCompleted}
|
2023-03-15 06:14:44 +00:00
|
|
|
userAuth={userAuth}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<AllBoards
|
|
|
|
type={type}
|
|
|
|
states={states}
|
|
|
|
addIssueToState={addIssueToState}
|
|
|
|
makeIssueCopy={makeIssueCopy}
|
|
|
|
handleEditIssue={handleEditIssue}
|
|
|
|
openIssuesListModal={type !== "issue" ? openIssuesListModal : null}
|
|
|
|
handleDeleteIssue={handleDeleteIssue}
|
|
|
|
handleTrashBox={handleTrashBox}
|
|
|
|
removeIssue={
|
|
|
|
type === "cycle"
|
|
|
|
? removeIssueFromCycle
|
|
|
|
: type === "module"
|
|
|
|
? removeIssueFromModule
|
|
|
|
: null
|
|
|
|
}
|
2023-03-23 17:12:08 +00:00
|
|
|
isCompleted={isCompleted}
|
2023-03-15 06:14:44 +00:00
|
|
|
userAuth={userAuth}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<div className="grid h-full w-full place-items-center px-4 sm:px-0">
|
|
|
|
<EmptySpace
|
|
|
|
title="You don't have any issue yet."
|
|
|
|
description="Issues help you track individual pieces of work. With Issues, keep track of what's going on, who is working on it, and what's done."
|
|
|
|
Icon={RectangleStackIcon}
|
|
|
|
>
|
|
|
|
<EmptySpaceItem
|
|
|
|
title="Create a new issue"
|
|
|
|
description={
|
|
|
|
<span>
|
|
|
|
Use <pre className="inline rounded bg-gray-200 px-2 py-1">C</pre> shortcut to
|
|
|
|
create a new issue
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
Icon={PlusIcon}
|
|
|
|
action={() => {
|
|
|
|
const e = new KeyboardEvent("keydown", {
|
|
|
|
key: "c",
|
|
|
|
});
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
}}
|
|
|
|
/>
|
2023-03-22 11:28:32 +00:00
|
|
|
{openIssuesListModal && (
|
|
|
|
<EmptySpaceItem
|
|
|
|
title="Add an existing issue"
|
|
|
|
description="Open list"
|
|
|
|
Icon={ListBulletIcon}
|
|
|
|
action={openIssuesListModal}
|
|
|
|
/>
|
|
|
|
)}
|
2023-03-15 06:14:44 +00:00
|
|
|
</EmptySpace>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
) : (
|
2023-03-22 13:36:36 +00:00
|
|
|
<div className="flex h-full w-full items-center justify-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
2023-03-15 06:14:44 +00:00
|
|
|
)}
|
|
|
|
</DragDropContext>
|
2023-02-05 11:27:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|