From 3440fb962d09e0f3dfd66cefb67eeba2d542abf1 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia Date: Mon, 25 Sep 2023 11:47:06 +0530 Subject: [PATCH] chore: workspace issues types and fetch key added --- web/components/core/filters/filters-list.tsx | 1 + .../my-issues/my-issues-select-filters.tsx | 2 +- web/components/views/delete-view-modal.tsx | 3 ++- web/components/views/form.tsx | 4 ++-- web/components/views/modal.tsx | 3 ++- web/components/views/single-view-item.tsx | 3 ++- web/constants/fetch-keys.ts | 15 +++++++------ .../[workspaceSlug]/workspace-views/index.tsx | 12 +++++------ web/services/workspace.service.ts | 18 +++++++++------- web/types/view-props.d.ts | 4 +++- web/types/views.d.ts | 6 ++++-- web/types/workspace-view.d.ts | 21 +++++++++++++++++++ web/types/workspace.d.ts | 15 ------------- 13 files changed, 63 insertions(+), 44 deletions(-) create mode 100644 web/types/workspace-view.d.ts diff --git a/web/components/core/filters/filters-list.tsx b/web/components/core/filters/filters-list.tsx index 81a12bd862..37e6795b96 100644 --- a/web/components/core/filters/filters-list.tsx +++ b/web/components/core/filters/filters-list.tsx @@ -21,6 +21,7 @@ type Props = { labels: IIssueLabels[] | undefined; members: IUserLite[] | undefined; states: IState[] | undefined; + stateGroup?: string[] | undefined; }; export const FiltersList: React.FC = ({ diff --git a/web/components/issues/my-issues/my-issues-select-filters.tsx b/web/components/issues/my-issues/my-issues-select-filters.tsx index ce8e03797f..079a3b1e51 100644 --- a/web/components/issues/my-issues/my-issues-select-filters.tsx +++ b/web/components/issues/my-issues/my-issues-select-filters.tsx @@ -23,7 +23,7 @@ import { GROUP_CHOICES, PRIORITIES } from "constants/project"; import { DATE_FILTER_OPTIONS } from "constants/filters"; type Props = { - filters: Partial | IQuery; + filters: Partial; onSelect: (option: any) => void; direction?: "left" | "right"; height?: "sm" | "md" | "rg" | "lg"; diff --git a/web/components/views/delete-view-modal.tsx b/web/components/views/delete-view-modal.tsx index 0d49c62cce..a7bf19b78c 100644 --- a/web/components/views/delete-view-modal.tsx +++ b/web/components/views/delete-view-modal.tsx @@ -17,6 +17,7 @@ import { DangerButton, SecondaryButton } from "components/ui"; import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // types import type { ICurrentUserResponse, IView } from "types"; +import { IWorkspaceView } from "types/workspace-view"; // fetch-keys import { VIEWS_LIST, WORKSPACE_VIEWS_LIST } from "constants/fetch-keys"; @@ -24,7 +25,7 @@ type Props = { isOpen: boolean; viewType: "project" | "workspace"; setIsOpen: React.Dispatch>; - data: IView | null; + data: IView | IWorkspaceView | null; user: ICurrentUserResponse | undefined; }; diff --git a/web/components/views/form.tsx b/web/components/views/form.tsx index 0c57a95423..6deb229d2e 100644 --- a/web/components/views/form.tsx +++ b/web/components/views/form.tsx @@ -21,6 +21,7 @@ import { getStatesList } from "helpers/state.helper"; // types import { IQuery, IView } from "types"; import issuesService from "services/issues.service"; +import { IWorkspaceView } from "types/workspace-view"; // fetch-keys import { PROJECT_ISSUE_LABELS, STATES_LIST } from "constants/fetch-keys"; @@ -28,7 +29,7 @@ type Props = { handleFormSubmit: (values: IView) => Promise; handleClose: () => void; status: boolean; - data?: IView | null; + data?: IView | IWorkspaceView | null; preLoadedData?: Partial | null; }; @@ -96,7 +97,6 @@ export const ViewForm: React.FC = ({ state: null, start_date: null, target_date: null, - type: null, }); }; diff --git a/web/components/views/modal.tsx b/web/components/views/modal.tsx index 88e69554d8..9e0fc14e67 100644 --- a/web/components/views/modal.tsx +++ b/web/components/views/modal.tsx @@ -15,6 +15,7 @@ import useToast from "hooks/use-toast"; import { ViewForm } from "components/views"; // types import { ICurrentUserResponse, IView } from "types"; +import { IWorkspaceView } from "types/workspace-view"; // fetch-keys import { VIEWS_LIST, WORKSPACE_VIEWS_LIST } from "constants/fetch-keys"; @@ -22,7 +23,7 @@ type Props = { isOpen: boolean; viewType: "project" | "workspace"; handleClose: () => void; - data?: IView | null; + data?: IView | IWorkspaceView | null; preLoadedData?: Partial | null; user: ICurrentUserResponse | undefined; }; diff --git a/web/components/views/single-view-item.tsx b/web/components/views/single-view-item.tsx index d27eb3cf19..9d1ec0dc22 100644 --- a/web/components/views/single-view-item.tsx +++ b/web/components/views/single-view-item.tsx @@ -12,6 +12,7 @@ import { CustomMenu } from "components/ui"; import viewsService from "services/views.service"; // types import { IView } from "types"; +import { IWorkspaceView } from "types/workspace-view"; // fetch keys import { VIEWS_LIST } from "constants/fetch-keys"; // hooks @@ -20,7 +21,7 @@ import useToast from "hooks/use-toast"; import { truncateText } from "helpers/string.helper"; type Props = { - view: IView; + view: IView | IWorkspaceView; viewType: "project" | "workspace"; handleEditView: () => void; handleDeleteView: () => void; diff --git a/web/constants/fetch-keys.ts b/web/constants/fetch-keys.ts index 8ab17d1a7d..6f138d7352 100644 --- a/web/constants/fetch-keys.ts +++ b/web/constants/fetch-keys.ts @@ -4,6 +4,7 @@ import { IAnalyticsParams, IJiraMetadata, INotificationParams } from "types"; const paramsToKey = (params: any) => { const { state, + state_group, priority, assignees, created_by, @@ -17,6 +18,7 @@ const paramsToKey = (params: any) => { let projectKey = project ? project.split(",") : []; let stateKey = state ? state.split(",") : []; + let stateGroupKey = state_group ? state_group.split(",") : []; let priorityKey = priority ? priority.split(",") : []; let assigneesKey = assignees ? assignees.split(",") : []; let createdByKey = created_by ? created_by.split(",") : []; @@ -31,12 +33,13 @@ const paramsToKey = (params: any) => { // sorting each keys in ascending order projectKey = projectKey.sort().join("_"); stateKey = stateKey.sort().join("_"); + stateGroupKey = stateGroupKey.sort().join("_"); priorityKey = priorityKey.sort().join("_"); assigneesKey = assigneesKey.sort().join("_"); createdByKey = createdByKey.sort().join("_"); labelsKey = labelsKey.sort().join("_"); - return `${projectKey}_${stateKey}_${priorityKey}_${assigneesKey}_${createdByKey}_${type}_${groupBy}_${orderBy}_${labelsKey}_${startDateKey}_${targetDateKey}_${sub_issue}_${startTargetDate}`; + return `${projectKey}_${stateGroupKey}_${stateKey}_${priorityKey}_${assigneesKey}_${createdByKey}_${type}_${groupBy}_${orderBy}_${labelsKey}_${startDateKey}_${targetDateKey}_${sub_issue}_${startTargetDate}`; }; const inboxParamsToKey = (params: any) => { @@ -154,14 +157,14 @@ export const PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS = (projectId: string, params? export const WORKSPACE_VIEWS_LIST = (workspaceSlug: string) => `WORKSPACE_VIEWS_LIST_${workspaceSlug.toUpperCase()}`; -export const WORKSPACE_VIEW_DETAILS = (viewId: string) => - `WORKSPACE_VIEW_DETAILS_${viewId.toUpperCase()}`; -export const WORKSPACE_VIEW_ISSUES = (viewId: string, params: any) => { - if (!params) return `WORKSPACE_VIEW_ISSUES_${viewId.toUpperCase()}`; +export const WORKSPACE_VIEW_DETAILS = (workspaceViewId: string) => + `WORKSPACE_VIEW_DETAILS_${workspaceViewId.toUpperCase()}`; +export const WORKSPACE_VIEW_ISSUES = (workspaceViewId: string, params: any) => { + if (!params) return `WORKSPACE_VIEW_ISSUES_${workspaceViewId.toUpperCase()}`; const paramsKey = paramsToKey(params); - return `WORKSPACE_VIEW_ISSUES_${viewId.toUpperCase()}_${paramsKey.toUpperCase()}`; + return `WORKSPACE_VIEW_ISSUES_${workspaceViewId.toUpperCase()}_${paramsKey.toUpperCase()}`; }; export const PROJECT_ISSUES_DETAILS = (issueId: string) => diff --git a/web/pages/[workspaceSlug]/workspace-views/index.tsx b/web/pages/[workspaceSlug]/workspace-views/index.tsx index efec5d9fa4..115638799c 100644 --- a/web/pages/[workspaceSlug]/workspace-views/index.tsx +++ b/web/pages/[workspaceSlug]/workspace-views/index.tsx @@ -25,27 +25,25 @@ import { PhotoFilterOutlined } from "@mui/icons-material"; import emptyView from "public/empty-state/view.svg"; // types import type { NextPage } from "next"; -import { IView } from "types"; +import { IWorkspaceView } from "types/workspace-view"; // constants import { WORKSPACE_VIEWS_LIST } from "constants/fetch-keys"; // helper import { truncateText } from "helpers/string.helper"; const WorkspaceViews: NextPage = () => { - console.log("test"); - // const [currentView, setCurrentView] = useState(""); const [createUpdateViewModal, setCreateUpdateViewModal] = useState(false); - const [selectedViewToUpdate, setSelectedViewToUpdate] = useState(null); + const [selectedViewToUpdate, setSelectedViewToUpdate] = useState(null); const [deleteViewModal, setDeleteViewModal] = useState(false); - const [selectedViewToDelete, setSelectedViewToDelete] = useState(null); + const [selectedViewToDelete, setSelectedViewToDelete] = useState(null); - const handleEditView = (view: IView) => { + const handleEditView = (view: IWorkspaceView) => { setSelectedViewToUpdate(view); setCreateUpdateViewModal(true); }; - const handleDeleteView = (view: IView) => { + const handleDeleteView = (view: IWorkspaceView) => { setSelectedViewToDelete(view); setDeleteViewModal(true); }; diff --git a/web/services/workspace.service.ts b/web/services/workspace.service.ts index 385e61fd69..00dd79c48c 100644 --- a/web/services/workspace.service.ts +++ b/web/services/workspace.service.ts @@ -14,9 +14,9 @@ import { ICurrentUserResponse, IWorkspaceBulkInviteFormData, IWorkspaceViewProps, - IView, - WorkspaceViewIssueParams, + IIssueFilterOptions, } from "types"; +import { IWorkspaceView } from "types/workspace-view"; class WorkspaceService extends APIService { constructor() { @@ -264,7 +264,7 @@ class WorkspaceService extends APIService { }); } - async createView(workspaceSlug: string, data: IView): Promise { + async createView(workspaceSlug: string, data: IWorkspaceView): Promise { return this.post(`/api/workspaces/${workspaceSlug}/views/`, data) .then((response) => response?.data) .catch((error) => { @@ -272,7 +272,11 @@ class WorkspaceService extends APIService { }); } - async updateView(workspaceSlug: string, viewId: string, data: Partial): Promise { + async updateView( + workspaceSlug: string, + viewId: string, + data: Partial + ): Promise { return this.patch(`/api/workspaces/${workspaceSlug}/views/${viewId}/`, data) .then((response) => response?.data) .catch((error) => { @@ -288,7 +292,7 @@ class WorkspaceService extends APIService { }); } - async getAllViews(workspaceSlug: string): Promise { + async getAllViews(workspaceSlug: string): Promise { return this.get(`/api/workspaces/${workspaceSlug}/views/`) .then((response) => response?.data) .catch((error) => { @@ -296,7 +300,7 @@ class WorkspaceService extends APIService { }); } - async getViewDetails(workspaceSlug: string, viewId: string): Promise { + async getViewDetails(workspaceSlug: string, viewId: string): Promise { return this.get(`/api/workspaces/${workspaceSlug}/views/${viewId}/`) .then((response) => response?.data) .catch((error) => { @@ -304,7 +308,7 @@ class WorkspaceService extends APIService { }); } - async getViewIssues(workspaceSlug: string, params: WorkspaceViewIssueParams): Promise { + async getViewIssues(workspaceSlug: string, params: IIssueFilterOptions): Promise { return this.get(`/api/workspaces/${workspaceSlug}/issues/`, { params, }) diff --git a/web/types/view-props.d.ts b/web/types/view-props.d.ts index a02fc5540a..822e9afbfa 100644 --- a/web/types/view-props.d.ts +++ b/web/types/view-props.d.ts @@ -35,9 +35,11 @@ export interface IIssueFilterOptions { priority?: string[] | null; start_date?: string[] | null; state?: string[] | null; - state_group?: TStateGroups[] | null; + state_group?: string[] | null; subscriber?: string[] | null; target_date?: string[] | null; + estimate_point?: string[] | null; + projects?: string[] | null; } export interface IIssueDisplayFilterOptions { diff --git a/web/types/views.d.ts b/web/types/views.d.ts index e1246af5aa..527e908331 100644 --- a/web/types/views.d.ts +++ b/web/types/views.d.ts @@ -1,3 +1,5 @@ +import { IIssueFilterOptions } from "./view-props"; + export interface IView { id: string; access: string; @@ -8,8 +10,8 @@ export interface IView { updated_by: string; name: string; description: string; - query: IQuery; - query_data: IQuery; + query: IIssueFilterOptions; + query_data: IIssueFilterOptions; project: string; workspace: string; } diff --git a/web/types/workspace-view.d.ts b/web/types/workspace-view.d.ts new file mode 100644 index 0000000000..bb1b3a45fd --- /dev/null +++ b/web/types/workspace-view.d.ts @@ -0,0 +1,21 @@ +import { IIssueFilterOptions } from "./view-props"; + +export interface IWorkspaceView { + access: string; + created_at: Date; + created_by: string; + description: string; + id: string; + name: string; + query: IIssueFilterOptions; + query_data: IIssueFilterOptions; + updated_at: Date; + updated_by: string; + is_favorite: boolean; + workspace: string; + workspace_detail: { + id: string; + name: string; + slug: string; + }; +} diff --git a/web/types/workspace.d.ts b/web/types/workspace.d.ts index 4bc50f7573..66e1e12739 100644 --- a/web/types/workspace.d.ts +++ b/web/types/workspace.d.ts @@ -114,21 +114,6 @@ export interface IWorkspaceSearchResults { }; } -export interface WorkspaceViewIssueParams { - assignees: string | undefined; - created_by: string | undefined; - estimate_point: string | undefined; - labels: string | undefined; - priority: string | undefined; - state: string | undefined; - state_group: string | undefined; - start_date: string | undefined; - target_date: string | undefined; - type: "active" | "backlog" | undefined; - project: string | undefined; - sub_issue: boolean; -} - export interface IProductUpdateResponse { url: string; assets_url: string;