From 77dbced515f3d02cc89423efba412867e949e151 Mon Sep 17 00:00:00 2001 From: Prateek Shourya Date: Mon, 17 Mar 2025 15:10:22 +0530 Subject: [PATCH] improvement: command palette search results --- packages/constants/src/workspace.ts | 14 +++++++++++++- .../components/command-palette/helpers.tsx | 6 ++++-- web/ce/components/command-palette/index.ts | 3 +++ .../command-palette/actions/search-results.tsx | 8 ++++---- .../components/command-palette/command-modal.tsx | 10 +++------- web/core/components/command-palette/index.ts | 1 - 6 files changed, 27 insertions(+), 15 deletions(-) rename web/{core => ce}/components/command-palette/helpers.tsx (97%) create mode 100644 web/ce/components/command-palette/index.ts diff --git a/packages/constants/src/workspace.ts b/packages/constants/src/workspace.ts index d1389759c34..cddc1a56ce7 100644 --- a/packages/constants/src/workspace.ts +++ b/packages/constants/src/workspace.ts @@ -1,4 +1,4 @@ -import { TStaticViewTypes } from "@plane/types"; +import { TStaticViewTypes, IWorkspaceSearchResults } from "@plane/types"; import { EUserWorkspaceRoles } from "./user"; export const ORGANIZATION_SIZE = [ @@ -324,3 +324,15 @@ export const WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS_LINKS: IWorkspaceSidebarN WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS["inbox"], WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS["projects"], ]; + +export const WORKSPACE_DEFAULT_SEARCH_RESULT: IWorkspaceSearchResults = { + results: { + workspace: [], + project: [], + issue: [], + cycle: [], + module: [], + issue_view: [], + page: [], + }, +}; diff --git a/web/core/components/command-palette/helpers.tsx b/web/ce/components/command-palette/helpers.tsx similarity index 97% rename from web/core/components/command-palette/helpers.tsx rename to web/ce/components/command-palette/helpers.tsx index 05885ebbd1d..d846ebfa061 100644 --- a/web/core/components/command-palette/helpers.tsx +++ b/web/ce/components/command-palette/helpers.tsx @@ -16,14 +16,16 @@ import { generateWorkItemLink } from "@/helpers/issue.helper"; // plane web components import { IssueIdentifier } from "@/plane-web/components/issues"; -export const commandGroups: { +export type TCommandGroups = { [key: string]: { icon: JSX.Element | null; itemName: (item: any) => React.ReactNode; path: (item: any, projectId: string | undefined) => string; title: string; }; -} = { +}; + +export const commandGroups: TCommandGroups = { cycle: { icon: , itemName: (cycle: IWorkspaceDefaultSearchResult) => ( diff --git a/web/ce/components/command-palette/index.ts b/web/ce/components/command-palette/index.ts new file mode 100644 index 00000000000..62404249d75 --- /dev/null +++ b/web/ce/components/command-palette/index.ts @@ -0,0 +1,3 @@ +export * from "./actions"; +export * from "./modals"; +export * from "./helpers"; diff --git a/web/core/components/command-palette/actions/search-results.tsx b/web/core/components/command-palette/actions/search-results.tsx index 8d67635ba91..18a8a75beb2 100644 --- a/web/core/components/command-palette/actions/search-results.tsx +++ b/web/core/components/command-palette/actions/search-results.tsx @@ -2,12 +2,12 @@ import { Command } from "cmdk"; import { useParams } from "next/navigation"; -// types +// plane imports import { IWorkspaceSearchResults } from "@plane/types"; -// helpers -import { commandGroups } from "@/components/command-palette"; // hooks import { useAppRouter } from "@/hooks/use-app-router"; +// plane web imports +import { commandGroups } from "@/plane-web/components/command-palette"; type Props = { closePalette: () => void; @@ -25,9 +25,9 @@ export const CommandPaletteSearchResults: React.FC = (props) => { return ( <> {Object.keys(results.results).map((key) => { + // TODO: add type for results const section = (results.results as any)[key]; const currentSection = commandGroups[key]; - if (!currentSection) return null; if (section.length > 0) { return ( diff --git a/web/core/components/command-palette/command-modal.tsx b/web/core/components/command-palette/command-modal.tsx index 7fdc96f5a7f..5cc0805041d 100644 --- a/web/core/components/command-palette/command-modal.tsx +++ b/web/core/components/command-palette/command-modal.tsx @@ -8,7 +8,7 @@ import useSWR from "swr"; import { CommandIcon, FolderPlus, Search, Settings, X } from "lucide-react"; import { Dialog, Transition } from "@headlessui/react"; // plane imports -import { EUserPermissions, EUserPermissionsLevel } from "@plane/constants"; +import { EUserPermissions, EUserPermissionsLevel, WORKSPACE_DEFAULT_SEARCH_RESULT } from "@plane/constants"; import { useTranslation } from "@plane/i18n"; import { IWorkspaceSearchResults } from "@plane/types"; import { LayersIcon, Loader, ToggleSwitch } from "@plane/ui"; @@ -58,9 +58,7 @@ export const CommandModal: React.FC = observer(() => { const [isLoading, setIsLoading] = useState(false); const [isSearching, setIsSearching] = useState(false); const [searchTerm, setSearchTerm] = useState(""); - const [results, setResults] = useState({ - results: { workspace: [], project: [], issue: [], cycle: [], module: [], issue_view: [], page: [] }, - }); + const [results, setResults] = useState(WORKSPACE_DEFAULT_SEARCH_RESULT); const [isWorkspaceLevel, setIsWorkspaceLevel] = useState(false); const [pages, setPages] = useState([]); const [searchInIssue, setSearchInIssue] = useState(false); @@ -151,9 +149,7 @@ export const CommandModal: React.FC = observer(() => { setIsSearching(false); }); } else { - setResults({ - results: { workspace: [], project: [], issue: [], cycle: [], module: [], issue_view: [], page: [] }, - }); + setResults(WORKSPACE_DEFAULT_SEARCH_RESULT); setIsLoading(false); setIsSearching(false); } diff --git a/web/core/components/command-palette/index.ts b/web/core/components/command-palette/index.ts index 0d2e042a7fe..5aee700af3e 100644 --- a/web/core/components/command-palette/index.ts +++ b/web/core/components/command-palette/index.ts @@ -2,4 +2,3 @@ export * from "./actions"; export * from "./shortcuts-modal"; export * from "./command-modal"; export * from "./command-palette"; -export * from "./helpers";