[WEB-1995] fix: searched page redirection from command palette. (#5170)

* [WEB-1995] fix: searched page redirection from command palette.

* chore: update redirect logic.
This commit is contained in:
Prateek Shourya
2024-07-19 13:56:16 +05:30
committed by GitHub
parent 075b8efa99
commit 44a0ff5c67
2 changed files with 12 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
"use client";
import { Command } from "cmdk";
import { useParams } from "next/navigation";
// types
import { IWorkspaceSearchResults } from "@plane/types";
// helpers
@@ -15,8 +16,11 @@ type Props = {
export const CommandPaletteSearchResults: React.FC<Props> = (props) => {
const { closePalette, results } = props;
// router
const router = useAppRouter();
const { projectId: routerProjectId } = useParams();
// derived values
const projectId = routerProjectId?.toString();
return (
<>
@@ -32,7 +36,7 @@ export const CommandPaletteSearchResults: React.FC<Props> = (props) => {
key={item.id}
onSelect={() => {
closePalette();
router.push(currentSection.path(item));
router.push(currentSection.path(item, projectId));
}}
value={`${key}-${item?.id}-${item.name}-${item.project__identifier ?? ""}-${item.sequence_id ?? ""}`}
className="focus:outline-none"

View File

@@ -15,7 +15,7 @@ export const commandGroups: {
[key: string]: {
icon: JSX.Element;
itemName: (item: any) => React.ReactNode;
path: (item: any) => string;
path: (item: any, projectId: string | undefined) => string;
title: string;
};
} = {
@@ -73,8 +73,11 @@ export const commandGroups: {
<span className="text-xs text-custom-text-300">{page.project__identifiers?.[0]}</span> {page.name}
</h6>
),
path: (page: IWorkspaceDefaultSearchResult) =>
`/${page?.workspace__slug}/projects/${page?.project_id}/pages/${page?.id}`,
path: (page: IWorkspacePageSearchResult, projectId: string | undefined) => {
let redirectProjectId = page?.project_ids?.[0];
if (!!projectId && page?.project_ids?.includes(projectId)) redirectProjectId = projectId;
return `/${page?.workspace__slug}/projects/${redirectProjectId}/pages/${page?.id}`;
},
title: "Pages",
},
project: {