2023-01-30 14:05:18 +00:00
|
|
|
import { createContext, useCallback, useEffect, useReducer } from "react";
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
import useSWR, { mutate } from "swr";
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
// components
|
|
|
|
import ToastAlert from "components/toast-alert";
|
|
|
|
// services
|
|
|
|
import projectService from "services/project.service";
|
2023-04-19 11:55:31 +00:00
|
|
|
import cyclesService from "services/cycles.service";
|
|
|
|
import modulesService from "services/modules.service";
|
2023-03-16 08:37:19 +00:00
|
|
|
import viewsService from "services/views.service";
|
2023-01-26 18:12:20 +00:00
|
|
|
// types
|
2023-03-27 20:22:13 +00:00
|
|
|
import {
|
|
|
|
IIssueFilterOptions,
|
2023-03-29 20:31:53 +00:00
|
|
|
TIssueViewOptions,
|
2023-03-27 20:22:13 +00:00
|
|
|
IProjectMember,
|
|
|
|
TIssueGroupByOptions,
|
|
|
|
TIssueOrderByOptions,
|
2023-06-06 16:06:00 +00:00
|
|
|
ICurrentUserResponse,
|
2023-03-27 20:22:13 +00:00
|
|
|
} from "types";
|
2023-01-26 18:12:20 +00:00
|
|
|
// fetch-keys
|
2023-04-19 11:55:31 +00:00
|
|
|
import {
|
|
|
|
CYCLE_DETAILS,
|
|
|
|
MODULE_DETAILS,
|
|
|
|
USER_PROJECT_VIEW,
|
|
|
|
VIEW_DETAILS,
|
|
|
|
} from "constants/fetch-keys";
|
2023-06-06 16:06:00 +00:00
|
|
|
import useUserAuth from "hooks/use-user-auth";
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
export const issueViewContext = createContext<ContextType>({} as ContextType);
|
|
|
|
|
|
|
|
type IssueViewProps = {
|
2023-03-29 20:31:53 +00:00
|
|
|
issueView: TIssueViewOptions;
|
2023-03-23 19:41:42 +00:00
|
|
|
groupByProperty: TIssueGroupByOptions;
|
2023-03-27 20:22:13 +00:00
|
|
|
orderBy: TIssueOrderByOptions;
|
2023-03-22 20:43:52 +00:00
|
|
|
showEmptyGroups: boolean;
|
2023-07-25 07:39:38 +00:00
|
|
|
showSubIssues: boolean;
|
2023-05-15 06:05:07 +00:00
|
|
|
calendarDateRange: string;
|
2023-03-15 06:14:44 +00:00
|
|
|
filters: IIssueFilterOptions;
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type ReducerActionType = {
|
|
|
|
type:
|
2023-01-30 14:05:18 +00:00
|
|
|
| "REHYDRATE_THEME"
|
2023-01-26 18:12:20 +00:00
|
|
|
| "SET_ISSUE_VIEW"
|
|
|
|
| "SET_ORDER_BY_PROPERTY"
|
2023-03-22 20:43:52 +00:00
|
|
|
| "SET_SHOW_EMPTY_STATES"
|
2023-05-15 06:05:07 +00:00
|
|
|
| "SET_CALENDAR_DATE_RANGE"
|
2023-03-15 06:14:44 +00:00
|
|
|
| "SET_FILTERS"
|
2023-01-26 18:12:20 +00:00
|
|
|
| "SET_GROUP_BY_PROPERTY"
|
2023-07-25 07:39:38 +00:00
|
|
|
| "RESET_TO_DEFAULT"
|
|
|
|
| "SET_SHOW_SUB_ISSUES";
|
2023-01-26 18:12:20 +00:00
|
|
|
payload?: Partial<IssueViewProps>;
|
|
|
|
};
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
type ContextType = IssueViewProps & {
|
2023-03-23 19:41:42 +00:00
|
|
|
setGroupByProperty: (property: TIssueGroupByOptions) => void;
|
2023-03-27 20:22:13 +00:00
|
|
|
setOrderBy: (property: TIssueOrderByOptions) => void;
|
2023-03-22 20:43:52 +00:00
|
|
|
setShowEmptyGroups: (property: boolean) => void;
|
2023-07-25 07:39:38 +00:00
|
|
|
setShowSubIssues: (value: boolean) => void;
|
2023-05-15 06:05:07 +00:00
|
|
|
setCalendarDateRange: (property: string) => void;
|
2023-03-22 12:48:19 +00:00
|
|
|
setFilters: (filters: Partial<IIssueFilterOptions>, saveToServer?: boolean) => void;
|
2023-01-26 18:12:20 +00:00
|
|
|
resetFilterToDefault: () => void;
|
|
|
|
setNewFilterDefaultView: () => void;
|
2023-03-29 20:31:53 +00:00
|
|
|
setIssueView: (property: TIssueViewOptions) => void;
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type StateType = {
|
2023-03-29 20:31:53 +00:00
|
|
|
issueView: TIssueViewOptions;
|
2023-03-23 19:41:42 +00:00
|
|
|
groupByProperty: TIssueGroupByOptions;
|
2023-03-27 20:22:13 +00:00
|
|
|
orderBy: TIssueOrderByOptions;
|
2023-03-22 20:43:52 +00:00
|
|
|
showEmptyGroups: boolean;
|
2023-07-25 07:39:38 +00:00
|
|
|
showSubIssues: boolean;
|
2023-05-15 06:05:07 +00:00
|
|
|
calendarDateRange: string;
|
2023-03-15 06:14:44 +00:00
|
|
|
filters: IIssueFilterOptions;
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
|
|
|
type ReducerFunctionType = (state: StateType, action: ReducerActionType) => StateType;
|
|
|
|
|
|
|
|
export const initialState: StateType = {
|
|
|
|
issueView: "list",
|
|
|
|
groupByProperty: null,
|
2023-03-27 20:22:13 +00:00
|
|
|
orderBy: "-created_at",
|
2023-03-23 17:55:30 +00:00
|
|
|
showEmptyGroups: true,
|
2023-07-26 12:22:03 +00:00
|
|
|
showSubIssues: true,
|
2023-05-15 06:05:07 +00:00
|
|
|
calendarDateRange: "",
|
2023-03-15 06:14:44 +00:00
|
|
|
filters: {
|
|
|
|
type: null,
|
2023-03-16 08:37:19 +00:00
|
|
|
priority: null,
|
2023-03-15 06:14:44 +00:00
|
|
|
assignees: null,
|
|
|
|
labels: null,
|
2023-03-16 08:37:19 +00:00
|
|
|
state: null,
|
2023-07-26 19:27:12 +00:00
|
|
|
state_group: null,
|
2023-08-08 07:45:25 +00:00
|
|
|
subscriber: null,
|
2023-03-24 18:01:56 +00:00
|
|
|
created_by: null,
|
2023-07-04 17:43:07 +00:00
|
|
|
target_date: null,
|
2023-03-15 06:14:44 +00:00
|
|
|
},
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const reducer: ReducerFunctionType = (state, action) => {
|
|
|
|
const { type, payload } = action;
|
|
|
|
|
|
|
|
switch (type) {
|
2023-01-30 14:05:18 +00:00
|
|
|
case "REHYDRATE_THEME": {
|
|
|
|
let collapsed: any = localStorage.getItem("collapsed");
|
|
|
|
collapsed = collapsed ? JSON.parse(collapsed) : false;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-01-30 14:05:18 +00:00
|
|
|
return { ...initialState, ...payload, collapsed };
|
|
|
|
}
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
case "SET_ISSUE_VIEW": {
|
|
|
|
const newState = {
|
|
|
|
...state,
|
|
|
|
issueView: payload?.issueView || "list",
|
|
|
|
};
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...newState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
case "SET_GROUP_BY_PROPERTY": {
|
|
|
|
const newState = {
|
|
|
|
...state,
|
|
|
|
groupByProperty: payload?.groupByProperty || null,
|
|
|
|
};
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...newState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
case "SET_ORDER_BY_PROPERTY": {
|
|
|
|
const newState = {
|
|
|
|
...state,
|
2023-03-27 20:22:13 +00:00
|
|
|
orderBy: payload?.orderBy || "-created_at",
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...newState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-22 20:43:52 +00:00
|
|
|
case "SET_SHOW_EMPTY_STATES": {
|
|
|
|
const newState = {
|
|
|
|
...state,
|
2023-03-23 17:55:30 +00:00
|
|
|
showEmptyGroups: payload?.showEmptyGroups || true,
|
2023-03-22 20:43:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...newState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-25 07:39:38 +00:00
|
|
|
case "SET_SHOW_SUB_ISSUES": {
|
|
|
|
const newState = {
|
|
|
|
...state,
|
2023-07-26 12:22:03 +00:00
|
|
|
showSubIssues: payload?.showSubIssues || true,
|
2023-07-25 07:39:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...newState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-05-15 06:05:07 +00:00
|
|
|
case "SET_CALENDAR_DATE_RANGE": {
|
|
|
|
const newState = {
|
|
|
|
...state,
|
|
|
|
calendarDateRange: payload?.calendarDateRange || "",
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...newState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
case "SET_FILTERS": {
|
2023-01-26 18:12:20 +00:00
|
|
|
const newState = {
|
|
|
|
...state,
|
2023-03-15 06:14:44 +00:00
|
|
|
filters: {
|
|
|
|
...state.filters,
|
2023-06-21 12:02:56 +00:00
|
|
|
...payload?.filters,
|
2023-03-15 06:14:44 +00:00
|
|
|
},
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...newState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
case "RESET_TO_DEFAULT": {
|
|
|
|
return {
|
|
|
|
...initialState,
|
|
|
|
...payload,
|
|
|
|
};
|
|
|
|
}
|
2023-02-14 14:35:32 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
default: {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const saveDataToServer = async (workspaceSlug: string, projectID: string, state: any) => {
|
2023-05-29 13:05:43 +00:00
|
|
|
mutate<IProjectMember>(
|
|
|
|
workspaceSlug && projectID ? USER_PROJECT_VIEW(projectID as string) : null,
|
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: state,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
await projectService.setProjectView(workspaceSlug, projectID, {
|
|
|
|
view_props: state,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-04-19 11:55:31 +00:00
|
|
|
const saveCycleFilters = async (
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
cycleId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
state: any,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-04-19 11:55:31 +00:00
|
|
|
) => {
|
2023-06-06 16:06:00 +00:00
|
|
|
await cyclesService.patchCycle(
|
|
|
|
workspaceSlug,
|
|
|
|
projectId,
|
|
|
|
cycleId,
|
|
|
|
{
|
|
|
|
...state,
|
|
|
|
},
|
|
|
|
user
|
|
|
|
);
|
2023-04-19 11:55:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const saveModuleFilters = async (
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
moduleId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
state: any,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-04-19 11:55:31 +00:00
|
|
|
) => {
|
2023-06-06 16:06:00 +00:00
|
|
|
await modulesService.patchModule(
|
|
|
|
workspaceSlug,
|
|
|
|
projectId,
|
|
|
|
moduleId,
|
|
|
|
{
|
|
|
|
...state,
|
|
|
|
},
|
|
|
|
user
|
|
|
|
);
|
2023-04-19 11:55:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const saveViewFilters = async (
|
2023-03-16 08:37:19 +00:00
|
|
|
workspaceSlug: string,
|
2023-03-23 19:41:42 +00:00
|
|
|
projectId: string,
|
2023-03-16 08:37:19 +00:00
|
|
|
viewId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
state: any,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-16 08:37:19 +00:00
|
|
|
) => {
|
2023-06-06 16:06:00 +00:00
|
|
|
await viewsService.patchView(
|
|
|
|
workspaceSlug,
|
|
|
|
projectId,
|
|
|
|
viewId,
|
|
|
|
{
|
|
|
|
...state,
|
|
|
|
},
|
|
|
|
user
|
|
|
|
);
|
2023-03-16 08:37:19 +00:00
|
|
|
};
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
const setNewDefault = async (workspaceSlug: string, projectId: string, state: any) => {
|
|
|
|
mutate<IProjectMember>(
|
|
|
|
workspaceSlug && projectId ? USER_PROJECT_VIEW(projectId as string) : null,
|
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: state,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
await projectService.setProjectView(workspaceSlug, projectId, {
|
2023-01-26 18:12:20 +00:00
|
|
|
view_props: state,
|
|
|
|
default_props: state,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const IssueViewContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
|
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
|
|
|
|
|
|
const router = useRouter();
|
2023-04-19 11:55:31 +00:00
|
|
|
const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query;
|
2023-01-26 18:12:20 +00:00
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
const { user } = useUserAuth();
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
const { data: myViewProps, mutate: mutateMyViewProps } = useSWR(
|
|
|
|
workspaceSlug && projectId ? USER_PROJECT_VIEW(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.projectMemberMe(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-03-16 08:37:19 +00:00
|
|
|
const { data: viewDetails, mutate: mutateViewDetails } = useSWR(
|
|
|
|
workspaceSlug && projectId && viewId ? VIEW_DETAILS(viewId as string) : null,
|
|
|
|
workspaceSlug && projectId && viewId
|
|
|
|
? () =>
|
|
|
|
viewsService.getViewDetails(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
viewId as string
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-04-19 11:55:31 +00:00
|
|
|
const { data: cycleDetails, mutate: mutateCycleDetails } = useSWR(
|
|
|
|
workspaceSlug && projectId && cycleId ? CYCLE_DETAILS(cycleId as string) : null,
|
|
|
|
workspaceSlug && projectId && cycleId
|
|
|
|
? () =>
|
|
|
|
cyclesService.getCycleDetails(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
|
|
|
cycleId.toString()
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const { data: moduleDetails, mutate: mutateModuleDetails } = useSWR(
|
|
|
|
workspaceSlug && projectId && moduleId ? MODULE_DETAILS(moduleId.toString()) : null,
|
|
|
|
workspaceSlug && projectId && moduleId
|
|
|
|
? () =>
|
|
|
|
modulesService.getModuleDetails(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
|
|
|
moduleId.toString()
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-03-29 20:31:53 +00:00
|
|
|
const setIssueView = useCallback(
|
|
|
|
(property: TIssueViewOptions) => {
|
|
|
|
dispatch({
|
|
|
|
type: "SET_ISSUE_VIEW",
|
|
|
|
payload: {
|
|
|
|
issueView: property,
|
|
|
|
},
|
|
|
|
});
|
2023-01-26 18:12:20 +00:00
|
|
|
|
2023-08-18 09:42:12 +00:00
|
|
|
const additionalProperties = {
|
|
|
|
groupByProperty: state.groupByProperty,
|
|
|
|
orderBy: state.orderBy,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (property === "kanban" && state.groupByProperty === null) {
|
|
|
|
additionalProperties.groupByProperty = "state";
|
2023-03-29 20:31:53 +00:00
|
|
|
dispatch({
|
|
|
|
type: "SET_GROUP_BY_PROPERTY",
|
|
|
|
payload: {
|
|
|
|
groupByProperty: "state",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-04-20 20:12:09 +00:00
|
|
|
if (property === "calendar") {
|
2023-08-18 09:42:12 +00:00
|
|
|
additionalProperties.groupByProperty = null;
|
2023-04-20 20:12:09 +00:00
|
|
|
dispatch({
|
|
|
|
type: "SET_GROUP_BY_PROPERTY",
|
|
|
|
payload: {
|
|
|
|
groupByProperty: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-08-18 09:42:12 +00:00
|
|
|
if (property === "gantt_chart") {
|
|
|
|
additionalProperties.orderBy = "sort_order";
|
|
|
|
dispatch({
|
|
|
|
type: "SET_ORDER_BY_PROPERTY",
|
|
|
|
payload: {
|
|
|
|
orderBy: "sort_order",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-03-29 20:31:53 +00:00
|
|
|
if (!workspaceSlug || !projectId) return;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-03-29 20:31:53 +00:00
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, {
|
|
|
|
...state,
|
|
|
|
issueView: property,
|
2023-08-18 09:42:12 +00:00
|
|
|
...additionalProperties,
|
2023-03-29 20:31:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
[workspaceSlug, projectId, state]
|
|
|
|
);
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
const setGroupByProperty = useCallback(
|
2023-03-23 19:41:42 +00:00
|
|
|
(property: TIssueGroupByOptions) => {
|
2023-01-26 18:12:20 +00:00
|
|
|
dispatch({
|
|
|
|
type: "SET_GROUP_BY_PROPERTY",
|
|
|
|
payload: {
|
|
|
|
groupByProperty: property,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-08-15 09:34:46 +00:00
|
|
|
mutateMyViewProps((prevData: any) => {
|
2023-03-15 06:14:44 +00:00
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: {
|
|
|
|
...state,
|
|
|
|
groupByProperty: property,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, {
|
|
|
|
...state,
|
|
|
|
groupByProperty: property,
|
|
|
|
});
|
|
|
|
},
|
2023-03-15 06:14:44 +00:00
|
|
|
[projectId, workspaceSlug, state, mutateMyViewProps]
|
2023-01-26 18:12:20 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const setOrderBy = useCallback(
|
2023-03-27 20:22:13 +00:00
|
|
|
(property: TIssueOrderByOptions) => {
|
2023-01-26 18:12:20 +00:00
|
|
|
dispatch({
|
|
|
|
type: "SET_ORDER_BY_PROPERTY",
|
|
|
|
payload: {
|
|
|
|
orderBy: property,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-08-15 09:34:46 +00:00
|
|
|
mutateMyViewProps((prevData: any) => {
|
2023-03-15 06:14:44 +00:00
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: {
|
|
|
|
...state,
|
|
|
|
orderBy: property,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
|
|
|
|
2023-02-23 12:20:47 +00:00
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, {
|
|
|
|
...state,
|
|
|
|
orderBy: property,
|
|
|
|
});
|
2023-01-26 18:12:20 +00:00
|
|
|
},
|
2023-03-15 06:14:44 +00:00
|
|
|
[projectId, workspaceSlug, state, mutateMyViewProps]
|
2023-01-26 18:12:20 +00:00
|
|
|
);
|
|
|
|
|
2023-03-22 20:43:52 +00:00
|
|
|
const setShowEmptyGroups = useCallback(
|
|
|
|
(property: boolean) => {
|
|
|
|
dispatch({
|
|
|
|
type: "SET_SHOW_EMPTY_STATES",
|
|
|
|
payload: {
|
|
|
|
showEmptyGroups: property,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
2023-08-15 09:34:46 +00:00
|
|
|
mutateMyViewProps((prevData: any) => {
|
2023-03-22 20:43:52 +00:00
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: {
|
|
|
|
...state,
|
|
|
|
showEmptyGroups: property,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, {
|
|
|
|
...state,
|
|
|
|
showEmptyGroups: property,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[projectId, workspaceSlug, state, mutateMyViewProps]
|
|
|
|
);
|
|
|
|
|
2023-07-25 07:39:38 +00:00
|
|
|
const setShowSubIssues = useCallback(
|
|
|
|
(property: boolean) => {
|
|
|
|
dispatch({
|
|
|
|
type: "SET_SHOW_SUB_ISSUES",
|
|
|
|
payload: {
|
|
|
|
showSubIssues: property,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
2023-08-15 09:34:46 +00:00
|
|
|
mutateMyViewProps((prevData: any) => {
|
2023-07-25 07:39:38 +00:00
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: {
|
|
|
|
...state,
|
|
|
|
showSubIssues: property,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, {
|
|
|
|
...state,
|
|
|
|
showSubIssues: property,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[projectId, workspaceSlug, state, mutateMyViewProps]
|
|
|
|
);
|
|
|
|
|
2023-05-15 06:05:07 +00:00
|
|
|
const setCalendarDateRange = useCallback(
|
|
|
|
(value: string) => {
|
|
|
|
dispatch({
|
|
|
|
type: "SET_CALENDAR_DATE_RANGE",
|
|
|
|
payload: {
|
|
|
|
calendarDateRange: value,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
2023-08-15 09:34:46 +00:00
|
|
|
mutateMyViewProps((prevData: any) => {
|
2023-05-15 06:05:07 +00:00
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: {
|
|
|
|
...state,
|
|
|
|
calendarDateRange: value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, {
|
|
|
|
...state,
|
|
|
|
calendarDateRange: value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[projectId, workspaceSlug, state, mutateMyViewProps]
|
|
|
|
);
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
const setFilters = useCallback(
|
2023-03-22 12:48:19 +00:00
|
|
|
(property: Partial<IIssueFilterOptions>, saveToServer = true) => {
|
2023-03-21 11:41:04 +00:00
|
|
|
Object.keys(property).forEach((key) => {
|
2023-04-19 11:55:31 +00:00
|
|
|
if (property[key as keyof typeof property]?.length === 0)
|
2023-03-21 11:41:04 +00:00
|
|
|
property[key as keyof typeof property] = null;
|
|
|
|
});
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
dispatch({
|
2023-03-15 06:14:44 +00:00
|
|
|
type: "SET_FILTERS",
|
2023-01-26 18:12:20 +00:00
|
|
|
payload: {
|
2023-03-15 06:14:44 +00:00
|
|
|
filters: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
2023-01-26 18:12:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-04-19 11:55:31 +00:00
|
|
|
if (cycleId) {
|
|
|
|
mutateCycleDetails((prevData: any) => {
|
|
|
|
if (!prevData) return prevData;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-04-19 11:55:31 +00:00
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: {
|
|
|
|
filters: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
saveCycleFilters(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
|
|
|
cycleId.toString(),
|
|
|
|
{
|
|
|
|
view_props: {
|
|
|
|
filters: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
2023-03-15 06:14:44 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user
|
|
|
|
);
|
2023-04-19 11:55:31 +00:00
|
|
|
} else if (moduleId) {
|
|
|
|
mutateModuleDetails((prevData: any) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: {
|
|
|
|
filters: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
saveModuleFilters(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
|
|
|
moduleId.toString(),
|
|
|
|
{
|
|
|
|
view_props: {
|
|
|
|
filters: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
2023-04-19 11:55:31 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user
|
|
|
|
);
|
2023-04-19 11:55:31 +00:00
|
|
|
} else if (viewId) {
|
2023-03-16 08:37:19 +00:00
|
|
|
mutateViewDetails((prevData: any) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
query_data: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
2023-03-22 12:48:19 +00:00
|
|
|
if (saveToServer)
|
2023-06-06 16:06:00 +00:00
|
|
|
saveViewFilters(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
viewId as string,
|
|
|
|
{
|
|
|
|
query_data: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
2023-03-22 12:48:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user
|
|
|
|
);
|
2023-04-19 11:55:31 +00:00
|
|
|
} else {
|
2023-08-15 09:34:46 +00:00
|
|
|
mutateMyViewProps((prevData: any) => {
|
2023-04-19 11:55:31 +00:00
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: {
|
|
|
|
...state,
|
|
|
|
filters: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, false);
|
|
|
|
|
2023-03-16 08:37:19 +00:00
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, {
|
|
|
|
...state,
|
|
|
|
filters: {
|
|
|
|
...state.filters,
|
|
|
|
...property,
|
|
|
|
},
|
|
|
|
});
|
2023-04-19 11:55:31 +00:00
|
|
|
}
|
2023-01-26 18:12:20 +00:00
|
|
|
},
|
2023-04-19 11:55:31 +00:00
|
|
|
[
|
|
|
|
projectId,
|
|
|
|
workspaceSlug,
|
|
|
|
state,
|
|
|
|
mutateMyViewProps,
|
|
|
|
cycleId,
|
|
|
|
mutateCycleDetails,
|
|
|
|
moduleId,
|
|
|
|
mutateModuleDetails,
|
|
|
|
viewId,
|
|
|
|
mutateViewDetails,
|
2023-06-16 13:27:17 +00:00
|
|
|
user,
|
2023-04-19 11:55:31 +00:00
|
|
|
]
|
2023-01-26 18:12:20 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const setNewDefaultView = useCallback(() => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
setNewDefault(workspaceSlug as string, projectId as string, state).then(() => {
|
|
|
|
mutateMyViewProps();
|
|
|
|
});
|
|
|
|
}, [projectId, workspaceSlug, state, mutateMyViewProps]);
|
|
|
|
|
|
|
|
const resetToDefault = useCallback(() => {
|
|
|
|
dispatch({
|
|
|
|
type: "RESET_TO_DEFAULT",
|
|
|
|
payload: myViewProps?.default_props,
|
|
|
|
});
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
if (!workspaceSlug || !projectId) return;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, myViewProps?.default_props);
|
|
|
|
}, [projectId, workspaceSlug, myViewProps]);
|
|
|
|
|
2023-01-30 14:05:18 +00:00
|
|
|
useEffect(() => {
|
|
|
|
dispatch({
|
|
|
|
type: "REHYDRATE_THEME",
|
2023-03-16 08:37:19 +00:00
|
|
|
payload: {
|
|
|
|
...myViewProps?.view_props,
|
|
|
|
filters: {
|
2023-04-19 11:55:31 +00:00
|
|
|
...(cycleId
|
|
|
|
? cycleDetails?.view_props.filters
|
|
|
|
: moduleId
|
|
|
|
? moduleDetails?.view_props.filters
|
|
|
|
: viewId
|
|
|
|
? viewDetails?.query_data
|
|
|
|
: myViewProps?.view_props?.filters),
|
2023-03-16 08:37:19 +00:00
|
|
|
} as any,
|
|
|
|
},
|
2023-01-30 14:05:18 +00:00
|
|
|
});
|
2023-04-19 11:55:31 +00:00
|
|
|
}, [myViewProps, cycleId, cycleDetails, moduleId, moduleDetails, viewId, viewDetails]);
|
2023-01-30 14:05:18 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
return (
|
|
|
|
<issueViewContext.Provider
|
|
|
|
value={{
|
|
|
|
issueView: state.issueView,
|
|
|
|
groupByProperty: state.groupByProperty,
|
|
|
|
setGroupByProperty,
|
|
|
|
orderBy: state.orderBy,
|
2023-03-22 20:43:52 +00:00
|
|
|
showEmptyGroups: state.showEmptyGroups,
|
2023-07-25 07:39:38 +00:00
|
|
|
showSubIssues: state.showSubIssues,
|
2023-05-15 06:05:07 +00:00
|
|
|
calendarDateRange: state.calendarDateRange,
|
|
|
|
setCalendarDateRange,
|
2023-01-26 18:12:20 +00:00
|
|
|
setOrderBy,
|
2023-03-22 20:43:52 +00:00
|
|
|
setShowEmptyGroups,
|
2023-07-25 07:39:38 +00:00
|
|
|
setShowSubIssues,
|
2023-03-15 06:14:44 +00:00
|
|
|
filters: state.filters,
|
|
|
|
setFilters,
|
2023-01-26 18:12:20 +00:00
|
|
|
resetFilterToDefault: resetToDefault,
|
|
|
|
setNewFilterDefaultView: setNewDefaultView,
|
2023-03-29 20:31:53 +00:00
|
|
|
setIssueView,
|
2023-01-26 18:12:20 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<ToastAlert />
|
|
|
|
{children}
|
|
|
|
</issueViewContext.Provider>
|
|
|
|
);
|
|
|
|
};
|