2023-05-20 12:00:15 +00:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import modulesService from "services/modules.service";
|
2023-08-11 10:29:13 +00:00
|
|
|
// hooks
|
|
|
|
import useIssuesView from "hooks/use-issues-view";
|
2023-05-20 12:00:15 +00:00
|
|
|
// fetch-keys
|
|
|
|
import { MODULE_ISSUES_WITH_PARAMS } from "constants/fetch-keys";
|
|
|
|
|
|
|
|
const useGanttChartModuleIssues = (
|
|
|
|
workspaceSlug: string | undefined,
|
|
|
|
projectId: string | undefined,
|
|
|
|
moduleId: string | undefined
|
|
|
|
) => {
|
2023-08-11 10:29:13 +00:00
|
|
|
const { orderBy, filters, showSubIssues } = useIssuesView();
|
|
|
|
|
|
|
|
const params: any = {
|
|
|
|
order_by: orderBy,
|
|
|
|
type: filters?.type ? filters?.type : undefined,
|
|
|
|
sub_issue: showSubIssues,
|
2023-08-28 07:55:47 +00:00
|
|
|
assignees: filters?.assignees ? filters?.assignees.join(",") : undefined,
|
|
|
|
state: filters?.state ? filters?.state.join(",") : undefined,
|
|
|
|
priority: filters?.priority ? filters?.priority.join(",") : undefined,
|
|
|
|
labels: filters?.labels ? filters?.labels.join(",") : undefined,
|
|
|
|
created_by: filters?.created_by ? filters?.created_by.join(",") : undefined,
|
2023-08-29 14:41:38 +00:00
|
|
|
start_date: filters?.start_date ? filters?.start_date.join(",") : undefined,
|
2023-08-28 07:55:47 +00:00
|
|
|
target_date: filters?.target_date ? filters?.target_date.join(",") : undefined,
|
|
|
|
start_target_date: true, // to fetch only issues with a start and target date
|
2023-08-11 10:29:13 +00:00
|
|
|
};
|
|
|
|
|
2023-05-20 12:00:15 +00:00
|
|
|
// all issues under the workspace and project
|
|
|
|
const { data: ganttIssues, mutate: mutateGanttIssues } = useSWR(
|
2023-08-11 10:29:13 +00:00
|
|
|
workspaceSlug && projectId && moduleId
|
|
|
|
? MODULE_ISSUES_WITH_PARAMS(moduleId.toString(), params)
|
|
|
|
: null,
|
2023-05-20 12:00:15 +00:00
|
|
|
workspaceSlug && projectId && moduleId
|
|
|
|
? () =>
|
|
|
|
modulesService.getModuleIssuesWithParams(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
2023-08-11 10:29:13 +00:00
|
|
|
moduleId.toString(),
|
|
|
|
params
|
2023-05-20 12:00:15 +00:00
|
|
|
)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
ganttIssues,
|
|
|
|
mutateGanttIssues,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default useGanttChartModuleIssues;
|