chore: workspace view display filters and properties , code refactor (#2295)
* chore: spreadsheet view context * chore: spreadsheet context provider * chore: spreadsheet view context * chore: display filters and properties added in workspace view and code refactor * fix: build error fix * chore: set sub-issue display option to false for global views --------- Co-authored-by: gurusainath <gurusainath007@gmail.com>
This commit is contained in:
parent
4503810aeb
commit
a048e513b7
48 changed files with 3119 additions and 2369 deletions
|
|
@ -118,7 +118,7 @@ const useMyIssuesFilters = (workspaceSlug: string | undefined) => {
|
|||
|
||||
const setProperty = useCallback(
|
||||
(key: keyof Properties) => {
|
||||
if (!myWorkspace) return;
|
||||
if (!myWorkspace?.view_props.display_properties) return;
|
||||
|
||||
saveData({
|
||||
display_properties: {
|
||||
|
|
|
|||
11
web/hooks/use-workspace-view.tsx
Normal file
11
web/hooks/use-workspace-view.tsx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { useContext } from "react";
|
||||
// types
|
||||
import { IWorkspaceViewContext, WorkspaceIssueViewContext } from "contexts/workspace-view-context";
|
||||
|
||||
export const useWorkspaceView = (): IWorkspaceViewContext => {
|
||||
const context = useContext(WorkspaceIssueViewContext);
|
||||
|
||||
if (!context) throw new Error("useWorkspaceView must be used within a WorkspaceIssueViewContext");
|
||||
|
||||
return context;
|
||||
};
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
import { useEffect, useCallback } from "react";
|
||||
|
||||
import useSWR, { mutate } from "swr";
|
||||
|
||||
// services
|
||||
import workspaceService from "services/workspace.service";
|
||||
// types
|
||||
import { IIssueFilterOptions, IView } from "types";
|
||||
// fetch-keys
|
||||
import { WORKSPACE_VIEW_DETAILS } from "constants/fetch-keys";
|
||||
|
||||
const initialValues: IIssueFilterOptions = {
|
||||
assignees: null,
|
||||
created_by: null,
|
||||
labels: null,
|
||||
priority: null,
|
||||
state: null,
|
||||
state_group: null,
|
||||
subscriber: null,
|
||||
start_date: null,
|
||||
target_date: null,
|
||||
project: null,
|
||||
};
|
||||
|
||||
const useWorkspaceIssuesFilters = (
|
||||
workspaceSlug: string | undefined,
|
||||
workspaceViewId: string | undefined
|
||||
) => {
|
||||
const { data: workspaceViewDetails } = useSWR(
|
||||
workspaceSlug && workspaceViewId ? WORKSPACE_VIEW_DETAILS(workspaceViewId) : null,
|
||||
workspaceSlug && workspaceViewId
|
||||
? () => workspaceService.getViewDetails(workspaceSlug, workspaceViewId)
|
||||
: null
|
||||
);
|
||||
|
||||
const saveData = useCallback(
|
||||
(data: Partial<IIssueFilterOptions>) => {
|
||||
if (!workspaceSlug || !workspaceViewId || !workspaceViewDetails) return;
|
||||
|
||||
const oldData = { ...workspaceViewDetails };
|
||||
|
||||
mutate<IView>(
|
||||
WORKSPACE_VIEW_DETAILS(workspaceViewId),
|
||||
(prevData) => {
|
||||
if (!prevData) return;
|
||||
return {
|
||||
...prevData,
|
||||
query_data: {
|
||||
...prevData?.query_data,
|
||||
...data,
|
||||
},
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
workspaceService.updateView(workspaceSlug, workspaceViewId, {
|
||||
query_data: {
|
||||
...oldData.query_data,
|
||||
...data,
|
||||
},
|
||||
});
|
||||
},
|
||||
[workspaceViewDetails, workspaceSlug, workspaceViewId]
|
||||
);
|
||||
|
||||
const filters = workspaceViewDetails?.query_data ?? initialValues;
|
||||
|
||||
const setFilters = useCallback(
|
||||
(updatedFilter: Partial<IIssueFilterOptions>) => {
|
||||
if (!workspaceViewDetails) return;
|
||||
|
||||
saveData({
|
||||
...workspaceViewDetails?.query_data,
|
||||
...updatedFilter,
|
||||
});
|
||||
},
|
||||
[workspaceViewDetails, saveData]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!workspaceViewDetails || !workspaceSlug || !workspaceViewId) return;
|
||||
|
||||
if (!workspaceViewDetails.query_data) {
|
||||
workspaceService.updateView(workspaceSlug, workspaceViewId, {
|
||||
query_data: { ...initialValues },
|
||||
});
|
||||
}
|
||||
}, [workspaceViewDetails, workspaceViewId, workspaceSlug]);
|
||||
|
||||
const params: any = {
|
||||
assignees: filters?.assignees ? filters?.assignees.join(",") : undefined,
|
||||
subscriber: filters?.subscriber ? filters?.subscriber.join(",") : undefined,
|
||||
state: filters?.state ? filters?.state.join(",") : undefined,
|
||||
state_group: filters?.state_group ? filters?.state_group.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,
|
||||
start_date: filters?.start_date ? filters?.start_date.join(",") : undefined,
|
||||
target_date: filters?.target_date ? filters?.target_date.join(",") : undefined,
|
||||
project: filters?.project ? filters?.project.join(",") : undefined,
|
||||
sub_issue: false,
|
||||
type: undefined,
|
||||
};
|
||||
|
||||
return {
|
||||
params,
|
||||
filters,
|
||||
setFilters,
|
||||
};
|
||||
};
|
||||
|
||||
export default useWorkspaceIssuesFilters;
|
||||
Loading…
Add table
Add a link
Reference in a new issue