mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: fetch correct list of issues on the calendar view (#611)
This commit is contained in:
parent
be5c4140ff
commit
5feaed3961
@ -24,7 +24,7 @@ import {
|
|||||||
} from "helpers/calendar.helper";
|
} from "helpers/calendar.helper";
|
||||||
// ui
|
// ui
|
||||||
import { Popover, Transition } from "@headlessui/react";
|
import { Popover, Transition } from "@headlessui/react";
|
||||||
import { DragDropContext, Draggable, Droppable, DropResult } from "react-beautiful-dnd";
|
import { DragDropContext, Draggable, DropResult } from "react-beautiful-dnd";
|
||||||
import StrictModeDroppable from "components/dnd/StrictModeDroppable";
|
import StrictModeDroppable from "components/dnd/StrictModeDroppable";
|
||||||
import { CustomMenu } from "components/ui";
|
import { CustomMenu } from "components/ui";
|
||||||
// icon
|
// icon
|
||||||
@ -36,12 +36,18 @@ import {
|
|||||||
} from "@heroicons/react/24/outline";
|
} from "@heroicons/react/24/outline";
|
||||||
// services
|
// services
|
||||||
import issuesService from "services/issues.service";
|
import issuesService from "services/issues.service";
|
||||||
|
import cyclesService from "services/cycles.service";
|
||||||
// fetch key
|
// fetch key
|
||||||
import { CALENDAR_ISSUES, ISSUE_DETAILS } from "constants/fetch-keys";
|
import {
|
||||||
|
CYCLE_CALENDAR_ISSUES,
|
||||||
|
MODULE_CALENDAR_ISSUES,
|
||||||
|
PROJECT_CALENDAR_ISSUES,
|
||||||
|
} from "constants/fetch-keys";
|
||||||
// type
|
// type
|
||||||
import { IIssue } from "types";
|
import { IIssue } from "types";
|
||||||
// constant
|
// constant
|
||||||
import { monthOptions, yearOptions } from "constants/calendar";
|
import { monthOptions, yearOptions } from "constants/calendar";
|
||||||
|
import modulesService from "services/modules.service";
|
||||||
|
|
||||||
interface ICalendarRange {
|
interface ICalendarRange {
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
@ -54,15 +60,15 @@ export const CalendarView = () => {
|
|||||||
const [isMonthlyView, setIsMonthlyView] = useState<boolean>(true);
|
const [isMonthlyView, setIsMonthlyView] = useState<boolean>(true);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId } = router.query;
|
const { workspaceSlug, projectId, cycleId, moduleId } = router.query;
|
||||||
|
|
||||||
const [calendarDateRange, setCalendarDateRange] = useState<ICalendarRange>({
|
const [calendarDateRange, setCalendarDateRange] = useState<ICalendarRange>({
|
||||||
startDate: startOfWeek(currentDate),
|
startDate: startOfWeek(currentDate),
|
||||||
endDate: lastDayOfWeek(currentDate),
|
endDate: lastDayOfWeek(currentDate),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: calendarIssues } = useSWR(
|
const { data: projectCalendarIssues } = useSWR(
|
||||||
workspaceSlug && projectId ? CALENDAR_ISSUES(projectId as string) : null,
|
workspaceSlug && projectId ? PROJECT_CALENDAR_ISSUES(projectId as string) : null,
|
||||||
workspaceSlug && projectId
|
workspaceSlug && projectId
|
||||||
? () =>
|
? () =>
|
||||||
issuesService.getIssuesWithParams(workspaceSlug as string, projectId as string, {
|
issuesService.getIssuesWithParams(workspaceSlug as string, projectId as string, {
|
||||||
@ -73,6 +79,44 @@ export const CalendarView = () => {
|
|||||||
: null
|
: null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { data: cycleCalendarIssues } = useSWR(
|
||||||
|
workspaceSlug && projectId && cycleId
|
||||||
|
? CYCLE_CALENDAR_ISSUES(projectId as string, cycleId as string)
|
||||||
|
: null,
|
||||||
|
workspaceSlug && projectId && cycleId
|
||||||
|
? () =>
|
||||||
|
cyclesService.getCycleIssuesWithParams(
|
||||||
|
workspaceSlug as string,
|
||||||
|
projectId as string,
|
||||||
|
cycleId as string,
|
||||||
|
{
|
||||||
|
target_date: `${renderDateFormat(
|
||||||
|
calendarDateRange.startDate
|
||||||
|
)};after,${renderDateFormat(calendarDateRange.endDate)};before`,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
|
||||||
|
const { data: moduleCalendarIssues } = useSWR(
|
||||||
|
workspaceSlug && projectId && moduleId
|
||||||
|
? MODULE_CALENDAR_ISSUES(projectId as string, moduleId as string)
|
||||||
|
: null,
|
||||||
|
workspaceSlug && projectId && moduleId
|
||||||
|
? () =>
|
||||||
|
modulesService.getModuleIssuesWithParams(
|
||||||
|
workspaceSlug as string,
|
||||||
|
projectId as string,
|
||||||
|
moduleId as string,
|
||||||
|
{
|
||||||
|
target_date: `${renderDateFormat(
|
||||||
|
calendarDateRange.startDate
|
||||||
|
)};after,${renderDateFormat(calendarDateRange.endDate)};before`,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
|
||||||
const totalDate = eachDayOfInterval({
|
const totalDate = eachDayOfInterval({
|
||||||
start: calendarDateRange.startDate,
|
start: calendarDateRange.startDate,
|
||||||
end: calendarDateRange.endDate,
|
end: calendarDateRange.endDate,
|
||||||
@ -85,6 +129,8 @@ export const CalendarView = () => {
|
|||||||
|
|
||||||
const currentViewDays = showWeekEnds ? totalDate : onlyWeekDays;
|
const currentViewDays = showWeekEnds ? totalDate : onlyWeekDays;
|
||||||
|
|
||||||
|
const calendarIssues = cycleCalendarIssues ?? moduleCalendarIssues ?? projectCalendarIssues;
|
||||||
|
|
||||||
const currentViewDaysData = currentViewDays.map((date: Date) => {
|
const currentViewDaysData = currentViewDays.map((date: Date) => {
|
||||||
const filterIssue =
|
const filterIssue =
|
||||||
calendarIssues && calendarIssues.length > 0
|
calendarIssues && calendarIssues.length > 0
|
||||||
@ -120,8 +166,37 @@ export const CalendarView = () => {
|
|||||||
if (!destination || !workspaceSlug || !projectId) return;
|
if (!destination || !workspaceSlug || !projectId) return;
|
||||||
if (source.droppableId === destination.droppableId) return;
|
if (source.droppableId === destination.droppableId) return;
|
||||||
|
|
||||||
|
if (cycleId)
|
||||||
mutate<IIssue[]>(
|
mutate<IIssue[]>(
|
||||||
CALENDAR_ISSUES(projectId as string),
|
CYCLE_CALENDAR_ISSUES(projectId as string, cycleId as string),
|
||||||
|
(prevData) =>
|
||||||
|
(prevData ?? []).map((p) => {
|
||||||
|
if (p.id === draggableId)
|
||||||
|
return {
|
||||||
|
...p,
|
||||||
|
target_date: destination.droppableId,
|
||||||
|
};
|
||||||
|
return p;
|
||||||
|
}),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
else if (moduleId)
|
||||||
|
mutate<IIssue[]>(
|
||||||
|
MODULE_CALENDAR_ISSUES(projectId as string, moduleId as string),
|
||||||
|
(prevData) =>
|
||||||
|
(prevData ?? []).map((p) => {
|
||||||
|
if (p.id === draggableId)
|
||||||
|
return {
|
||||||
|
...p,
|
||||||
|
target_date: destination.droppableId,
|
||||||
|
};
|
||||||
|
return p;
|
||||||
|
}),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
else
|
||||||
|
mutate<IIssue[]>(
|
||||||
|
PROJECT_CALENDAR_ISSUES(projectId as string),
|
||||||
(prevData) =>
|
(prevData) =>
|
||||||
(prevData ?? []).map((p) => {
|
(prevData ?? []).map((p) => {
|
||||||
if (p.id === draggableId)
|
if (p.id === draggableId)
|
||||||
@ -248,9 +323,9 @@ export const CalendarView = () => {
|
|||||||
<button
|
<button
|
||||||
className="group flex cursor-pointer items-center gap-2 rounded-md border bg-white px-4 py-1.5 text-sm hover:bg-gray-100 hover:text-gray-900 focus:outline-none"
|
className="group flex cursor-pointer items-center gap-2 rounded-md border bg-white px-4 py-1.5 text-sm hover:bg-gray-100 hover:text-gray-900 focus:outline-none"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if(isMonthlyView){
|
if (isMonthlyView) {
|
||||||
updateDate(new Date())
|
updateDate(new Date());
|
||||||
}else{
|
} else {
|
||||||
setCurrentDate(new Date());
|
setCurrentDate(new Date());
|
||||||
setCalendarDateRange({
|
setCalendarDateRange({
|
||||||
startDate: getCurrentWeekStartDate(new Date()),
|
startDate: getCurrentWeekStartDate(new Date()),
|
||||||
|
@ -72,7 +72,8 @@ export const PROJECT_GITHUB_REPOSITORY = (projectId: string) =>
|
|||||||
`PROJECT_GITHUB_REPOSITORY_${projectId.toUpperCase()}`;
|
`PROJECT_GITHUB_REPOSITORY_${projectId.toUpperCase()}`;
|
||||||
|
|
||||||
export const CYCLE_LIST = (projectId: string) => `CYCLE_LIST_${projectId.toUpperCase()}`;
|
export const CYCLE_LIST = (projectId: string) => `CYCLE_LIST_${projectId.toUpperCase()}`;
|
||||||
export const CYCLE_INCOMPLETE_LIST = (projectId: string) => `CYCLE_INCOMPLETE_LIST_${projectId.toUpperCase()}`;
|
export const CYCLE_INCOMPLETE_LIST = (projectId: string) =>
|
||||||
|
`CYCLE_INCOMPLETE_LIST_${projectId.toUpperCase()}`;
|
||||||
export const CYCLE_ISSUES = (cycleId: string) => `CYCLE_ISSUES_${cycleId.toUpperCase()}`;
|
export const CYCLE_ISSUES = (cycleId: string) => `CYCLE_ISSUES_${cycleId.toUpperCase()}`;
|
||||||
export const CYCLE_ISSUES_WITH_PARAMS = (cycleId: string, params?: any) => {
|
export const CYCLE_ISSUES_WITH_PARAMS = (cycleId: string, params?: any) => {
|
||||||
if (!params) return `CYCLE_ISSUES_WITH_PARAMS_${cycleId.toUpperCase()}`;
|
if (!params) return `CYCLE_ISSUES_WITH_PARAMS_${cycleId.toUpperCase()}`;
|
||||||
@ -122,7 +123,12 @@ export const SUB_ISSUES = (issueId: string) => `SUB_ISSUES_${issueId.toUpperCase
|
|||||||
// integrations
|
// integrations
|
||||||
|
|
||||||
// Calendar
|
// Calendar
|
||||||
export const CALENDAR_ISSUES = (projectId: string) => `CALENDAR_ISSUES_${projectId}`;
|
export const PROJECT_CALENDAR_ISSUES = (projectId: string) =>
|
||||||
|
`CALENDAR_ISSUES_${projectId.toUpperCase()}`;
|
||||||
|
export const CYCLE_CALENDAR_ISSUES = (projectId: string, cycleId: string) =>
|
||||||
|
`CALENDAR_ISSUES_${projectId.toUpperCase()}_${cycleId.toUpperCase()}`;
|
||||||
|
export const MODULE_CALENDAR_ISSUES = (projectId: string, moduleId: string) =>
|
||||||
|
`CALENDAR_ISSUES_${projectId.toUpperCase()}_${moduleId.toUpperCase()}`;
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
export const RECENT_PAGES_LIST = (projectId: string) =>
|
export const RECENT_PAGES_LIST = (projectId: string) =>
|
||||||
|
@ -80,7 +80,7 @@ class ProjectCycleServices extends APIService {
|
|||||||
workspaceSlug: string,
|
workspaceSlug: string,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
cycleId: string,
|
cycleId: string,
|
||||||
queries?: IIssueViewOptions
|
queries?: Partial<IIssueViewOptions>
|
||||||
): Promise<IIssue[] | { [key: string]: IIssue[] }> {
|
): Promise<IIssue[] | { [key: string]: IIssue[] }> {
|
||||||
return this.get(
|
return this.get(
|
||||||
`/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/${cycleId}/cycle-issues/`,
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/${cycleId}/cycle-issues/`,
|
||||||
|
@ -111,7 +111,7 @@ class ProjectIssuesServices extends APIService {
|
|||||||
workspaceSlug: string,
|
workspaceSlug: string,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
moduleId: string,
|
moduleId: string,
|
||||||
queries?: IIssueViewOptions
|
queries?: Partial<IIssueViewOptions>
|
||||||
): Promise<
|
): Promise<
|
||||||
| IIssue[]
|
| IIssue[]
|
||||||
| {
|
| {
|
||||||
|
1
apps/app/types/issues.d.ts
vendored
1
apps/app/types/issues.d.ts
vendored
@ -250,4 +250,5 @@ export interface IIssueViewOptions {
|
|||||||
group_by: TIssueGroupByOptions;
|
group_by: TIssueGroupByOptions;
|
||||||
order_by: TIssueOrderByOptions;
|
order_by: TIssueOrderByOptions;
|
||||||
filters: IIssueFilterOptions;
|
filters: IIssueFilterOptions;
|
||||||
|
target_date: string;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user