From 507d7da7175907936fbd9b6219793e4145dfd109 Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Thu, 16 May 2024 13:14:36 +0530 Subject: [PATCH] fix: issue peekoverview handled state and query parameters handlers (#4475) --- .../issues/board-views/list/block.tsx | 20 +++++---- .../issues/peek-overview/layout.tsx | 44 ++++++++++++------- space/components/views/project-details.tsx | 4 +- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/space/components/issues/board-views/list/block.tsx b/space/components/issues/board-views/list/block.tsx index 364bf1231..5eaa31721 100644 --- a/space/components/issues/board-views/list/block.tsx +++ b/space/components/issues/board-views/list/block.tsx @@ -1,7 +1,7 @@ "use client"; import { FC } from "react"; import { observer } from "mobx-react-lite"; -import { useParams, useRouter, useSearchParams } from "next/navigation"; +import { useRouter, useSearchParams } from "next/navigation"; // components import { IssueBlockDueDate } from "@/components/issues/board-views/block-due-date"; import { IssueBlockLabels } from "@/components/issues/board-views/block-labels"; @@ -21,8 +21,12 @@ type IssueListBlockProps = { export const IssueListBlock: FC = observer((props) => { const { workspaceSlug, projectId, issue } = props; - const { board, states, priority, labels } = useParams(); const searchParams = useSearchParams(); + // query params + const board = searchParams.get("board") || undefined; + const state = searchParams.get("state") || undefined; + const priority = searchParams.get("priority") || undefined; + const labels = searchParams.get("labels") || undefined; // store const { project } = useProject(); const { setPeekId } = useIssueDetails(); @@ -31,12 +35,12 @@ export const IssueListBlock: FC = observer((props) => { const handleBlockClick = () => { setPeekId(issue.id); - const params: any = { board: board, peekId: issue.id }; - if (states && states.length > 0) params.states = states; - if (priority && priority.length > 0) params.priority = priority; - if (labels && labels.length > 0) params.labels = labels; - router.push(`/${workspaceSlug}/${projectId}?${searchParams}`); - // router.push(`/${workspace_slug?.toString()}/${project_slug}?board=${board?.toString()}&peekId=${issue.id}`); + let queryParams: any = { board: board, peekId: issue.id }; + if (priority && priority.length > 0) queryParams = { ...queryParams, priority: priority }; + if (state && state.length > 0) queryParams = { ...queryParams, state: state }; + if (labels && labels.length > 0) queryParams = { ...queryParams, labels: labels }; + queryParams = new URLSearchParams(queryParams).toString(); + router.push(`/${workspaceSlug}/${projectId}?${queryParams}`); }; return ( diff --git a/space/components/issues/peek-overview/layout.tsx b/space/components/issues/peek-overview/layout.tsx index a70021372..453cc59f3 100644 --- a/space/components/issues/peek-overview/layout.tsx +++ b/space/components/issues/peek-overview/layout.tsx @@ -1,16 +1,29 @@ "use client"; -import React, { useEffect, useState } from "react"; +import { FC, Fragment, useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; -// headless ui +import { useRouter, useSearchParams } from "next/navigation"; import { Dialog, Transition } from "@headlessui/react"; // components import { FullScreenPeekView, SidePeekView } from "@/components/issues/peek-overview"; // store import { useIssue, useIssueDetails } from "@/hooks/store"; -export const IssuePeekOverview: React.FC = observer((props: any) => { - const { workspaceSlug, projectId, peekId, board, priority, states, labels } = props; +type TIssuePeekOverview = { + workspaceSlug: string; + projectId: string; + peekId: string; +}; + +export const IssuePeekOverview: FC = observer((props) => { + const { workspaceSlug, projectId, peekId } = props; + const router = useRouter(); + const searchParams = useSearchParams(); + // query params + const board = searchParams.get("board") || undefined; + const state = searchParams.get("state") || undefined; + const priority = searchParams.get("priority") || undefined; + const labels = searchParams.get("labels") || undefined; // states const [isSidePeekOpen, setIsSidePeekOpen] = useState(false); const [isModalPeekOpen, setIsModalPeekOpen] = useState(false); @@ -30,13 +43,12 @@ export const IssuePeekOverview: React.FC = observer((props: any) => { const handleClose = () => { issueDetailStore.setPeekId(null); - - const params: any = { board: board }; - if (states && states.length > 0) params.states = states; - if (priority && priority.length > 0) params.priority = priority; - if (labels && labels.length > 0) params.labels = labels; - // TODO: fix this redirection - // router.push( encodeURI(`/${workspaceSlug?.toString()}/${projectId}`, ) { pathname: `/${workspaceSlug?.toString()}/${projectId}`, query: { ...params } }); + let queryParams: any = { board: board }; + if (priority && priority.length > 0) queryParams = { ...queryParams, priority: priority }; + if (state && state.length > 0) queryParams = { ...queryParams, state: state }; + if (labels && labels.length > 0) queryParams = { ...queryParams, labels: labels }; + queryParams = new URLSearchParams(queryParams).toString(); + router.push(`/${workspaceSlug}/${projectId}?${queryParams}`); }; useEffect(() => { @@ -56,10 +68,10 @@ export const IssuePeekOverview: React.FC = observer((props: any) => { return ( <> - + { - + {
= observer((props) return (
- {workspaceSlug && } + {workspaceSlug && projectId && peekId && ( + + )} {loader && !issues ? (
Loading...