fix: workspace view filters count fix (#2307)

This commit is contained in:
Anmol Singh Bhatia 2023-09-29 16:40:02 +05:30 committed by GitHub
parent f1879a404d
commit 4cab00ec79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 138 additions and 44 deletions

View File

@ -299,8 +299,6 @@ export const WorkspaceFiltersList: React.FC<Props> = ({
: key === "project"
? filters.project?.map((projectId) => {
const currentProject = project?.find((p) => p.id === projectId);
console.log("currentProject", currentProject);
console.log("currentProject", projectId);
return (
<p
key={currentProject?.id}

View File

@ -12,7 +12,6 @@ import { CustomMenu } from "components/ui";
import viewsService from "services/views.service";
// types
import { IView } from "types";
import { IWorkspaceView } from "types/workspace-views";
// fetch keys
import { VIEWS_LIST } from "constants/fetch-keys";
// hooks
@ -21,18 +20,12 @@ import useToast from "hooks/use-toast";
import { truncateText } from "helpers/string.helper";
type Props = {
view: IView | IWorkspaceView;
viewType: "project" | "workspace";
view: IView;
handleEditView: () => void;
handleDeleteView: () => void;
};
export const SingleViewItem: React.FC<Props> = ({
view,
viewType,
handleEditView,
handleDeleteView,
}) => {
export const SingleViewItem: React.FC<Props> = ({ view, handleEditView, handleDeleteView }) => {
const router = useRouter();
const { workspaceSlug, projectId } = router.query;
@ -88,10 +81,7 @@ export const SingleViewItem: React.FC<Props> = ({
});
};
const viewRedirectionUrl =
viewType === "project"
? `/${workspaceSlug}/projects/${projectId}/views/${view.id}`
: `/${workspaceSlug}/workspace-views/issues?globalViewId=${view.id}`;
const viewRedirectionUrl = `/${workspaceSlug}/projects/${projectId}/views/${view.id}`;
return (
<div className="group hover:bg-custom-background-90 border-b border-custom-border-200">
@ -126,8 +116,7 @@ export const SingleViewItem: React.FC<Props> = ({
filters
</p>
{viewType === "project" ? (
view.is_favorite ? (
{view.is_favorite ? (
<button
type="button"
onClick={(e) => {
@ -149,8 +138,7 @@ export const SingleViewItem: React.FC<Props> = ({
>
<StarIcon className="h-4 w-4 " color="rgb(var(--color-text-200))" />
</button>
)
) : null}
)}
<CustomMenu width="auto" ellipsis>
<CustomMenu.MenuItem
onClick={(e: any) => {

View File

@ -0,0 +1,110 @@
import React from "react";
import Link from "next/link";
import { useRouter } from "next/router";
// icons
import { TrashIcon, PencilIcon } from "@heroicons/react/24/outline";
import { PhotoFilterOutlined } from "@mui/icons-material";
//components
import { CustomMenu } from "components/ui";
import { IWorkspaceView } from "types/workspace-views";
// helpers
import { truncateText } from "helpers/string.helper";
type Props = {
view: IWorkspaceView;
handleEditView: () => void;
handleDeleteView: () => void;
};
export const SingleWorkspaceViewItem: React.FC<Props> = ({
view,
handleEditView,
handleDeleteView,
}) => {
const router = useRouter();
const { workspaceSlug } = router.query;
const viewRedirectionUrl = `/${workspaceSlug}/workspace-views/issues?globalViewId=${view.id}`;
return (
<div className="group hover:bg-custom-background-90 border-b border-custom-border-200">
<Link href={viewRedirectionUrl}>
<a className="flex items-center justify-between relative rounded px-5 py-4 w-full">
<div className="flex items-center justify-between w-full">
<div className="flex items-center gap-4">
<div
className={`flex items-center justify-center h-10 w-10 rounded bg-custom-background-90 group-hover:bg-custom-background-100`}
>
<PhotoFilterOutlined className="!text-base !leading-6" />
</div>
<div className="flex flex-col">
<p className="truncate text-sm leading-4 font-medium">
{truncateText(view.name, 75)}
</p>
{view?.description && (
<p className="text-xs text-custom-text-200">{view.description}</p>
)}
</div>
</div>
<div className="ml-2 flex flex-shrink-0">
<div className="flex items-center gap-4">
<p className="rounded bg-custom-background-80 py-1 px-2 text-xs text-custom-text-200 opacity-0 group-hover:opacity-100">
{view.query_data.filters && Object.keys(view.query_data.filters).length > 0
? `${Object.keys(view.query_data.filters)
.map((key: string) =>
view.query_data.filters[key as keyof typeof view.query_data.filters] !==
null
? isNaN(
(
view.query_data.filters[
key as keyof typeof view.query_data.filters
] as any
).length
)
? 0
: (
view.query_data.filters[
key as keyof typeof view.query_data.filters
] as any
).length
: 0
)
.reduce((curr, prev) => curr + prev, 0)} filters`
: "0 filters"}
</p>
<CustomMenu width="auto" ellipsis>
<CustomMenu.MenuItem
onClick={(e: any) => {
e.preventDefault();
e.stopPropagation();
handleEditView();
}}
>
<span className="flex items-center justify-start gap-2">
<PencilIcon className="h-3.5 w-3.5" />
<span>Edit View</span>
</span>
</CustomMenu.MenuItem>
<CustomMenu.MenuItem
onClick={(e: any) => {
e.preventDefault();
e.stopPropagation();
handleDeleteView();
}}
>
<span className="flex items-center justify-start gap-2">
<TrashIcon className="h-3.5 w-3.5" />
<span>Delete View</span>
</span>
</CustomMenu.MenuItem>
</CustomMenu>
</div>
</div>
</div>
</a>
</Link>
</div>
);
};

View File

@ -107,7 +107,6 @@ const ProjectViews: NextPage = () => {
<SingleViewItem
key={view.id}
view={view}
viewType="project"
handleEditView={() => handleEditView(view)}
handleDeleteView={() => handleDeleteView(view)}
/>

View File

@ -11,7 +11,7 @@ import workspaceService from "services/workspace.service";
// layouts
import { WorkspaceAuthorizationLayout } from "layouts/auth-layout";
// components
import { SingleViewItem } from "components/views";
import { SingleWorkspaceViewItem } from "components/workspace/views/single-workspace-view-item";
import { WorkspaceIssuesViewOptions } from "components/issues/workspace-views/workspace-issue-view-option";
import { CreateUpdateWorkspaceViewModal } from "components/workspace/views/modal";
import { DeleteWorkspaceViewModal } from "components/workspace/views/delete-workspace-view-modal";
@ -169,10 +169,9 @@ const WorkspaceViews: NextPage = () => {
filteredOptions.length > 0 ? (
<div>
{filteredOptions.map((view) => (
<SingleViewItem
<SingleWorkspaceViewItem
key={view.id}
view={view}
viewType="workspace"
handleEditView={() => handleEditView(view)}
handleDeleteView={() => handleDeleteView(view)}
/>