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-07-26 12:21:26 +00:00
|
|
|
import { 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";
|
2023-02-05 16:31:23 +00:00
|
|
|
import modulesService from "services/modules.service";
|
2023-04-06 06:38:52 +00:00
|
|
|
import trackEventServices from "services/track-event.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-06-06 16:06:00 +00:00
|
|
|
import useUserAuth from "hooks/use-user-auth";
|
2023-07-26 12:21:26 +00:00
|
|
|
import useIssuesProperties from "hooks/use-issue-properties";
|
|
|
|
import useProjectMembers from "hooks/use-project-members";
|
2023-02-05 11:27:37 +00:00
|
|
|
// components
|
2023-07-26 12:21:26 +00:00
|
|
|
import { FiltersList, AllViews } from "components/core";
|
2023-02-05 11:27:37 +00:00
|
|
|
import { CreateUpdateIssueModal, DeleteIssueModal } from "components/issues";
|
2023-03-16 08:37:19 +00:00
|
|
|
import { CreateUpdateViewModal } from "components/views";
|
2023-03-17 05:10:38 +00:00
|
|
|
// ui
|
2023-08-01 08:28:58 +00:00
|
|
|
import { PrimaryButton, SecondaryButton } from "components/ui";
|
2023-02-13 05:02:02 +00:00
|
|
|
// icons
|
2023-07-26 12:21:26 +00:00
|
|
|
import { PlusIcon } from "@heroicons/react/24/outline";
|
2023-02-08 13:21:03 +00:00
|
|
|
// helpers
|
|
|
|
import { getStatesList } from "helpers/state.helper";
|
2023-04-14 11:11:28 +00:00
|
|
|
import { orderArrayBy } from "helpers/array.helper";
|
2023-02-05 11:27:37 +00:00
|
|
|
// types
|
2023-07-26 17:50:44 +00:00
|
|
|
import { IIssue, IIssueFilterOptions, IState } from "types";
|
2023-02-05 11:27:37 +00:00
|
|
|
// fetch-keys
|
|
|
|
import {
|
2023-03-31 12:59:24 +00:00
|
|
|
CYCLE_DETAILS,
|
2023-03-15 06:14:44 +00:00
|
|
|
CYCLE_ISSUES_WITH_PARAMS,
|
2023-03-31 12:59:24 +00:00
|
|
|
MODULE_DETAILS,
|
2023-03-15 06:14:44 +00:00
|
|
|
MODULE_ISSUES_WITH_PARAMS,
|
|
|
|
PROJECT_ISSUES_LIST_WITH_PARAMS,
|
2023-07-26 12:21:26 +00:00
|
|
|
PROJECT_ISSUE_LABELS,
|
2023-04-22 12:49:35 +00:00
|
|
|
STATES_LIST,
|
2023-02-05 11:27:37 +00:00
|
|
|
} from "constants/fetch-keys";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
openIssuesListModal?: () => void;
|
2023-07-26 12:21:26 +00:00
|
|
|
disableUserActions?: boolean;
|
2023-02-05 11:27:37 +00:00
|
|
|
};
|
|
|
|
|
2023-03-23 17:12:08 +00:00
|
|
|
export const IssuesView: React.FC<Props> = ({
|
|
|
|
openIssuesListModal,
|
2023-07-26 12:21:26 +00:00
|
|
|
disableUserActions = false,
|
2023-03-23 17:12:08 +00:00
|
|
|
}) => {
|
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-06-06 16:06:00 +00:00
|
|
|
const { user } = useUserAuth();
|
|
|
|
|
2023-03-22 12:48:19 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2023-02-20 13:49:46 +00:00
|
|
|
const {
|
|
|
|
groupedByIssues,
|
2023-07-28 08:09:42 +00:00
|
|
|
mutateIssues,
|
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-07-12 06:15:45 +00:00
|
|
|
isEmpty,
|
2023-03-15 06:14:44 +00:00
|
|
|
setFilters,
|
2023-03-16 12:45:08 +00:00
|
|
|
params,
|
2023-07-26 12:21:26 +00:00
|
|
|
showEmptyGroups,
|
2023-03-15 06:14:44 +00:00
|
|
|
} = useIssuesView();
|
2023-07-26 12:21:26 +00:00
|
|
|
const [properties] = useIssuesProperties(workspaceSlug as string, projectId as string);
|
2023-02-05 11:27:37 +00:00
|
|
|
|
2023-02-08 13:21:03 +00:00
|
|
|
const { data: stateGroups } = useSWR(
|
2023-04-22 12:49:35 +00:00
|
|
|
workspaceSlug && projectId ? STATES_LIST(projectId as string) : null,
|
2023-02-05 11:27:37 +00:00
|
|
|
workspaceSlug
|
|
|
|
? () => stateService.getStates(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
2023-07-26 17:50:44 +00:00
|
|
|
const states = getStatesList(stateGroups);
|
2023-02-05 11:27:37 +00:00
|
|
|
|
2023-07-26 12:21:26 +00:00
|
|
|
const { data: labels } = useSWR(
|
|
|
|
workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId.toString()) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => issuesService.getIssueLabels(workspaceSlug.toString(), projectId.toString())
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const { members } = useProjectMembers(workspaceSlug?.toString(), projectId?.toString());
|
|
|
|
|
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(
|
2023-07-26 12:21:26 +00:00
|
|
|
async (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-07-26 17:50:44 +00:00
|
|
|
else if (selectedGroup === "state") {
|
|
|
|
draggedItem.state = destinationGroup;
|
|
|
|
draggedItem.state_detail = states?.find((s) => s.id === destinationGroup) as IState;
|
|
|
|
}
|
2023-03-15 06:14:44 +00:00
|
|
|
}
|
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-04-14 11:11:28 +00:00
|
|
|
mutate<{
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
}>(
|
|
|
|
cycleId
|
|
|
|
? CYCLE_ISSUES_WITH_PARAMS(cycleId as string, params)
|
|
|
|
: moduleId
|
|
|
|
? MODULE_ISSUES_WITH_PARAMS(moduleId as string, params)
|
|
|
|
: PROJECT_ISSUES_LIST_WITH_PARAMS(projectId as string, params),
|
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
2023-07-26 17:50:44 +00:00
|
|
|
const sourceGroupArray = [...groupedByIssues[sourceGroup]];
|
|
|
|
const destinationGroupArray = [...groupedByIssues[destinationGroup]];
|
2023-04-14 11:11:28 +00:00
|
|
|
|
|
|
|
sourceGroupArray.splice(source.index, 1);
|
|
|
|
destinationGroupArray.splice(destination.index, 0, draggedItem);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
[sourceGroup]: orderArrayBy(sourceGroupArray, orderBy),
|
|
|
|
[destinationGroup]: orderArrayBy(destinationGroupArray, orderBy),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2023-03-15 06:14:44 +00:00
|
|
|
|
|
|
|
// patch request
|
|
|
|
issuesService
|
2023-06-06 16:06:00 +00:00
|
|
|
.patchIssue(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
draggedItem.id,
|
|
|
|
{
|
|
|
|
priority: draggedItem.priority,
|
|
|
|
state: draggedItem.state,
|
|
|
|
sort_order: draggedItem.sort_order,
|
|
|
|
},
|
|
|
|
user
|
|
|
|
)
|
2023-04-06 06:38:52 +00:00
|
|
|
.then((response) => {
|
2023-07-26 17:50:44 +00:00
|
|
|
const sourceStateBeforeDrag = states?.find(
|
|
|
|
(state) => state.name === source.droppableId
|
|
|
|
);
|
2023-04-06 06:38:52 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
sourceStateBeforeDrag?.group !== "completed" &&
|
|
|
|
response?.state_detail?.group === "completed"
|
|
|
|
)
|
2023-06-06 16:06:00 +00:00
|
|
|
trackEventServices.trackIssueMarkedAsDoneEvent(
|
|
|
|
{
|
|
|
|
workspaceSlug,
|
|
|
|
workspaceId: draggedItem.workspace,
|
|
|
|
projectName: draggedItem.project_detail.name,
|
|
|
|
projectIdentifier: draggedItem.project_detail.identifier,
|
|
|
|
projectId,
|
|
|
|
issueId: draggedItem.id,
|
|
|
|
},
|
|
|
|
user
|
|
|
|
);
|
2023-04-06 06:38:52 +00:00
|
|
|
|
2023-03-31 12:59:24 +00:00
|
|
|
if (cycleId) {
|
|
|
|
mutate(CYCLE_ISSUES_WITH_PARAMS(cycleId as string, params));
|
|
|
|
mutate(CYCLE_DETAILS(cycleId as string));
|
|
|
|
}
|
|
|
|
if (moduleId) {
|
|
|
|
mutate(MODULE_ISSUES_WITH_PARAMS(moduleId as string, params));
|
|
|
|
mutate(MODULE_DETAILS(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-04-06 06:38:52 +00:00
|
|
|
states,
|
2023-06-16 13:27:17 +00:00
|
|
|
user,
|
2023-02-13 05:02:02 +00:00
|
|
|
]
|
2023-02-05 11:27:37 +00:00
|
|
|
);
|
|
|
|
|
2023-07-26 12:21:26 +00:00
|
|
|
const addIssueToGroup = useCallback(
|
2023-03-15 06:14:44 +00:00
|
|
|
(groupTitle: string) => {
|
2023-02-13 05:02:02 +00:00
|
|
|
setCreateIssueModal(true);
|
2023-06-23 05:38:53 +00:00
|
|
|
|
|
|
|
let preloadedValue: string | string[] = groupTitle;
|
|
|
|
|
|
|
|
if (selectedGroup === "labels") {
|
|
|
|
if (groupTitle === "None") preloadedValue = [];
|
|
|
|
else preloadedValue = [groupTitle];
|
|
|
|
}
|
|
|
|
|
2023-02-13 05:02:02 +00:00
|
|
|
if (selectedGroup)
|
|
|
|
setPreloadedData({
|
2023-06-23 05:38:53 +00:00
|
|
|
[selectedGroup]: preloadedValue,
|
2023-02-13 05:02:02 +00:00
|
|
|
actionType: "createIssue",
|
|
|
|
});
|
|
|
|
else setPreloadedData({ actionType: "createIssue" });
|
|
|
|
},
|
|
|
|
[setCreateIssueModal, setPreloadedData, selectedGroup]
|
|
|
|
);
|
|
|
|
|
2023-04-20 08:41:11 +00:00
|
|
|
const addIssueToDate = useCallback(
|
|
|
|
(date: string) => {
|
|
|
|
setCreateIssueModal(true);
|
|
|
|
setPreloadedData({
|
|
|
|
target_date: date,
|
|
|
|
actionType: "createIssue",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[setCreateIssueModal, setPreloadedData]
|
|
|
|
);
|
|
|
|
|
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]
|
|
|
|
);
|
|
|
|
|
2023-07-26 12:21:26 +00:00
|
|
|
const handleIssueAction = useCallback(
|
|
|
|
(issue: IIssue, action: "copy" | "edit" | "delete") => {
|
|
|
|
if (action === "copy") makeIssueCopy(issue);
|
|
|
|
else if (action === "edit") handleEditIssue(issue);
|
|
|
|
else if (action === "delete") handleDeleteIssue(issue);
|
|
|
|
},
|
|
|
|
[makeIssueCopy, handleEditIssue, handleDeleteIssue]
|
|
|
|
);
|
|
|
|
|
2023-02-13 05:02:02 +00:00
|
|
|
const removeIssueFromCycle = useCallback(
|
2023-04-28 12:19:16 +00:00
|
|
|
(bridgeId: string, issueId: string) => {
|
2023-03-31 12:59:24 +00:00
|
|
|
if (!workspaceSlug || !projectId || !cycleId) return;
|
2023-02-13 05:02:02 +00:00
|
|
|
|
2023-04-28 12:19:16 +00:00
|
|
|
mutate(
|
|
|
|
CYCLE_ISSUES_WITH_PARAMS(cycleId as string, params),
|
|
|
|
(prevData: any) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
if (selectedGroup) {
|
|
|
|
const filteredData: any = {};
|
|
|
|
for (const key in prevData) {
|
|
|
|
filteredData[key] = prevData[key].filter((item: any) => item.id !== issueId);
|
|
|
|
}
|
|
|
|
return filteredData;
|
|
|
|
} else {
|
|
|
|
const filteredData = prevData.filter((i: any) => i.id !== issueId);
|
|
|
|
return filteredData;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2023-02-13 05:02:02 +00:00
|
|
|
|
|
|
|
issuesService
|
|
|
|
.removeIssueFromCycle(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
cycleId as string,
|
|
|
|
bridgeId
|
|
|
|
)
|
2023-04-28 12:19:16 +00:00
|
|
|
.then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Success",
|
|
|
|
message: "Issue removed successfully.",
|
|
|
|
type: "success",
|
|
|
|
});
|
|
|
|
})
|
2023-02-13 05:02:02 +00:00
|
|
|
.catch((e) => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
},
|
2023-05-05 11:37:29 +00:00
|
|
|
[workspaceSlug, projectId, cycleId, params, selectedGroup, setToastAlert]
|
2023-02-13 05:02:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const removeIssueFromModule = useCallback(
|
2023-04-28 12:19:16 +00:00
|
|
|
(bridgeId: string, issueId: string) => {
|
2023-03-31 12:59:24 +00:00
|
|
|
if (!workspaceSlug || !projectId || !moduleId) return;
|
2023-02-13 05:02:02 +00:00
|
|
|
|
2023-04-28 12:19:16 +00:00
|
|
|
mutate(
|
|
|
|
MODULE_ISSUES_WITH_PARAMS(moduleId as string, params),
|
|
|
|
(prevData: any) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
if (selectedGroup) {
|
|
|
|
const filteredData: any = {};
|
|
|
|
for (const key in prevData) {
|
|
|
|
filteredData[key] = prevData[key].filter((item: any) => item.id !== issueId);
|
|
|
|
}
|
|
|
|
return filteredData;
|
|
|
|
} else {
|
|
|
|
const filteredData = prevData.filter((item: any) => item.id !== issueId);
|
|
|
|
return filteredData;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2023-02-13 05:02:02 +00:00
|
|
|
|
|
|
|
modulesService
|
|
|
|
.removeIssueFromModule(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
moduleId as string,
|
|
|
|
bridgeId
|
|
|
|
)
|
2023-04-28 12:19:16 +00:00
|
|
|
.then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Success",
|
|
|
|
message: "Issue removed successfully.",
|
|
|
|
type: "success",
|
|
|
|
});
|
|
|
|
})
|
2023-02-13 05:02:02 +00:00
|
|
|
.catch((e) => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
},
|
2023-05-05 11:37:29 +00:00
|
|
|
[workspaceSlug, projectId, moduleId, params, selectedGroup, setToastAlert]
|
2023-02-13 05:02:02 +00:00
|
|
|
);
|
|
|
|
|
2023-03-22 09:17:13 +00:00
|
|
|
const nullFilters = Object.keys(filters).filter(
|
|
|
|
(key) => filters[key as keyof IIssueFilterOptions] === null
|
|
|
|
);
|
|
|
|
|
2023-04-17 12:12:02 +00:00
|
|
|
const areFiltersApplied =
|
|
|
|
Object.keys(filters).length > 0 && nullFilters.length !== Object.keys(filters).length;
|
|
|
|
|
2023-02-05 11:27:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-03-16 08:37:19 +00:00
|
|
|
<CreateUpdateViewModal
|
|
|
|
isOpen={createViewModal !== null}
|
|
|
|
handleClose={() => setCreateViewModal(null)}
|
2023-04-17 06:54:30 +00:00
|
|
|
preLoadedData={createViewModal}
|
2023-06-06 16:06:00 +00:00
|
|
|
user={user}
|
2023-03-16 08:37:19 +00:00
|
|
|
/>
|
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"}
|
|
|
|
handleClose={() => setEditIssueModal(false)}
|
|
|
|
data={issueToEdit}
|
|
|
|
/>
|
|
|
|
<DeleteIssueModal
|
|
|
|
handleClose={() => setDeleteIssueModal(false)}
|
|
|
|
isOpen={deleteIssueModal}
|
|
|
|
data={issueToDelete}
|
2023-06-06 16:06:00 +00:00
|
|
|
user={user}
|
2023-02-05 11:27:37 +00:00
|
|
|
/>
|
2023-05-05 11:37:29 +00:00
|
|
|
{areFiltersApplied && (
|
|
|
|
<>
|
|
|
|
<div className="flex items-center justify-between gap-2 px-5 pt-3 pb-0">
|
2023-07-26 12:21:26 +00:00
|
|
|
<FiltersList
|
|
|
|
filters={filters}
|
2023-07-26 19:27:12 +00:00
|
|
|
setFilters={(updatedFilter) => setFilters(updatedFilter, !Boolean(viewId))}
|
2023-07-26 12:21:26 +00:00
|
|
|
labels={labels}
|
|
|
|
members={members?.map((m) => m.member)}
|
|
|
|
states={states}
|
|
|
|
clearAllFilters={() =>
|
|
|
|
setFilters({
|
|
|
|
assignees: null,
|
|
|
|
created_by: null,
|
|
|
|
labels: null,
|
|
|
|
priority: null,
|
|
|
|
state: null,
|
2023-08-24 14:15:23 +00:00
|
|
|
start_date: null,
|
2023-07-26 12:21:26 +00:00
|
|
|
target_date: null,
|
|
|
|
type: null,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
2023-05-17 07:55:58 +00:00
|
|
|
<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-05-05 11:37:29 +00:00
|
|
|
</div>
|
2023-07-17 10:58:23 +00:00
|
|
|
{<div className="mt-3 border-t border-custom-border-200" />}
|
2023-05-05 11:37:29 +00:00
|
|
|
</>
|
|
|
|
)}
|
2023-07-26 12:21:26 +00:00
|
|
|
<AllViews
|
|
|
|
addIssueToDate={addIssueToDate}
|
|
|
|
addIssueToGroup={addIssueToGroup}
|
|
|
|
disableUserActions={disableUserActions}
|
|
|
|
dragDisabled={
|
|
|
|
selectedGroup === "created_by" ||
|
|
|
|
selectedGroup === "labels" ||
|
2023-08-24 14:16:12 +00:00
|
|
|
selectedGroup === "state_detail.group" ||
|
|
|
|
selectedGroup === "assignees"
|
2023-07-26 12:21:26 +00:00
|
|
|
}
|
2023-08-01 08:28:58 +00:00
|
|
|
emptyState={{
|
|
|
|
title: cycleId
|
|
|
|
? "Cycle issues will appear here"
|
|
|
|
: moduleId
|
|
|
|
? "Module issues will appear here"
|
|
|
|
: "Project issues will appear here",
|
|
|
|
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.",
|
|
|
|
primaryButton: {
|
|
|
|
icon: <PlusIcon className="h-4 w-4" />,
|
|
|
|
text: "New Issue",
|
|
|
|
onClick: () => {
|
|
|
|
const e = new KeyboardEvent("keydown", {
|
|
|
|
key: "c",
|
|
|
|
});
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
secondaryButton:
|
|
|
|
cycleId || moduleId ? (
|
|
|
|
<SecondaryButton
|
|
|
|
className="flex items-center gap-1.5"
|
|
|
|
onClick={openIssuesListModal ?? (() => {})}
|
|
|
|
>
|
|
|
|
<PlusIcon className="h-4 w-4" />
|
|
|
|
Add an existing issue
|
|
|
|
</SecondaryButton>
|
|
|
|
) : null,
|
|
|
|
}}
|
2023-07-26 12:21:26 +00:00
|
|
|
handleOnDragEnd={handleOnDragEnd}
|
|
|
|
handleIssueAction={handleIssueAction}
|
2023-08-25 12:11:23 +00:00
|
|
|
openIssuesListModal={openIssuesListModal ?? null}
|
2023-07-26 12:21:26 +00:00
|
|
|
removeIssue={cycleId ? removeIssueFromCycle : moduleId ? removeIssueFromModule : null}
|
|
|
|
trashBox={trashBox}
|
|
|
|
setTrashBox={setTrashBox}
|
|
|
|
viewProps={{
|
|
|
|
groupByProperty: selectedGroup,
|
|
|
|
groupedIssues: groupedByIssues,
|
|
|
|
isEmpty,
|
|
|
|
issueView,
|
2023-07-28 08:09:42 +00:00
|
|
|
mutateIssues,
|
2023-07-26 12:21:26 +00:00
|
|
|
orderBy,
|
|
|
|
params,
|
|
|
|
properties,
|
|
|
|
showEmptyGroups,
|
|
|
|
}}
|
|
|
|
/>
|
2023-02-05 11:27:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|