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-09-12 16:57:15 +00:00
|
|
|
// hooks
|
|
|
|
import useUserAuth from "hooks/use-user-auth";
|
2023-01-26 18:12:20 +00:00
|
|
|
// types
|
2023-03-27 20:22:13 +00:00
|
|
|
import {
|
|
|
|
IIssueFilterOptions,
|
|
|
|
IProjectMember,
|
2023-06-06 16:06:00 +00:00
|
|
|
ICurrentUserResponse,
|
2023-09-12 16:57:15 +00:00
|
|
|
IIssueDisplayFilterOptions,
|
|
|
|
IProjectViewProps,
|
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-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
export const issueViewContext = createContext<ContextType>({} as ContextType);
|
|
|
|
|
|
|
|
type ReducerActionType = {
|
2023-09-12 16:57:15 +00:00
|
|
|
type: "REHYDRATE_THEME" | "SET_DISPLAY_FILTERS" | "SET_FILTERS" | "RESET_TO_DEFAULT";
|
|
|
|
payload?: Partial<IProjectViewProps>;
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
|
|
|
|
2023-09-12 16:57:15 +00:00
|
|
|
type ContextType = IProjectViewProps & {
|
|
|
|
setDisplayFilters: (displayFilter: Partial<IIssueDisplayFilterOptions>) => 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-09-12 16:57:15 +00:00
|
|
|
type StateType = IProjectViewProps;
|
2023-01-26 18:12:20 +00:00
|
|
|
type ReducerFunctionType = (state: StateType, action: ReducerActionType) => StateType;
|
|
|
|
|
|
|
|
export const initialState: StateType = {
|
2023-09-12 16:57:15 +00:00
|
|
|
display_filters: {
|
|
|
|
calendar_date_range: "",
|
|
|
|
group_by: null,
|
|
|
|
layout: "list",
|
|
|
|
order_by: "-created_at",
|
|
|
|
show_empty_groups: true,
|
|
|
|
sub_issue: true,
|
|
|
|
},
|
2023-03-15 06:14:44 +00:00
|
|
|
filters: {
|
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-08-24 14:15:23 +00:00
|
|
|
start_date: 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-09-12 16:57:15 +00:00
|
|
|
case "SET_DISPLAY_FILTERS": {
|
2023-05-15 06:05:07 +00:00
|
|
|
const newState = {
|
|
|
|
...state,
|
2023-09-12 16:57:15 +00:00
|
|
|
display_filters: {
|
|
|
|
...state.display_filters,
|
|
|
|
...payload,
|
|
|
|
},
|
|
|
|
issueView: payload?.display_filters?.layout || "list",
|
2023-05-15 06:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-09-12 16:57:15 +00:00
|
|
|
const saveDataToServer = async (
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
state: IProjectViewProps
|
|
|
|
) => {
|
2023-05-29 13:05:43 +00:00
|
|
|
mutate<IProjectMember>(
|
2023-09-12 16:57:15 +00:00
|
|
|
workspaceSlug && projectId ? USER_PROJECT_VIEW(projectId as string) : null,
|
2023-05-29 13:05:43 +00:00
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
view_props: state,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2023-09-12 16:57:15 +00:00
|
|
|
await projectService.setProjectView(workspaceSlug, projectId, {
|
2023-01-26 18:12:20 +00:00
|
|
|
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-09-12 16:57:15 +00:00
|
|
|
const setDisplayFilters = useCallback(
|
|
|
|
(displayFilter: Partial<IIssueDisplayFilterOptions>) => {
|
2023-03-29 20:31:53 +00:00
|
|
|
dispatch({
|
2023-09-12 16:57:15 +00:00
|
|
|
type: "SET_DISPLAY_FILTERS",
|
2023-03-29 20:31:53 +00:00
|
|
|
payload: {
|
2023-09-12 16:57:15 +00:00
|
|
|
display_filters: {
|
|
|
|
...state.display_filters,
|
|
|
|
...displayFilter,
|
|
|
|
},
|
2023-03-29 20:31:53 +00:00
|
|
|
},
|
|
|
|
});
|
2023-01-26 18:12:20 +00:00
|
|
|
|
2023-09-12 16:57:15 +00:00
|
|
|
const additionalProperties: Partial<IIssueDisplayFilterOptions> = {
|
|
|
|
group_by: displayFilter.group_by ?? state.display_filters?.group_by,
|
|
|
|
order_by: displayFilter.order_by ?? state.display_filters?.order_by,
|
2023-08-18 09:42:12 +00:00
|
|
|
};
|
|
|
|
|
2023-09-12 16:57:15 +00:00
|
|
|
if (
|
|
|
|
displayFilter.layout &&
|
|
|
|
displayFilter.layout === "kanban" &&
|
|
|
|
state.display_filters?.group_by === null
|
|
|
|
) {
|
|
|
|
additionalProperties.group_by = "state";
|
2023-03-29 20:31:53 +00:00
|
|
|
dispatch({
|
2023-09-12 16:57:15 +00:00
|
|
|
type: "SET_DISPLAY_FILTERS",
|
2023-03-29 20:31:53 +00:00
|
|
|
payload: {
|
2023-09-12 16:57:15 +00:00
|
|
|
display_filters: {
|
|
|
|
group_by: "state",
|
|
|
|
},
|
2023-03-29 20:31:53 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-09-12 16:57:15 +00:00
|
|
|
if (displayFilter.layout && displayFilter.layout === "calendar") {
|
|
|
|
additionalProperties.group_by = null;
|
2023-04-20 20:12:09 +00:00
|
|
|
dispatch({
|
2023-09-12 16:57:15 +00:00
|
|
|
type: "SET_DISPLAY_FILTERS",
|
2023-04-20 20:12:09 +00:00
|
|
|
payload: {
|
2023-09-12 16:57:15 +00:00
|
|
|
display_filters: {
|
|
|
|
group_by: null,
|
|
|
|
},
|
2023-04-20 20:12:09 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-09-12 16:57:15 +00:00
|
|
|
if (displayFilter.layout && displayFilter.layout === "gantt_chart") {
|
|
|
|
additionalProperties.order_by = "sort_order";
|
2023-08-18 09:42:12 +00:00
|
|
|
dispatch({
|
2023-09-12 16:57:15 +00:00
|
|
|
type: "SET_DISPLAY_FILTERS",
|
2023-08-18 09:42:12 +00:00
|
|
|
payload: {
|
2023-09-12 16:57:15 +00:00
|
|
|
display_filters: {
|
|
|
|
order_by: "sort_order",
|
|
|
|
},
|
2023-08-18 09:42:12 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
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,
|
2023-09-12 16:57:15 +00:00
|
|
|
display_filters: {
|
|
|
|
...state.display_filters,
|
|
|
|
...displayFilter,
|
|
|
|
...additionalProperties,
|
2023-07-25 07:39:38 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2023-09-12 16:57:15 +00:00
|
|
|
[workspaceSlug, projectId, state]
|
2023-05-15 06:05:07 +00:00
|
|
|
);
|
|
|
|
|
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-09-12 16:57:15 +00:00
|
|
|
if (!workspaceSlug || !projectId || !myViewProps) return;
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-09-12 16:57:15 +00:00
|
|
|
saveDataToServer(workspaceSlug as string, projectId as string, myViewProps.default_props);
|
2023-01-26 18:12:20 +00:00
|
|
|
}, [projectId, workspaceSlug, myViewProps]);
|
|
|
|
|
2023-01-30 14:05:18 +00:00
|
|
|
useEffect(() => {
|
2023-09-12 16:57:15 +00:00
|
|
|
console.log("running");
|
2023-01-30 14:05:18 +00:00
|
|
|
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={{
|
2023-09-12 16:57:15 +00:00
|
|
|
display_filters: state.display_filters,
|
|
|
|
setDisplayFilters,
|
2023-03-15 06:14:44 +00:00
|
|
|
filters: state.filters,
|
|
|
|
setFilters,
|
2023-01-26 18:12:20 +00:00
|
|
|
resetFilterToDefault: resetToDefault,
|
|
|
|
setNewFilterDefaultView: setNewDefaultView,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<ToastAlert />
|
|
|
|
{children}
|
|
|
|
</issueViewContext.Provider>
|
|
|
|
);
|
|
|
|
};
|