chore: workspace issues types and fetch key added

This commit is contained in:
Anmol Singh Bhatia 2023-09-25 11:47:06 +05:30
parent 3a7ea55e81
commit 3440fb962d
13 changed files with 63 additions and 44 deletions

View File

@ -21,6 +21,7 @@ type Props = {
labels: IIssueLabels[] | undefined; labels: IIssueLabels[] | undefined;
members: IUserLite[] | undefined; members: IUserLite[] | undefined;
states: IState[] | undefined; states: IState[] | undefined;
stateGroup?: string[] | undefined;
}; };
export const FiltersList: React.FC<Props> = ({ export const FiltersList: React.FC<Props> = ({

View File

@ -23,7 +23,7 @@ import { GROUP_CHOICES, PRIORITIES } from "constants/project";
import { DATE_FILTER_OPTIONS } from "constants/filters"; import { DATE_FILTER_OPTIONS } from "constants/filters";
type Props = { type Props = {
filters: Partial<IIssueFilterOptions> | IQuery; filters: Partial<IIssueFilterOptions>;
onSelect: (option: any) => void; onSelect: (option: any) => void;
direction?: "left" | "right"; direction?: "left" | "right";
height?: "sm" | "md" | "rg" | "lg"; height?: "sm" | "md" | "rg" | "lg";

View File

@ -17,6 +17,7 @@ import { DangerButton, SecondaryButton } from "components/ui";
import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
// types // types
import type { ICurrentUserResponse, IView } from "types"; import type { ICurrentUserResponse, IView } from "types";
import { IWorkspaceView } from "types/workspace-view";
// fetch-keys // fetch-keys
import { VIEWS_LIST, WORKSPACE_VIEWS_LIST } from "constants/fetch-keys"; import { VIEWS_LIST, WORKSPACE_VIEWS_LIST } from "constants/fetch-keys";
@ -24,7 +25,7 @@ type Props = {
isOpen: boolean; isOpen: boolean;
viewType: "project" | "workspace"; viewType: "project" | "workspace";
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>; setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
data: IView | null; data: IView | IWorkspaceView | null;
user: ICurrentUserResponse | undefined; user: ICurrentUserResponse | undefined;
}; };

View File

@ -21,6 +21,7 @@ import { getStatesList } from "helpers/state.helper";
// types // types
import { IQuery, IView } from "types"; import { IQuery, IView } from "types";
import issuesService from "services/issues.service"; import issuesService from "services/issues.service";
import { IWorkspaceView } from "types/workspace-view";
// fetch-keys // fetch-keys
import { PROJECT_ISSUE_LABELS, STATES_LIST } from "constants/fetch-keys"; import { PROJECT_ISSUE_LABELS, STATES_LIST } from "constants/fetch-keys";
@ -28,7 +29,7 @@ type Props = {
handleFormSubmit: (values: IView) => Promise<void>; handleFormSubmit: (values: IView) => Promise<void>;
handleClose: () => void; handleClose: () => void;
status: boolean; status: boolean;
data?: IView | null; data?: IView | IWorkspaceView | null;
preLoadedData?: Partial<IView> | null; preLoadedData?: Partial<IView> | null;
}; };
@ -96,7 +97,6 @@ export const ViewForm: React.FC<Props> = ({
state: null, state: null,
start_date: null, start_date: null,
target_date: null, target_date: null,
type: null,
}); });
}; };

View File

@ -15,6 +15,7 @@ import useToast from "hooks/use-toast";
import { ViewForm } from "components/views"; import { ViewForm } from "components/views";
// types // types
import { ICurrentUserResponse, IView } from "types"; import { ICurrentUserResponse, IView } from "types";
import { IWorkspaceView } from "types/workspace-view";
// fetch-keys // fetch-keys
import { VIEWS_LIST, WORKSPACE_VIEWS_LIST } from "constants/fetch-keys"; import { VIEWS_LIST, WORKSPACE_VIEWS_LIST } from "constants/fetch-keys";
@ -22,7 +23,7 @@ type Props = {
isOpen: boolean; isOpen: boolean;
viewType: "project" | "workspace"; viewType: "project" | "workspace";
handleClose: () => void; handleClose: () => void;
data?: IView | null; data?: IView | IWorkspaceView | null;
preLoadedData?: Partial<IView> | null; preLoadedData?: Partial<IView> | null;
user: ICurrentUserResponse | undefined; user: ICurrentUserResponse | undefined;
}; };

View File

@ -12,6 +12,7 @@ import { CustomMenu } from "components/ui";
import viewsService from "services/views.service"; import viewsService from "services/views.service";
// types // types
import { IView } from "types"; import { IView } from "types";
import { IWorkspaceView } from "types/workspace-view";
// fetch keys // fetch keys
import { VIEWS_LIST } from "constants/fetch-keys"; import { VIEWS_LIST } from "constants/fetch-keys";
// hooks // hooks
@ -20,7 +21,7 @@ import useToast from "hooks/use-toast";
import { truncateText } from "helpers/string.helper"; import { truncateText } from "helpers/string.helper";
type Props = { type Props = {
view: IView; view: IView | IWorkspaceView;
viewType: "project" | "workspace"; viewType: "project" | "workspace";
handleEditView: () => void; handleEditView: () => void;
handleDeleteView: () => void; handleDeleteView: () => void;

View File

@ -4,6 +4,7 @@ import { IAnalyticsParams, IJiraMetadata, INotificationParams } from "types";
const paramsToKey = (params: any) => { const paramsToKey = (params: any) => {
const { const {
state, state,
state_group,
priority, priority,
assignees, assignees,
created_by, created_by,
@ -17,6 +18,7 @@ const paramsToKey = (params: any) => {
let projectKey = project ? project.split(",") : []; let projectKey = project ? project.split(",") : [];
let stateKey = state ? state.split(",") : []; let stateKey = state ? state.split(",") : [];
let stateGroupKey = state_group ? state_group.split(",") : [];
let priorityKey = priority ? priority.split(",") : []; let priorityKey = priority ? priority.split(",") : [];
let assigneesKey = assignees ? assignees.split(",") : []; let assigneesKey = assignees ? assignees.split(",") : [];
let createdByKey = created_by ? created_by.split(",") : []; let createdByKey = created_by ? created_by.split(",") : [];
@ -31,12 +33,13 @@ const paramsToKey = (params: any) => {
// sorting each keys in ascending order // sorting each keys in ascending order
projectKey = projectKey.sort().join("_"); projectKey = projectKey.sort().join("_");
stateKey = stateKey.sort().join("_"); stateKey = stateKey.sort().join("_");
stateGroupKey = stateGroupKey.sort().join("_");
priorityKey = priorityKey.sort().join("_"); priorityKey = priorityKey.sort().join("_");
assigneesKey = assigneesKey.sort().join("_"); assigneesKey = assigneesKey.sort().join("_");
createdByKey = createdByKey.sort().join("_"); createdByKey = createdByKey.sort().join("_");
labelsKey = labelsKey.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) => { 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) => export const WORKSPACE_VIEWS_LIST = (workspaceSlug: string) =>
`WORKSPACE_VIEWS_LIST_${workspaceSlug.toUpperCase()}`; `WORKSPACE_VIEWS_LIST_${workspaceSlug.toUpperCase()}`;
export const WORKSPACE_VIEW_DETAILS = (viewId: string) => export const WORKSPACE_VIEW_DETAILS = (workspaceViewId: string) =>
`WORKSPACE_VIEW_DETAILS_${viewId.toUpperCase()}`; `WORKSPACE_VIEW_DETAILS_${workspaceViewId.toUpperCase()}`;
export const WORKSPACE_VIEW_ISSUES = (viewId: string, params: any) => { export const WORKSPACE_VIEW_ISSUES = (workspaceViewId: string, params: any) => {
if (!params) return `WORKSPACE_VIEW_ISSUES_${viewId.toUpperCase()}`; if (!params) return `WORKSPACE_VIEW_ISSUES_${workspaceViewId.toUpperCase()}`;
const paramsKey = paramsToKey(params); 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) => export const PROJECT_ISSUES_DETAILS = (issueId: string) =>

View File

@ -25,27 +25,25 @@ import { PhotoFilterOutlined } from "@mui/icons-material";
import emptyView from "public/empty-state/view.svg"; import emptyView from "public/empty-state/view.svg";
// types // types
import type { NextPage } from "next"; import type { NextPage } from "next";
import { IView } from "types"; import { IWorkspaceView } from "types/workspace-view";
// constants // constants
import { WORKSPACE_VIEWS_LIST } from "constants/fetch-keys"; import { WORKSPACE_VIEWS_LIST } from "constants/fetch-keys";
// helper // helper
import { truncateText } from "helpers/string.helper"; import { truncateText } from "helpers/string.helper";
const WorkspaceViews: NextPage = () => { const WorkspaceViews: NextPage = () => {
console.log("test");
// const [currentView, setCurrentView] = useState("");
const [createUpdateViewModal, setCreateUpdateViewModal] = useState(false); const [createUpdateViewModal, setCreateUpdateViewModal] = useState(false);
const [selectedViewToUpdate, setSelectedViewToUpdate] = useState<IView | null>(null); const [selectedViewToUpdate, setSelectedViewToUpdate] = useState<IWorkspaceView | null>(null);
const [deleteViewModal, setDeleteViewModal] = useState(false); const [deleteViewModal, setDeleteViewModal] = useState(false);
const [selectedViewToDelete, setSelectedViewToDelete] = useState<IView | null>(null); const [selectedViewToDelete, setSelectedViewToDelete] = useState<IWorkspaceView | null>(null);
const handleEditView = (view: IView) => { const handleEditView = (view: IWorkspaceView) => {
setSelectedViewToUpdate(view); setSelectedViewToUpdate(view);
setCreateUpdateViewModal(true); setCreateUpdateViewModal(true);
}; };
const handleDeleteView = (view: IView) => { const handleDeleteView = (view: IWorkspaceView) => {
setSelectedViewToDelete(view); setSelectedViewToDelete(view);
setDeleteViewModal(true); setDeleteViewModal(true);
}; };

View File

@ -14,9 +14,9 @@ import {
ICurrentUserResponse, ICurrentUserResponse,
IWorkspaceBulkInviteFormData, IWorkspaceBulkInviteFormData,
IWorkspaceViewProps, IWorkspaceViewProps,
IView, IIssueFilterOptions,
WorkspaceViewIssueParams,
} from "types"; } from "types";
import { IWorkspaceView } from "types/workspace-view";
class WorkspaceService extends APIService { class WorkspaceService extends APIService {
constructor() { constructor() {
@ -264,7 +264,7 @@ class WorkspaceService extends APIService {
}); });
} }
async createView(workspaceSlug: string, data: IView): Promise<any> { async createView(workspaceSlug: string, data: IWorkspaceView): Promise<any> {
return this.post(`/api/workspaces/${workspaceSlug}/views/`, data) return this.post(`/api/workspaces/${workspaceSlug}/views/`, data)
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
@ -272,7 +272,11 @@ class WorkspaceService extends APIService {
}); });
} }
async updateView(workspaceSlug: string, viewId: string, data: Partial<IView>): Promise<any> { async updateView(
workspaceSlug: string,
viewId: string,
data: Partial<IWorkspaceView>
): Promise<any> {
return this.patch(`/api/workspaces/${workspaceSlug}/views/${viewId}/`, data) return this.patch(`/api/workspaces/${workspaceSlug}/views/${viewId}/`, data)
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
@ -288,7 +292,7 @@ class WorkspaceService extends APIService {
}); });
} }
async getAllViews(workspaceSlug: string): Promise<IView[]> { async getAllViews(workspaceSlug: string): Promise<IWorkspaceView[]> {
return this.get(`/api/workspaces/${workspaceSlug}/views/`) return this.get(`/api/workspaces/${workspaceSlug}/views/`)
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
@ -296,7 +300,7 @@ class WorkspaceService extends APIService {
}); });
} }
async getViewDetails(workspaceSlug: string, viewId: string): Promise<IView> { async getViewDetails(workspaceSlug: string, viewId: string): Promise<IWorkspaceView> {
return this.get(`/api/workspaces/${workspaceSlug}/views/${viewId}/`) return this.get(`/api/workspaces/${workspaceSlug}/views/${viewId}/`)
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
@ -304,7 +308,7 @@ class WorkspaceService extends APIService {
}); });
} }
async getViewIssues(workspaceSlug: string, params: WorkspaceViewIssueParams): Promise<any> { async getViewIssues(workspaceSlug: string, params: IIssueFilterOptions): Promise<any> {
return this.get(`/api/workspaces/${workspaceSlug}/issues/`, { return this.get(`/api/workspaces/${workspaceSlug}/issues/`, {
params, params,
}) })

View File

@ -35,9 +35,11 @@ export interface IIssueFilterOptions {
priority?: string[] | null; priority?: string[] | null;
start_date?: string[] | null; start_date?: string[] | null;
state?: string[] | null; state?: string[] | null;
state_group?: TStateGroups[] | null; state_group?: string[] | null;
subscriber?: string[] | null; subscriber?: string[] | null;
target_date?: string[] | null; target_date?: string[] | null;
estimate_point?: string[] | null;
projects?: string[] | null;
} }
export interface IIssueDisplayFilterOptions { export interface IIssueDisplayFilterOptions {

View File

@ -1,3 +1,5 @@
import { IIssueFilterOptions } from "./view-props";
export interface IView { export interface IView {
id: string; id: string;
access: string; access: string;
@ -8,8 +10,8 @@ export interface IView {
updated_by: string; updated_by: string;
name: string; name: string;
description: string; description: string;
query: IQuery; query: IIssueFilterOptions;
query_data: IQuery; query_data: IIssueFilterOptions;
project: string; project: string;
workspace: string; workspace: string;
} }

21
web/types/workspace-view.d.ts vendored Normal file
View File

@ -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;
};
}

View File

@ -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 { export interface IProductUpdateResponse {
url: string; url: string;
assets_url: string; assets_url: string;